Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4354 Lượt xem

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 


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 23
3849
1
thg 12 22
2153
1
thg 11 22
4659
1
thg 5 22
3961
0
thg 2 22
2356