Reputation: 1
I have 3 models. Module 1 has a One2many relationship with module 2. Module 2 has One2many relationship with Module 3. I am trying to use a View Created for Module 1 to enter data into all the Three modules. The code is provided below. of the models and the views. When I try to add data into Module 3. I am getting the following error.
Traceback (most recent call last):
File "C:\Apps\hrms\odoo\models.py", line 5322, in _update_cache
field_values = [(fields[name], value) for name, value in values.items()]
File "C:\Apps\hrms\odoo\models.py", line 5322, in <listcomp>
field_values = [(fields[name], value) for name, value in values.items()]
KeyError: 'name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Apps\hrms\odoo\http.py", line 1632, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "C:\Apps\hrms\odoo\service\model.py", line 133, in retrying
result = func()
File "C:\Apps\hrms\odoo\http.py", line 1659, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "C:\Apps\hrms\odoo\http.py", line 1863, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "C:\Apps\hrms\odoo\addons\base\models\ir_http.py", line 154, in _dispatch
result = endpoint(**request.params)
File "C:\Apps\hrms\odoo\http.py", line 716, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "c:\apps\hrms\addons\web\controllers\dataset.py", line 42, in call_kw
return self._call_kw(model, method, args, kwargs)
File "c:\apps\hrms\addons\web\controllers\dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "C:\Apps\hrms\odoo\api.py", line 468, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "C:\Apps\hrms\odoo\api.py", line 453, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "C:\Apps\hrms\odoo\models.py", line 6572, in onchange
record._update_cache(changed_values, validate=False)
File "C:\Apps\hrms\odoo\models.py", line 5328, in _update_cache
value = field.convert_to_cache(value, self, validate)
File "C:\Apps\hrms\odoo\fields.py", line 2980, in convert_to_cache
id_ = comodel.new(value, origin=origin).id
File "C:\Apps\hrms\odoo\models.py", line 5754, in new
record._update_cache(values, validate=False)
File "C:\Apps\hrms\odoo\models.py", line 5324, in _update_cache
raise ValueError("Invalid field %r on model %r" % (e.args[0], self._name))
ValueError: Invalid field 'name' on model 'zm.strategic.plans'
The above server error caused the following client error:
null
It is saying that the field is invalid on the model..
Below is the code for the models...
from odoo import api, fields, models
class StrategicPlans(models.Model):
_name = "zm.strategic.plans"
_description = "National Strategic Plans"
_rec_name = "doc_title"
doc_title = fields.Char(string="Title", required="true")
level = fields.Selection([
('1', 'National'),
('2', 'Ministerial')
])
ministry = fields.Char(string="Ministry")
period = fields.Char(string="Plan Year")
objective_ids = fields.One2many('zm.strategic.objective', 'objective_id', string='Strategic Objectives',
copy=True, auto_join=True, ondelete='cascade')
class Objective(models.Model):
_name = 'zm.strategic.objective'
_description = 'Strategy'
name = fields.Char(string='Objective', required=True)
objective_id = fields.Many2one('zm.strategic.plans', string='Objective', required=True,
index=True, copy=False)
objective = fields.Char(string="Strategic Objectives", required="true")
strategy_obj_ids = fields.One2many('zm.strategic.strategy', 'strategy_id', string='Strategies',
copy=True, auto_join=True)
class Strategy(models.Model):
_name = 'zm.strategic.strategy'
_description = 'Strategy'
name = fields.Char(string='Strategy', required=True)
strategy_id = fields.Many2one('zm.strategic.plans', string='Objective', required=True,
index=True, copy=False)
Below is the code for the view that is suppose to handle all of this..
</odoo>
<record id="view_strategic_plan_form" model="ir.ui.view">
<field name="name">zm.strategic.plans.form</field>
<field name="model">zm.strategic.plans</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="doc_title"/>
<field name="period"/>
<field name="level"/>
</group>
<notebook>
<page string="Strategic Objectives">
<field name="objective_ids" context="{'default_strategic_plan_id': active_id}" mode="tree,form">
<form>
<group>
<field name="name" />
<field name="objective" invisible="1" />
</group>
<notebook>
<page string="Strategies">
<field name="strategy_obj_ids" context="{'default_strategic_objective_id': active_id}" mode="tree,form">
<form>
<group>
<field name="name" />
<field name="strategy_id" invisible="1" />
</group>
</form>
</field>
</page>
</notebook>
</form>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<!--The core code that contains the action-->
<record id="action_strategic_plan" model="ir.actions.act_window">
<field name="name">Strategic Plans</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">zm.strategic.plans</field>
<field name="view_mode">tree,form,kanban,pivot</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
</p>
</field>
</record>
</odoo>
I tried defining the context in which to access the fields. I am able to see the field and the name but I cannot add information through that field. I used the code below
context="{'default_strategic_objective_id': active_id}" mode="tree,form"
Upvotes: 0
Views: 56