替换原始字段时出现未捕获的错误

时间:2018-08-21 15:23:35

标签: odoo odoo-8 odoo-9

所以我想用自定义模型替换字段城市,但​​是出现此错误。我认为可能是某些域尝试使用旧的“城市”字段,但我找不到它。

Uncaught Error: NameError: name 'city' is not defined
from openerp import fields, models


class ResCity(models.Model):
    _name = 'res.city'
    _description = 'Res City'

    name = fields.Char(string='Name', required=True)
    country_id = fields.Many2one(
        'res.country', string='Country')


class ResCountry(models.Model):
    _inherit = 'res.country'

    city_ids = fields.One2many(
        'res.city', 'country_id', string="City's")


class ResPartner(models.Model):
    _inherit = 'res.partner'
city_id = fields.Many2one('res.city', string='City')
 <record id="view_contact_form" model="ir.ui.view">
                <field name="name">res.partner.view</field>
                <field name="model">res.partner</field>
                <field name="priority" eval="101"/>
                <field name="inherit_id" ref="base.view_partner_form"/>
                <field name="arch" type="xml">
    <field name="city_id" position="replace">
                        <field name="city_id" placeholder="City"/>
                    </field>
    <xpath expr="//field[@name='child_ids']/form//field[@name='city']" position="replace">
                        <field name="city_id" placeholder="City"/>
                    </xpath>

1 个答案:

答案 0 :(得分:-1)

在您的代码段中,插入对city字段的引用,这将导致该错误消息。您需要用对新字段city的引用替换对原始格式city_id的引用:

<record id="view_contact_form" model="ir.ui.view">
    <field name="name">res.partner.view</field>
    <field name="model">res.partner</field>
    <field name="priority" eval="101"/>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='city']" position="replace">
            <field name="city_id" placeholder="Select city..."/>
        </xpath>
    </field>
</record>