4

I want to make the field in the same model product.product

let's say A which is depends on lst_price of product.product.

if user not set value of A then its take lst_price but if User will set the value of A then its set as it is. Also A field value change on variant price set.

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

1 Answers1

1

let say you want to create field in product.product which will populate on the lst_price change also can be change by user.

You can achieve it like this.

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
KbiR
  • 4,047
  • 6
  • 37
  • 103
Chavada Viki
  • 1,514
  • 1
  • 12
  • 22