Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
2599 Weergaven

Good afternoon All,

I was wondering if there is an easy way or option to add a margin to the product, similar to what we can activate in the Sales Orders. 

We would like to see the margin on each product as well. I have searched all existing fields in Odoo Studio but couldn't find the one that includes the margin.


Thank you for any ideas and for your help.

Avatar
Annuleer
Beste antwoord

Hi 

Try the following code


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

margin_product = fields.Float(string='Margin',
compute='_compute_margin', store=True)

@api.depends('list_price', 'standard_price')
def _compute_margin(self):
self.margin_product = 0
for record in self:
if record.list_price and record.standard_price:
record.margin_product = (record.list_price - record.standard_price) / record.list_price * 100


Regards

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
apr. 24
3514
0
aug. 18
4497
0
mrt. 15
4214
1
aug. 25
260
2
jun. 25
1726