我想在同一个模型中制作字段product.product
假设 A 取决于 lst_price of product.product
.
如果用户未设置 A 的值,则取 lst_price 但如果用户将设置 A 的值,则按原样设置。
变体价格集上的字段值也发生了变化。
amount=fields.Float(compute="_compute_amount",inverse="_set_amount",store=True)
@api.depends('lst_price')
def _compute_amount(self):
for product in self:
if product.amount<product.lst_price:
product.amount = product.lst_price
@api.one
def _set_amount(self):
return True
最佳答案
假设您想在 product.product 中创建字段,该字段将在 lst_price 更改时填充,也可以由用户更改。
你可以像这样实现它。
A = fields.AnyType(compute="get_value_on_lst_price", inverse="set_value_by_user",store=True)
@api.depends('lst_price')
def get_value_on_lst_price(self):
for product in self:
product.A = Any_Calculation_Using_lst_price
@api.one
def set_value_by_user(self):
return True
关于model - 如何制作字段取决于 product.product 的 lst_price 但可以编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46336331/