Skip to Content
Menú
This question has been flagged
1 Respondre
2479 Vistes

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
Descartar
Autor 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
Descartar
Related Posts Respostes Vistes Activitat
1
de set. 20
4475
0
de set. 23
1827
2
de jul. 23
2130
0
de març 15
4499
2
de març 25
3558