Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
4222 Vizualizări

Hello, I am totally new to odoo and I am stuck with this problem: I have a module named "comite technique" that has a one2many field with the "promoteurs" model in on other module, so I had to add a many2one field to the "promoteurs" model to make it work, when I added the many2one field, the promoteurs works pretty fine here is the code of models.py in the promoteurs module:

class promoteurinitiative(models.Model):
    _name = 'initiative.promoteur'
    _rec_name = 'prenom'

    civilite = fields.Many2one('res.partner.title')
    nom = fields.Char(string="Nom", required=True)
    prenom = fields.Char(string="Prénom", required=True)
    date = fields.Date(string="Date de naissance", required=True)
    email = fields.Char()
    country_id = fields.Many2one('res.country', string='Country', ondelete='restrict')
    tel = fields.Char(string="Tél", required=True)
    contract_count = fields.Integer()
    comite_id = fields.Many2one('initiative.comitetechnique', string="Comité technique")

But whenever I add the one2many field in the "comite technique" ,change its view, restart odoo server and try to upgrade the module, I get this error:

(...)
  File "/home/asma/odoo/odoo/modules/registry.py", line 261, in setup_models
    model._setup_fields()
  File "/home/asma/odoo/odoo/models.py", line 2748, in _setup_fields
    field.setup_full(self)
  File "/home/asma/odoo/odoo/fields.py", line 431, in setup_full
    self._setup_regular_full(model)
  File "/home/asma/odoo/odoo/fields.py", line 2981, in _setup_regular_full
    invf = comodel._fields[self.inverse_name]
KeyError: 'comite_id'

Here is the code in models.py of the "comite technique" module:

class comitetechniqueinitiative(models.Model):
    _name = 'initiative.comitetechnique'
    _rec_name = 'date'
    _description = 'comitetechniqueinitiative'

    date = fields.Date(default=fields.Date.today, string="Date de la comité technique", required=True)
    jour = fields.Char( string='Jour')
    pro = fields.One2many('initiative.promoteur','comite_id')


    @api.onchange('date')
    def _get_day_of_date(self):
        for r in self:
            if r.date :
                selected = fields.Datetime.from_string(r.date)
                r.jour = calendar.day_name[selected.weekday()]

I will be grateful if you can help find a solution to this problem. Thank you 


Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

If the both models are defined in same module there wont be issues. Reading the question i understood that you have defined the models in separate modules right ? correct me if i am wrong.

So either you have to make these models in the same module, or give the dependency between module properly and adjust the code.


Thanks

Imagine profil
Abandonează
Autor Cel mai bun răspuns

yes @Niyas Raphy, the models are defined in separate modules, how can give the dependency between the modules properly and make it work, please, I will be thankful if you can help me with this. Thank you (Sorry I can't comment so I am writing here in the response)

Imagine profil
Abandonează
Cel mai bun răspuns

Hi, you are affecting two modules: 'comite technique' and the module that has "promoteurs" model. So when starting Odoo server, you need to update both of them, try './odoo-bin -u all'. This command will update all of your modules and start the server.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
sept. 23
3704
1
dec. 22
2065
1
nov. 22
4515
1
mai 22
3863
0
feb. 22
2293