コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
457 ビュー

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. 


アバター
破棄
著作者 最善の回答

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

アバター
破棄
最善の回答

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

アバター
破棄
最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
6月 25
15080
1
6月 25
591
1
6月 25
1391
3
4月 25
5176
2
7月 24
2037