Skip to Content
Menu
This question has been flagged
2 Replies
7018 Views

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
Discard
Author

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

Best Answer

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
Discard
Related Posts Replies Views Activity
1
Feb 21
2423
0
Mar 21
1370
1
Sep 19
2140
1
Aug 24
1526
1
Dec 22
1284