模型名称而不是 product_id 值
name of model instead of product_id value
我试图从 stock.quant 获取 product_id 值,但我获取的是模型名称和列表:
代码如下:
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.
那么如何从这个 Many2One 中获取一个值呢?
我们可以使用 _name
属性从 many2one 字段访问模型名称。
例如,
many2one_field_name._name
self.search([]):
你在stock.quant
模型中写了一个方法,所以在这个方法中self
是stock.quant
的一个对象,所以对[=11=的自身结果记录集进行搜索], 你是运行 stock.quant
模型所有记录的for 循环。所以 y
在循环的每次迭代中也是一个 stock.quant
记录,调用 y.browse()
只会导致另一个 stock.quant
。如果要获取 product.product
记录,则必须遵循 stock.quant
模型上的 product_id
关系,例如 y.product_id.id
,或者从注册表中获取模型,例如 self.env['product.product'].browse()
.
我试图从 stock.quant 获取 product_id 值,但我获取的是模型名称和列表:
代码如下:
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.
那么如何从这个 Many2One 中获取一个值呢?
我们可以使用 _name
属性从 many2one 字段访问模型名称。
例如,
many2one_field_name._name
self.search([]):
你在stock.quant
模型中写了一个方法,所以在这个方法中self
是stock.quant
的一个对象,所以对[=11=的自身结果记录集进行搜索], 你是运行 stock.quant
模型所有记录的for 循环。所以 y
在循环的每次迭代中也是一个 stock.quant
记录,调用 y.browse()
只会导致另一个 stock.quant
。如果要获取 product.product
记录,则必须遵循 stock.quant
模型上的 product_id
关系,例如 y.product_id.id
,或者从注册表中获取模型,例如 self.env['product.product'].browse()
.