Home > Net >  Computed field on a tree view in odoo 13
Computed field on a tree view in odoo 13

Time:02-10

in customize module in odoo I add computed field transactions_count This field appears correctly in the form view But in the tree view it appears incorrectly (if its value is zero, it shows the value of the previous record)

this is my code :

transactions_count = fields.Float(string='Total Amount', compute='_compute_transactions_ids')


@api.depends('transactions_ids')
def _compute_transactions_ids(self):
    amount = 0.0
    for order in self:
        for line in order.transactions_ids:
            amount = amount  line.amount_total
        order.transactions_count = amount

CodePudding user response:

I think you should restart amount = 0.0 for every order in self, so you should place amount = 0.0 inside your first for.

I hope this answer can be helpful for you.

CodePudding user response:

Can need to set amount=0 in side the first loop as below.

transactions_count = fields.Float(string='Total Amount', compute='_compute_transactions_ids')


@api.depends('transactions_ids')
def _compute_transactions_ids(self):
    for order in self:
        amount = 0.0
        for line in order.transactions_ids:
            amount = amount  line.amount_total
        order.transactions_count = amount

Please check and let me know if works for you.

Thanks.

  • Related