How to make the field depends on lst_price product product.product, but may be editable

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

let A, which depends on lst_price of product.product.

if the user did not set the value of A, and then took lst_price, but if the user sets the value of A, then it will be set as it is. The value of the field will also change at a given option price.

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
+4
source share
1 answer

let's say you want to create a field in product.product that will be populated when lst_price changes, can also be changed by the user.

You can achieve it this way.

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
+1
source

Source: https://habr.com/ru/post/1686095/


All Articles