Skip to Content
Menu
This question has been flagged
1 Reply
1212 Views

hello to all - in may class, i have to set set set value of a field with the property compute, and this is what i did in my class:


class cave_casier_plein(models.Model):

    _name = 'cave.casier_plein'


    def calculeQte(self):

        total = 0

        for record in self.env['cave.approvi'].search([('idcasier', '=', self.id)]):

            total += record.qte

        self.qte = total # this lead to an error

    qte = fields.Integer('Quantité', compute='calculeQte', store=False, readonly=True)

here i'ld like help to updte the 'qte' value of this class when the 'qte' value of class 'cave.approvi' come to change.
thanks

Avatar
Discard
Best Answer

Try this one

class cave_casier_plein(models.Model):

    _name = 'cave.casier_plein'


    @api.multi

    def calculeQte(self):

        for rec in self:

            total = 0

            for record in self.env['cave.approvi'].search([('idcasier', '=', rec.id)]):

                total += record.qte

            rec.update({'qte': total})   
        

      qte = fields.Integer(string='Quantité', compute='calculeQte', store=False, readonly=True)


Avatar
Discard