Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
33261 Zobrazení

i have pos_order_total field in contact tree view , and it's calculates perfecly if store=False , but if store=True it doesnt calculates if i make another pos order for client. how can i make this work with store=True. 
Maybe i need to add some depends fields. i tryed

from odoo import api, fields, models


class ResPartner(models.Model):
    _inherit = 'res.partner'
    
    order_id = fields.One2many('pos.order', 'amount_total') pos_order_total = fields.Monetary( string='POS Order Total', compute='_compute_pos_order_total', store=True)

    @api.depends('order_id') def _compute_pos_order_total(self): Order = self.env['pos.order'] for partner in self: total = 0.0 domain = [('partner_id', '=', partner.id)] for o in Order.search(domain): total += o.amount_total partner.pos_order_total = total
Avatar
Zrušit

When you keep store=True, your compute function will be only called when the depends field value is changed.

In your above code, if store=True

_compute_pos_order_total will only be called if order_id field is changed in partner.

Hope this helps.

Thank You

Related Posts Odpovědi Zobrazení Aktivita
1
zář 19
8491
9
bře 20
42071
1
kvě 19
3806
2
říj 18
3986
1
říj 17
4230