Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
8439 Widoki

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 ? 

Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lut 21
3530
0
mar 21
2183
1
wrz 19
2835
1
sie 24
2610
1
gru 22
2159