我将继承两个模型到我的模块中,如下所示:
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="{"waiting":"blue","confirmed":"blue"}"/>
</header>
</xpath>
</field>
</record>
我不明白,我的意思是,我知道这是一个继承的模型,但它应该抓住它们,否则,我怎么能在那个视图上显示这个?
有什么想法吗?
答案 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>