I'm trying to get a product_id value from stock.quant, but instead I'm getting the name of the model and a list:
Here is the code:
class stock_quant(models.Model):
_inherit = "stock.quant"
...some code...
prodID = product.id (the value is correct( 235 ), I have no problem there)
...some code...
for y in self.search([]):
x=y.browse([(prodID)])
_logger.info("myValue : " +str(x)) #so this value is displayed stock.quant(235,) but I
want to get only the 235 from this list.
So how to get a value from this Many2One?
self.search([]):
you are writing a method in the stock.quant
model, so in this method self
is a object of stock.quant
, so performing search on self results recordset of stock.quant
, you are running the for loop for all the record of stock.quant
model. so y
is also a stock.quant
record on each iteration of the loop, calling y.browse()
will only result in another stock.quant
. If you want to get product.product
record, you have to either follow the product_id
relation on stock.quant
model, for example y.product_id.id
, or fetch the model from registry, for example self.env['product.product'].browse()
.