Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
8409 Переглядів

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 ? 

Аватар
Відмінити
Автор

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

Найкраща відповідь

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
лют. 21
3514
0
бер. 21
2174
1
вер. 19
2828
1
серп. 24
2594
KeyError: batch_id Вирішено
1
груд. 22
2146