Inside model class, I have given One2many relationship and tried to make tree view inside form view.
This is my model class:
from odoo import models, fields, api
class tms(models.Model):
_name = 'tms.tms'
_description = "Parent"
_columns = {
'name':fields.Char('Parent', size=128, required=True),
'parent_id': fields.one2many('tms.course', 'child_id', 'temp note'),
}
class course(models.Model):
_name = "tms.course"
_description = "Course"
_columns = {
'name': fields.Char('Child', size=128, required=True),
'child_id': fields.many2one('tms.tms', 'Parent Name'),
}
and this is my view.xml
<record model="ir.ui.view" id="tms.list">
<field name="name">tms.tms.tree</field>
<field name="model">tms.tms</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
</tree>
</field>
</record>
<record model="ir.ui.view" id="tms.form">
<field name="name">tms.tms.form</field>
<field name="model">tms.tms</field>
<field name="arch" type="xml">
<form string="Form String">
<sheet>
<notebook>
<page string="Page String">
<field name="parent_id" nolabel="1">
<tree string="Tree String">
<field name="child_id" />
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="action_1" model="ir.actions.act_window">
<field name="name">First view</field>
<field name="res_model">tms.tms</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="view_id"/>
</record>
<record id="action_new_tree" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="tms.list"/>
<field name="act_window_id" ref="action_1"/>
</record>
<record id="action_new_form" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="tms.form"/>
<field name="act_window_id" ref="action_1"/>
</record>
While upgrading the application I am getting this error.
2017-08-18 12:01:20,516 4048 ERROR tms odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
File "C:\odoo-10.0\odoo\http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:\odoo-10.0\odoo\http.py", line 677, in dispatch
result = self._call_function(**self.params)
File "C:\odoo-10.0\odoo\http.py", line 333, in _call_function
return checked_call(self.db, *args, **kwargs)
File "C:\odoo-10.0\odoo\service\model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "C:\odoo-10.0\odoo\http.py", line 326, in checked_call
result = self.endpoint(*a, **kw)
File "C:\odoo-10.0\odoo\http.py", line 935, in __call__
return self.method(*args, **kw)
File "C:\odoo-10.0\odoo\http.py", line 506, in response_wrap
response = f(*args, **kw)
File "C:\odoo-10.0\addons\web\controllers\main.py", line 1154, in load
action = request.env[action_type].browse([action_id]).read()
File "C:\odoo-10.0\odoo\addons\base\ir\ir_actions.py", line 317, in read
result = super(IrActionsActWindow, self).read(fields, load=load)
File "C:\odoo-10.0\odoo\models.py", line 3021, in read
values[name] = field.convert_to_read(record[name], record, use_name_get)
File "C:\odoo-10.0\odoo\models.py", line 5214, in __getitem__
return self._fields[key].__get__(self, type(self))
File "C:\odoo-10.0\odoo\fields.py", line 870, in __get__
self.determine_value(record)
File "C:\odoo-10.0\odoo\fields.py", line 981, in determine_value
self.compute_value(recs)
File "C:\odoo-10.0\odoo\fields.py", line 936, in compute_value
self._compute_value(records)
File "C:\odoo-10.0\odoo\fields.py", line 927, in _compute_value
getattr(records, self.compute)()
File "C:\odoo-10.0\odoo\addons\base\ir\ir_actions.py", line 277, in _compute_search_view
fvg = self.env[act.res_model].fields_view_get(act.search_view_id.id, 'search')
File "C:\odoo-10.0\odoo\api.py", line 753, in __getitem__
return self.registry[model_name]._browse((), self)
File "C:\odoo-10.0\odoo\modules\registry.py", line 174, in __getitem__
return self.models[model_name]
KeyError: u'tms.tms'
I need help to fix this.
I think you cannot define columns by importing "odoo". try defining fields in new api way
Can you tell me how to define? Actually I am new in odoo.
I fixed the above issue. Now it is working fine.