Odoo Help

0

Model depending another model using "compute" attribute

By
Alessandro Losco
on 4/15/18, 5:50 AM 201 views

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

Alessandro Losco
on 4/15/18, 9:38 AM
0
salah BELHAMICHE
On 4/16/18, 10:39 AM

Try  self.magazzinopieno = True instead of magazzinopieno = True to save the value of magazzinopieno


def _capacityMagazzino(self):

if self.capacitaLotti > 24:

self.magazzinopieno = True

Thank you for your answer

I got this: KeyError: 'capacitaLotti'

Alessandro Losco
on 4/16/18, 11:44 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 4/15/18, 5:50 AM
Seen: 201 times
Last updated: 4/16/18, 10:39 AM