将股票中的选择字段继承到另一个模型中 - Odoo v9 community

Inherit selection field from stock into another model - Odoo v9 community

我将两个模型继承到我的模块中,如下所示:

class fleet_vehicles_services(models.Model):
    _inherit = ["fleet.vehicle.log.services","stock.picking",]

现在,我有这两个字段,它们与stock.picking相关:

stock_picking = fields.Many2one("stock.picking", "Picking")
state = fields.Selection(string="Estados", store=True, readonly=True, related="stock_picking.state")

这些是采摘的状态,现在在我看来:

    <record model='ir.ui.view' id='fleet_vehicle_log_services_form_inherit_1'>
        <field name='name'>fleet.vehicle.log.services.form0</field>
        <field name='model'>fleet.vehicle.log.services</field>
        <field name='inherit_id' ref='fleet.fleet_vehicle_log_services_form'/>
        <field name="priority">89</field>
        <field name='arch' type='xml'>
            <xpath expr="//form//sheet//group[1]" position="before">
            <header>
                <field name="state" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done" statusbar_colors='{"waiting":"blue","confirmed":"blue"}'/>
            </header>
            </xpath>
        </field>
    </record>

但它让我:

ParseError: "Invalid view definition

Error details:
Field `state` does not exist

Error context:
View `fleet.vehicle.log.services.form0`
[view_id: 2084, xml_id: n/a, model: fleet.vehicle.log.services, parent_id: 820]
None" while parsing /home/kristian/odoov9/danisan/fleet_stock/views/fleet_vehicle_log_services.xml:4, near
<record model="ir.ui.view" id="fleet_vehicle_log_services_form_inherit_1">
        <field name="name">fleet.vehicle.log.services.form0</field>
        <field name="model">fleet.vehicle.log.services</field>
        <field name="inherit_id" ref="fleet.fleet_vehicle_log_services_form"/>
        <field name="priority">89</field>
        <field name="arch" type="xml">
            <xpath expr="//form//sheet//group[1]" position="before">
            <header>
                <field name="state" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done" statusbar_colors="{&quot;waiting&quot;:&quot;blue&quot;,&quot;confirmed&quot;:&quot;blue&quot;}"/>
            </header>
            </xpath>
        </field>
    </record>

我不明白,我的意思是,我知道这是一个继承模型,但它应该捕捉到它们,否则,我如何在那个视图上显示它?

有什么想法吗?

您在 stock.picking 中声明了字段,但您正在尝试将其添加到 fleet.vehicle.log.services 表单视图中。

Python代码:

class fleet_vehicles_services(models.Model):
    _inherit = "fleet.vehicle.log.services"

    stock_picking = fields.Many2one("stock.picking", "Picking")
    state = fields.Selection(string="Estados", store=True, readonly=True, related="stock_picking.state")

XML代码:

<record model='ir.ui.view' id='fleet_vehicle_log_services_form_inherit_1'>
        <field name='name'>fleet.vehicle.log.services.form0</field>
        <field name='model'>fleet.vehicle.log.services</field>
        <field name='inherit_id' ref='fleet.fleet_vehicle_log_services_form'/>
        <field name="priority">89</field>
        <field name='arch' type='xml'>
            <xpath expr="//form//sheet//group[1]" position="before">
            <header>
                <field name="state" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done" statusbar_colors='{"waiting":"blue","confirmed":"blue"}'/>
            </header>
            </xpath>
        </field>
    </record>