跳至內容
選單
此問題已被標幟
1 回覆
2667 瀏覽次數

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.

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
4月 24
3665
0
8月 18
4568
0
3月 15
4242
1
8月 25
341
2
6月 25
1783