Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
500 Vizualizări

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. 


Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iun. 25
15116
1
iun. 25
626
1
iun. 25
1429
3
apr. 25
5200
2
iul. 24
2075