I have a model in which i want that a field of one Entity depends on a field of another entity. Entities are bound with one2many/many2one relationship. I tried the following code but without success
I tried to follow official documentation example here: https://www.odoo.com/documentation/11.0/howtos/backend.html#dependencies but since code isn't complete I have difficulty in guessing variables
I also found some examples with @api.one and @api.multi and I would like to know the difference with @api.depends
class Cantiere(models.Model):
_name = 'modulotest01.cantiere'
name = fields.Char(required=True)
description = fields.Text()
magazzino = fields.One2many('modulotest01.magazzino', 'cantiere')
magazzinopieno = fields.Boolean(compute="_capacityMagazzino", store=True)
@api.depends('capacitaLotti', 'modulotest01.magazzino')
def _capacityMagazzino(self):
if self.capacitaLotti > 24:
magazzinopieno = True
class Magazzino(models.Model):
_name = 'modulotest01.magazzino'
capacitaLotti = fields.Integer()
cantiere = fields.Many2one('modulotest01.cantiere', string='Cantiere', index=True, ondelete='cascade' )
i tried with
capacitaMagazzini = fields.Integer('Magazzino Pieno', related='magazzino.capacitaLotti')
but in this way i get only the capacitaLotti of the first magazzino in the list