Hello everyone,
I have been trying to create a custom module in Odoo. What I want to do is add some additional fields for res.company
module. I also want res.partner
module as contact details section for res.company
with OneToMany relation. So far I have inherited res.company module for my custom module and created a One2many field with co-model as res.partner and inverse field as parent_id. I have also inherited xml form views of the company to include the custom fields that I have added. Here is the code for model and views.
Model class:
class ResCompany(models.Model):
_inherit = 'res.company'
contact_ids = fields.One2many('res.partner', 'parent_id', string='Contacts', domain=[('is_company', '=', False)])
comp_industry_type = fields.Many2one('res.partner.industry', string='Industry')
class ResPartner(models.Model):
_inherit = 'res.partner'
parent_id = fields.Many2one('res.company', string='Related Company', index=True)
is_company = fields.Boolean(string='Is a Company', default=False)
View:
res.company.form.inherit
res.company
1
Records are being displayed in Contact Details tab as expected. But when I click on Add a line
button I get the following error:
Traceback (most recent call last): File "D:\odoo-17.0\odoo\http.py", line 1765, in _serve_db return service_model.retrying(self._serve_ir_http, self.env) File "D:\odoo-17.0\odoo\service\model.py", line 133, in retrying result = func() File "D:\odoo-17.0\odoo\http.py", line 1792, in _serve_ir_http response = self.dispatcher.dispatch(rule.endpoint, args) File "D:\odoo-17.0\odoo\http.py", line 1996, in dispatch result = self.request.registry['ir.http']._dispatch(endpoint) File "D:\odoo-17.0\odoo\addons\base\models\ir_http.py", line 222, in _dispatch result = endpoint(**request.params) File "D:\odoo-17.0\odoo\http.py", line 722, in route_wrapper result = endpoint(self, *args, **params_ok) File "d:\odoo-17.0\addons\web\controllers\dataset.py", line 24, in call_kw return self._call_kw(model, method, args, kwargs) File "d:\odoo-17.0\addons\web\controllers\dataset.py", line 20, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "D:\odoo-17.0\odoo\api.py", line 468, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "D:\odoo-17.0\odoo\api.py", line 453, in _call_kw_multi result = method(recs, *args, **kwargs) File "d:\odoo-17.0\addons\web\models\models.py", line 1030, in onchange record._update_cache(changed_values) File "D:\odoo-17.0\odoo\models.py", line 6008, in _update_cache invf._update(inv_recs, self) File "D:\odoo-17.0\odoo\fields.py", line 4173, in _update records.modified([self.name]) File "D:\odoo-17.0\odoo\models.py", line 6723, in modified todo = [self._modified([self._fields[fname] for fname in fnames], create)] File "D:\odoo-17.0\odoo\models.py", line 6723, in todo = [self._modified([self._fields[fname] for fname in fnames], create)] KeyError: 'contact_ids'
Where I am going wrong? Is there any other ways to implement the same? Any help is appreciated.