Skip to Content
मेन्यू
This question has been flagged
3 Replies
2411 Views

Hello All,

I have added a field in my form with name "product" and type Many2one from product.product. And also a field "new_price" field for price of a product. I want that when i select a particular product then its price should be automatically selected.

For this purpose i am writing an onchange:

 @api.multi
# @api.onchange('product_id')
def onchange_secondary_price(self):
if self:
for rec in self:
rec.new_price = rec.product_id.price
but it is not working.
Help please

 

Avatar
Discard
Best Answer

Hello, 

You can try below code maybe its help you 

​@api.onchange('product_id')
def onchange_secondary_price(self):
    for rec in self:
         if rec.product_id:
            rec.new_price = rec.product_id.price
Avatar
Discard
Best Answer

Hi,

Update the function like this, also add some print statement or by adding logger message make sure that function get called


 @api.onchange('product_id')
def onchange_secondary_price(self):
for rec in self:
if rec.product_id:
rec.new_price = rec.product_id.price


Thanks

Avatar
Discard
Best Answer

Hello,

I think the the price field is not correct. "list_price" is Sale price field.

@api.multi
@api.onchange('product_id')
def onchange_secondary_price(self):
for rec in self:
rec.new_price = rec.product_id.list_price
Avatar
Discard