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

Hi,


I want to get the total cost of all products that belongs to the category "MO"

Everything works fine except the _total_mo function.


See my BOM here : https://imgur.com/a/9VzutCU


Here is my code :

    total_mo = fields.Float(compute='_total_mo', string='Coût total MO')

@api.multi
@api.depends('bom_line_ids')
def _total_mo(self,):
for bom_obj in self:
total_bom_cost = 0
for bom_line in bom_obj.bom_line_ids:
if bom_line.product_id.product_tmpl_id.categ_id.name == 'MO':
total_bom_cost += bom_line.total_cost_price
bom_obj.total_bom_cost = total_bom_cost


Any idea ? Thanks in advance

Avatar
Discard
Author Best Answer

It was just a beginner mistake, here is the final code :


    @api.multi
@api.depends('bom_line_ids')
def _total_mo(self,):
for bom_obj in self:
total_mo = 0
for bom_line in bom_obj.bom_line_ids:
if bom_line.product_id.product_tmpl_id.categ_id.name == 'MO':
total_mo += bom_line.total_cost_price
bom_obj.total_mo = total_mo
Avatar
Discard
Related Posts Replies Views Activity
1
Sep 20
3442
0
Sep 23
591
2
Jul 23
1007
0
Mar 15
3209
1
Sep 24
125