Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2440 Vistas

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 Mejor respuesta

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
Publicaciones relacionadas Respuestas Vistas Actividad
1
sept 20
4426
0
sept 23
1769
2
jul 23
2077
0
mar 15
4452
2
mar 25
3490