İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
451 Görünümler

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
Vazgeç
Üretici En İyi Yanıt

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

Avatar
Vazgeç
En İyi Yanıt

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
Vazgeç
En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Haz 25
15079
1
Haz 25
587
1
Haz 25
1387
3
Nis 25
5176
Compute Fields Çözüldü
2
Tem 24
2036