Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
452 Vistas

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
Descartar
Autor Mejor respuesta

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

Avatar
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 25
15079
1
jun 25
587
1
jun 25
1387
3
abr 25
5176
2
jul 24
2037