'res.one' has a one2many relation with 'res.many'.
'res.one' should pass a default value of the field 'model_id' in 'res.many'.
This works: context={'default_model_id': 1}
This gives error: context={'default_model_id': self.env.ref('one2many_error.model_res_one').id}
Why?
__manifest__.py
{
'name': "one2many_error",
'depends': ['base'],
'data': ['views.xml'],
}
models.py
from odoo import api, fields, models, _
class Many(models.Model):
_name = 'res.many'
name = fields.Char()
model_id = fields.Many2one('ir.model')
one_id = fields.Many2one('res.one')
class One(models.Model):
_name = 'res.one'
name = fields.Char()
def _compute_context(self):
#return {'default_model_id': self.env.ref('one2many_error.model_res_one').id}return {'default_model_id': 1}
many_ids = fields.One2many('res.many', 'one_id',
context=_compute_context,
)
views.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="view_res_one_a_form">
<field name="name">res.one.form</field>
<field name="model">res.one</field>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<form>
<field name="name"/>
<field name="many_ids">
<tree editable="bottom">
<field name="name"/>
<field name="model_id"/>
<field name="one_id"/>
</tree>
</field>
</form>
</field>
</record>
</data>
</odoo>
Odoo Server Error
Traceback (most recent call last): File "C:\Program Files\Odoo 10.0\server\odoo\http.py", line 640, in _handle_exception File "C:\Program Files\Odoo 10.0\server\odoo\http.py", line 677, in dispatch File "C:\Program Files\Odoo 10.0\server\odoo\http.py", line 333, in _call_function File "C:\Program Files\Odoo 10.0\server\odoo\service\model.py", line 101, in wrapper File "C:\Program Files\Odoo 10.0\server\odoo\http.py", line 326, in checked_call File "C:\Program Files\Odoo 10.0\server\odoo\http.py", line 935, in __call__ File "C:\Program Files\Odoo 10.0\server\odoo\http.py", line 506, in response_wrap File "C:\Program Files\Odoo 10.0\server\odoo\addons\web\controllers\main.py", line 894, in call_button File "C:\Program Files\Odoo 10.0\server\odoo\addons\web\controllers\main.py", line 882, in _call_kw File "C:\Program Files\Odoo 10.0\server\odoo\api.py", line 689, in call_kw File "C:\Program Files\Odoo 10.0\server\odoo\api.py", line 680, in call_kw_multi File "C:\Program Files\Odoo 10.0\server\odoo\addons\base\module\module.py", line 528, in button_immediate_upgrade File "C:\Program Files\Odoo 10.0\server\odoo\addons\base\module\module.py", line 485, in _button_immediate_function File "C:\Program Files\Odoo 10.0\server\odoo\modules\registry.py", line 83, in new File "C:\Program Files\Odoo 10.0\server\odoo\modules\loading.py", line 335, in load_modules File "C:\Program Files\Odoo 10.0\server\odoo\modules\loading.py", line 237, in load_marked_modules File "C:\Program Files\Odoo 10.0\server\odoo\modules\loading.py", line 156, in load_module_graph File "C:\Program Files\Odoo 10.0\server\odoo\modules\loading.py", line 95, in _load_data File "C:\Program Files\Odoo 10.0\server\odoo\tools\convert.py", line 845, in convert_file File "C:\Program Files\Odoo 10.0\server\odoo\tools\convert.py", line 915, in convert_xml_import File "C:\Program Files\Odoo 10.0\server\odoo\tools\convert.py", line 796, in parse File "C:\Program Files\Odoo 10.0\server\odoo\tools\convert.py", line 799, in parse File "C:\Program Files\Odoo 10.0\server\odoo\tools\convert.py", line 707, in _tag_record File "C:\Program Files\Odoo 10.0\server\odoo\addons\base\ir\ir_model.py", line 1190, in _update File "C:\Program Files\Odoo 10.0\server\odoo\addons\base\ir\ir_ui_view.py", line 380, in write File "C:\Program Files\Odoo 10.0\server\odoo\models.py", line 3565, in write File "C:\Program Files\Odoo 10.0\server\odoo\fields.py", line 1041, in determine_inverse File "C:\Program Files\Odoo 10.0\server\odoo\addons\base\ir\ir_ui_view.py", line 220, in _inverse_arch File "C:\Program Files\Odoo 10.0\server\odoo\addons\base\ir\ir_ui_view.py", line 380, in write File "C:\Program Files\Odoo 10.0\server\odoo\models.py", line 3557, in write File "C:\Program Files\Odoo 10.0\server\odoo\models.py", line 3708, in _write File "C:\Program Files\Odoo 10.0\server\odoo\models.py", line 1079, in _validate_fields ParseError: "Error while validating constraint 'Environment' object has no attribute 'env' None" while parsing file:///c:/users/henrik/documents/bitbucket/test/one2many_error/views.xml:4, near <record model="ir.ui.view" id="view_res_one_a_form"> <field name="name">res.one.form</field> <field name="model">res.one</field> <field name="priority" eval="20"/> <field name="arch" type="xml"> <form> <field name="name"/> <field name="many_ids"> <tree editable="bottom"> <field name="name"/> <field name="model_id"/> <field name="one_id"/> </tree> </field> </form> </field> </record>