0

这是错误,我已经重置了服务器、编译器并删除了所有 .pyc 文件,并且没有拼写错误。architect_ids 存在于模块中,并且也在init .py 中导入。尽管如此,错误是它无法识别或无法读取“architect_ids”字段。依赖已经到位。我不知道如何解决这个问题。

    Error:
Odoo Server Error

Traceback (most recent call last):
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 392, in _check_xml
    self.postprocess_and_fields(view.model, view_doc, view.id)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 952, in postprocess_and_fields
    fields_def = self.postprocess(model, node, view_id, False, fields)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 882, in postprocess
    fields.update(self.postprocess(model, f, view_id, in_tree_view, model_fields))
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 882, in postprocess
    fields.update(self.postprocess(model, f, view_id, in_tree_view, model_fields))
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 882, in postprocess
    fields.update(self.postprocess(model, f, view_id, in_tree_view, model_fields))
  [Previous line repeated 1 more time]
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 803, in postprocess
    xarch, xfields = self.with_context(
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 964, in postprocess_and_fields
    self.raise_view_error(message, view_id)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 592, in raise_view_error
    raise ValueError(message)
ValueError: Field `architect_ids` does not exist

Error context:
View `architect.page.view`
[view_id: 849, xml_id: n/a, model: sale.order, parent_id: 756]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 712, in parse
    self._tag_root(de)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 674, in _tag_root
    f(rec)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 577, in _tag_record
    record = model._load_records([data], self.mode == 'update')
  File "D:\dev\odoo-13.0\odoo\models.py", line 4067, in _load_records
    records = self._load_records_create([data['values'] for data in to_create])
  File "D:\dev\odoo-13.0\odoo\models.py", line 3981, in _load_records_create
    return self.create(values)
  File "<decorator-gen-32>", line 2, in create
  File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
    return create(self, arg)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 473, in create
    return super(View, self).create(vals_list)
  File "<decorator-gen-3>", line 2, in create
  File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
    return create(self, arg)
  File "D:\dev\odoo-13.0\odoo\models.py", line 3762, in create
    fields[0].determine_inverse(batch_recs)
  File "D:\dev\odoo-13.0\odoo\fields.py", line 1114, in determine_inverse
    getattr(records, self.inverse)()
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 299, in _inverse_arch
    view.write(data)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 490, in write
    return super(View, self).write(self._compute_defaults(vals))
  File "D:\dev\odoo-13.0\odoo\models.py", line 3551, in write
    real_recs._validate_fields(set(vals) - set(inverse_fields))
  File "D:\dev\odoo-13.0\odoo\models.py", line 1167, in _validate_fields
    check(self)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 394, in _check_xml
    raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))
