Skip to Content
Menu
This question has been flagged
1 Reply
704 Views

Hello everyone
I have entered a customised margin field, which represents the pre-customised margin I would like on the product.
How can I make sure that, based on the purchase price and the margin I enter in that field, the final price is calculated and updated every time I change the margin field or the cost field?

I was thinking of doing an automated action, but I can't figure out if it's OK

Avatar
Discard
Best Answer

Hi,

Try refer the following code.

class ProductProduct(models.Model):
_inherit = 'product.product'

custom_margin = fields.Float(string="Custom Margin")
list_price = fields.Float(string="Sale Price", compute="_compute_custom_price", store=True)

@api.depends('standard_price', 'custom_margin')
def _compute_custom_price(self):
for product in self:
product.list_price = product.standard_price * (1 + product.custom_margin)

Regards

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 24
121
0
May 24
23
1
Apr 24
2623
0
Mar 24
419
0
Mar 24
542