列“ res_model”中的空值违反了Odoo11中的非空约束

时间:2018-10-08 06:29:18

标签: python python-3.x inheritance odoo odoo-11

我正在浏览odoo11(https://www.odoo.com/documentation/11.0/howtos/backend.html#inheritance)的文档,但是当我仔细遵循每个步骤并确认多次后,却陷入了Inheritance部分,无法运行我的模块。

  

partner.py

# -*- coding: utf-8 -*-
from odoo import fields, models
class Partner(models.Model):
    _inherit = 'res.partner'

# Add a new coumn to res.partner model, by default parameters are not instructors.
    instructor = fields.Boolean("Instructor", default='False')
    session_ids = fields.Many2many('openacademy.session', 
                                    string="Attended Sessions",
                                    readonly=True)
  

partner.xml

<?xml version="1.0" encoding="UTF-8"?>

<odoo>
<!-- Add instructor field to existing view. -->
  <record model="ir.ui.view" id="partner_instructor_form_view">
    <field name="name">partner.instructor</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
      <notebook position="inside">
        <page string="Sessions">
          <group>
            <field name="instructor"/>
            <field name="session_ids"/>
          </group>
        </page>
      </notebook>
    </field>
  </record>

    <record model="ir.actions.act_window" id="contact_list_action">
      <field name="name">Contacts</field>
      <field name="model">res.partner</field>
      <field name="view_type">form</field>
      <field name="view_mode">tree,form</field>
    </record>    
  <menuitem id="configuration_menu" name="Configuration" parent="main_openacademy_menu"/>
  <menuitem id="contact_menu" name="Contacts" parent="configuration_menu" action="contact_list_action"/>
</odoo>

我还分别在__init__.py和__manifest__.py中添加了这些文件名。

  

错误消息

2018-10-08 06:11:56,242 14284 WARNING odoo11 odoo.models: ir.actions.act_window.create() includes unknown fields: model
2018-10-08 06:11:56,243 14284 ERROR odoo11 odoo.sql_db: bad query: b'INSERT INTO "ir_act_window" ("id", "binding_type", "type", "context", "auto_search", "limit", "target", "name", "view_type", "view_mode", "filter", "multi", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval(\'ir_actions_id_seq\'), \'action\', \'ir.actions.act_window\', \'{}\', true, 80, \'current\', \'Contacts\', \'form\', \'form\', false, false, 1, 1, (now() at time zone \'UTC\'), (now() at time zone \'UTC\')) RETURNING id'
ERROR: null value in column "res_model" violates not-null constraint
DETAIL:  Failing row contains (297, Contacts, ir.actions.act_window, null, null, action, 1, 2018-10-08 06:11:56.093253, 1, 2018-10-08 06:11:56.093253, null, null, {}, null, null, null, current, form, form, null, 80, null, f, t, f).

2018-10-08 06:11:56,244 14284 WARNING odoo11 odoo.modules.loading: Transient module states were reset
2018-10-08 06:11:56,245 14284 ERROR odoo11 odoo.modules.registry: Failed to load registry
Traceback (most recent call last):
  File "/odoo/odoo-server/odoo/modules/registry.py", line 59, in __new__
    return cls.registries[db_name]
  File "/odoo/odoo-server/odoo/tools/func.py", line 68, in wrapper
    return func(self, *args, **kwargs)
  File "/odoo/odoo-server/odoo/tools/lru.py", line 44, in __getitem__
    a = self.d[obj].me
KeyError: 'odoo11'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/odoo/odoo-server/odoo/tools/convert.py", line 744, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/odoo/odoo-server/odoo/tools/convert.py", line 654, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_model.py", line 1487, in _update
    record = record.create(values)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_actions.py", line 230, in create
    return super(IrActionsActWindow, self).create(vals)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_actions.py", line 57, in create
    res = super(IrActions, self).create(vals)
  File "/odoo/odoo-server/odoo/models.py", line 3372, in create
    record = self.browse(self._create(old_vals))
  File "/odoo/odoo-server/odoo/models.py", line 3465, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/odoo/odoo-server/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/odoo/odoo-server/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
psycopg2.IntegrityError: null value in column "res_model" violates not-null constraint
DETAIL:  Failing row contains (297, Contacts, ir.actions.act_window, null, null, action, 1, 2018-10-08 06:11:56.093253, 1, 2018-10-08 06:11:56.093253, null, null, {}, null, null, null, current, form, form, null, 80, null, f, t, f).


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/odoo/odoo-server/odoo/modules/registry.py", line 85, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/odoo/odoo-server/odoo/modules/loading.py", line 376, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/odoo/odoo-server/odoo/modules/loading.py", line 274, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/odoo/odoo-server/odoo/modules/loading.py", line 181, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/odoo/odoo-server/odoo/modules/loading.py", line 95, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/odoo/odoo-server/odoo/tools/convert.py", line 791, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/odoo/odoo-server/odoo/tools/convert.py", line 852, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/odoo/odoo-server/odoo/tools/convert.py", line 751, in parse
    exc_info[2]
  File "/odoo/odoo-server/odoo/tools/pycompat.py", line 86, in reraise
    raise value.with_traceback(tb)
  File "/odoo/odoo-server/odoo/tools/convert.py", line 744, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/odoo/odoo-server/odoo/tools/convert.py", line 654, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_model.py", line 1487, in _update
    record = record.create(values)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_actions.py", line 230, in create
    return super(IrActionsActWindow, self).create(vals)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_actions.py", line 57, in create
    res = super(IrActions, self).create(vals)
  File "/odoo/odoo-server/odoo/models.py", line 3372, in create
    record = self.browse(self._create(old_vals))
  File "/odoo/odoo-server/odoo/models.py", line 3465, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/odoo/odoo-server/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/odoo/odoo-server/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
odoo.tools.convert.ParseError: "null value in column "res_model" violates not-null constraint
DETAIL:  Failing row contains (297, Contacts, ir.actions.act_window, null, null, action, 1, 2018-10-08 06:11:56.093253, 1, 2018-10-08 06:11:56.093253, null, null, {}, null, null, null, current, form, form, null, 80, null, f, t, f).
" while parsing /odoo/odoo-server/custom_addons/openacademy/views/partner.xml:21, near
<record model="ir.actions.act_window" id="contact_list_action">
    <field name="name">Contacts</field>
    <field name="model">res.partner</field>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
  </record>
  

我没有做任何更改,这些代码来自文档本身。

请帮助我。 非常感谢您的快速帮助,并在此先感谢。

请让我知道是否有人需要更多详细信息。

1 个答案:

答案 0 :(得分:1)

在partner.xml中,您的操作中有一个名为“模型”的字段。您应该在其中使用“ res_model”字段。文档页面上的来源正确。请在代码中更正act_window规范模型-> res_model:

...
   <record model="ir.actions.act_window" id="contact_list_action">
      <field name="name">Contacts</field>
      <field name="res_model">res.partner</field>
...