odoo.exceptions.ValidationError: ('Error while validating view\n\nField `architect_ids` does not exist\n\nError context:\nView `architect.page.view`\n[view_id: 849, xml_id: n/a, model: sale.order, parent_id: 756]', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\dev\odoo-13.0\odoo\http.py", line 619, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "D:\dev\odoo-13.0\odoo\http.py", line 309, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "D:\dev\odoo-13.0\odoo\tools\pycompat.py", line 14, in reraise
    raise value
  File "D:\dev\odoo-13.0\odoo\http.py", line 664, in dispatch
    result = self._call_function(**self.params)
  File "D:\dev\odoo-13.0\odoo\http.py", line 345, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "D:\dev\odoo-13.0\odoo\service\model.py", line 93, in wrapper
    return f(dbname, *args, **kwargs)
  File "D:\dev\odoo-13.0\odoo\http.py", line 338, in checked_call
    result = self.endpoint(*a, **kw)
  File "D:\dev\odoo-13.0\odoo\http.py", line 910, in __call__
    return self.method(*args, **kw)
  File "D:\dev\odoo-13.0\odoo\http.py", line 510, in response_wrap
    response = f(*args, **kw)
  File "d:\dev\odoo-13.0\addons\web\controllers\main.py", line 1324, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "d:\dev\odoo-13.0\addons\web\controllers\main.py", line 1312, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "D:\dev\odoo-13.0\odoo\api.py", line 387, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "D:\dev\odoo-13.0\odoo\api.py", line 374, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-59>", line 2, in button_immediate_install
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_module.py", line 72, in check_and_log
    return method(self, *args, **kwargs)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_module.py", line 463, in button_immediate_install
    return self._button_immediate_function(type(self).button_install)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_module.py", line 573, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "D:\dev\odoo-13.0\odoo\modules\registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 421, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 313, in load_marked_modules
    loaded, processed = load_module_graph(
  File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 225, in load_module_graph
    load_data(cr, idref, mode, kind='data', package=package, report=report)
  File "D:\dev\odoo-13.0\odoo\modules\loading.py", line 68, in load_data
    tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 736, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 803, in convert_xml_import
    obj.parse(doc.getroot())
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 715, in parse
    pycompat.reraise(
  File "D:\dev\odoo-13.0\odoo\tools\pycompat.py", line 13, in reraise
    raise value.with_traceback(tb)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 712, in parse
    self._tag_root(de)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 674, in _tag_root
    f(rec)
  File "D:\dev\odoo-13.0\odoo\tools\convert.py", line 577, in _tag_record
    record = model._load_records([data], self.mode == 'update')
  File "D:\dev\odoo-13.0\odoo\models.py", line 4067, in _load_records
    records = self._load_records_create([data['values'] for data in to_create])
  File "D:\dev\odoo-13.0\odoo\models.py", line 3981, in _load_records_create
    return self.create(values)
  File "<decorator-gen-32>", line 2, in create
  File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
    return create(self, arg)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 473, in create
    return super(View, self).create(vals_list)
  File "<decorator-gen-3>", line 2, in create
  File "D:\dev\odoo-13.0\odoo\api.py", line 336, in _model_create_multi
    return create(self, arg)
  File "D:\dev\odoo-13.0\odoo\models.py", line 3762, in create
    fields[0].determine_inverse(batch_recs)
  File "D:\dev\odoo-13.0\odoo\fields.py", line 1114, in determine_inverse
    getattr(records, self.inverse)()
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 299, in _inverse_arch
    view.write(data)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 490, in write
    return super(View, self).write(self._compute_defaults(vals))
  File "D:\dev\odoo-13.0\odoo\models.py", line 3551, in write
    real_recs._validate_fields(set(vals) - set(inverse_fields))
  File "D:\dev\odoo-13.0\odoo\models.py", line 1167, in _validate_fields
    check(self)
  File "D:\dev\odoo-13.0\odoo\addons\base\models\ir_ui_view.py", line 394, in _check_xml
    raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating view

Field `architect_ids` does not exist

Error context:
View `architect.page.view`
[view_id: 849, xml_id: n/a, model: sale.order, parent_id: 756]
None" while parsing file:/d:/dev/odoo-13.0/custom/architect_page/views/architect_page.xml:1, near
<odoo>
    <record id="view_order_form" model="ir.ui.view">
        <field name="name">architect.page.view</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//page[@name='order_lines']" position="after">
                <page string="Architect and Interior Designer">
                    <field name="architect_ids">
                        <tree string="Architect and Interior Designer" editable="bottom">
                            <control>
                                <create name="add_architect_control" string="Add a architect"/>
                            </control>
                            <field name="architect_ids"/>
                            <field name="architect_commission"/>
                            <field name="architect_com_type"/>
                        </tree>
                    </field>
                </page>
            </xpath>
        </field>
    </record>
</odoo>

这些是我的模型:

架构师页面.py

from odoo import models, fields


class ArchitectPage(models.Model):
    _inherit = 'sale.order'

    architect_ids = fields.One2many(string='Architect',
                                    comodel_name='res.architect', inverse_name='sale_id')

res_architect.py

from odoo import models, fields, api, exceptions


class ResArchitect(models.Model):
    _name = 'res.architect'
    name = fields.Char('name')
    architect_com_type = fields.Selection(string='Commission type',
                                          selection=[('percentage', 'Percentage'), ('float', 'Float')])
    architect_commission = fields.Float(string='Architect Commission')
    sale_id = fields.Many2one(string='sale', comodel_name='sale.order')

    # put your constraint here
    @api.constrains('architect_com_type', 'architect_commission')
    def _validate_commission(self):
        for field in self:
            if field.architect_com_type == 'Percentage':
                if (field.architect_com_type > 100) or (field.architect_com_type <= 0):
                    raise exceptions.ValidationError(
                        "Percentage fields must be less than equal to 100 or greater than 0")

xml:

<odoo>
    <record id="view_order_form" model="ir.ui.view">
        <field name="name">architect.page.view</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//page[@name='order_lines']" position="after">
                <page string="Architect and Interior Designer">
                    <field name='architect_ids'>
                        <tree string="Architect and Interior Designer"
                              editable="bottom">
                            <control>
                                <create name="add_architect_control" string="Add a architect"/>
                            </control>
                            <field name="architect_ids"/>
                            <field name="architect_commission"/>
                            <field name="architect_com_type"/>
                        </tree>
                    </field>
                </page>
            </xpath>
        </field>
    </record>
</odoo>

其他自定义模块:

# -*- coding: utf-8 -*-

from odoo import models, fields, api


class architect(models.Model):
    _name = 'architect.form'
    _description = 'architect'

    prefix_id = fields.Selection(
        [('company', 'COMPANY'), ('architect', 'ARCH'), ('interior designer', 'ID'), ('others', 'OTHERS')],
        required=True)
    first_name = fields.Char(string="First Name", required=True)
    last_name = fields.Char(string="Last Name", required=True)
    address = fields.Char(string="Address", required=True)
    email = fields.Char(string="Email")
    mobile_no = fields.Char(string="Mobile No.")
    tel_no = fields.Char(string="Telephone No.")
4

2 回答 2

1

在您的模型 ['sale.order'] 视图中,定义了architect_ids字段 [ One2many ]。

在您的 XML 文件中,您已经添加了One2many字段,您已经添加了不需要的字段architect_ids,它不在您正在访问的模型上[' res.architect ']。在这里检查,

<odoo>
    <record id="view_order_form" model="ir.ui.view">
        <field name="name">architect.page.view</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="XML">
            <xpath expr="//page[@name='order_lines']" position="after">
                <page string="Architect and Interior Designer">
                    <field name='architect_ids'>
                        <tree string="Architect and Interior Designer"
                          editable="bottom">
                            <control>
                                <create name="add_architect_control" string="Add a architect"/>
                            </control>
                            <field name="architect_commission"/>
                            <field name="architect_com_type"/>
                        </tree>
                    </field>
                </page>
            </xpath>
        </field>
    </record>
</odoo>

谢谢

于 2020-03-21T09:27:10.960 回答
1

消除

建筑师 ID

从树视图

                       <field name='architect_ids'>
                        <tree string="Architect and Interior Designer"
                              editable="bottom">
                            <control>
                                <create name="add_architect_control" string="Add a architect"/>
                            </control>
                           <!-- Removing architect_ids from view -->
                           <!-- <field name="architect_ids"/> -->
                            <field name="architect_commission"/>
                            <field name="architect_com_type"/>
                        </tree>
                    </field>
于 2020-03-21T09:19:12.910 回答