将库存中的选择字段继承到另一个模型 - Odoo v9社区

时间:2017-01-13 02:21:03

标签: python inheritance openerp qweb

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

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>

我不明白,我的意思是,我知道这是一个继承的模型,但它应该抓住它们,否则,我怎么能在那个视图上显示这个?

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

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>