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

In the form view, I wanted to automatically update the list_price(Product Price)when the standard_price(Cost) and the margin(Desired Profit Margin) are given. 

The computed field(list_price) does not change automatically after clicking on the "save manually button"(cloud icon). The change only occurs after refreshing the browser page. 

class Phone(models.Model):
_inherit = "product.template"

margin = fields.Float(string="Desired Profit Margin(%)")
list_price = fields.Float(compute="_compute_list_price")

def _compute_list_price(self):
for record in self:
if record.margin:
record.list_price = record.standard_price * (1 + record.margin / 100)
else:
record.list_price = ""

Thanks a lot for your suggestions. 


Avatar
Discard
Author Best Answer

Thanks for the solution. I've tried and it is working perfectly.

Avatar
Discard
Best Answer

Hi,


Try with the following code,



@api.depends('standard_price', 'margin')
def _compute_list_price(self):
for record in self:
if record.margin:
record.list_price = record.standard_price * (1 + record.margin / 100)
else:
record.list_price = record.standard_priceH


Hope it helps

Avatar
Discard
Best Answer

Hii,
Here is updated code 

from odoo import models, fields, api



class Phone(models.Model):


    _inherit = "product.template"


    margin = fields.Float(string="Desired Profit Margin (%)")

   

    list_price = fields.Float(

        string="Sale Price",

        compute="_compute_list_price",

        store=True  

    )


    @api.depends('standard_price', 'margin')

    def _compute_list_price(self):

        for record in self:

            if record.standard_price and record.margin:

                record.list_price = record.standard_price * (1 + record.margin / 100)

            else:

                record.list_price = record.standard_price or 0.0  # fallback to cost or 0


    @api.onchange('margin', 'standard_price')

    def _onchange_margin(self):

        for record in self:

            if record.standard_price and record.margin:

                record.list_price = record.standard_price * (1 + record.margin / 100)

i hope it is use full

Avatar
Discard
Related Posts Replies Views Activity
1
जून 25
15070
1
जून 25
523
1
जून 25
1318
3
अप्रैल 25
5162
2
जुल॰ 24
2032