Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
8565 Visualizações

i want to get the sum of amount's values of in a computed field in event.event model 

class EventEvent(models.Model):
    _inherit = 'event.event'

    birst_ids = fields.Many2many('hr.birst', string='field name')

class FleetList(models.Model):
    _name = 'hr.birst'

    bricom = fields.Char('field name")
    amount = fields.Float('Montant')

how can i get a computed field in the event.event model that has as a value the sum of amount value field ? 

i tried this code but it seems that i am still missing something 

class EventEvent(models.Model):
    _inherit = 'event.event'

    birst_ids = fields.Many2many('hr.birst', string='field name') 
    
    def _amount_total (self, cr, uid, ids, field_name, arg, context=None):
        res = {}
        for event in self.browse(cr, uid, ids, context=context):
            total = 0.0
            for ids in event.birst_ids:
                total += ids.amount
            res[event.id] = total
        return res

    total_amount = fields.Float(computed="_amount_total", sting="Total")

any help ? 

Avatar
Cancelar
Autor

thanks Niyas for your replay, but still the total_amount field dosent filled up with the sum of amount's values,

Melhor resposta

Hi,

def _amount_total(self):
for rec in self:
total = sum(rec.birst_ids.mapped('amount')) if rec.birst_ids else 0
rec.total_amount = total

Thanks

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
fev. 21
3606
0
mar. 21
2263
1
set. 19
2871
1
ago. 24
2684
1
dez. 22
2227