我正在尝试将stock.picking
模型中的功能/按钮用于fleet.vehicle.log.services
一个。
到目前为止,我认为:
<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>
<button name="action_confirm" states="draft" string="Mark as Todo" type="object" class="oe_highlight" groups="base.group_user"/>
<button name="action_assign" states="confirmed,waiting" string="Reserve" type="object" class="oe_highlight" groups="base.group_user"/>
<button name="force_assign" states="confirmed,waiting,partially_available" string="Force Availability" type="object" groups="base.group_user"/>
<button name="do_new_transfer" states="draft,partially_available,assigned" string="Validate" groups="stock.group_stock_user" type="object" class="oe_highlight"/>
<button name="do_print_picking" string="Print" groups="stock.group_stock_user" type="object" attrs="{'invisible': [('state', 'not in', ('assigned', 'partially_available'))]}"/>
<button name="%(stock.act_stock_return_picking)d" string="Reverse" states="done" type="action" groups="base.group_user"/>
<button name="action_cancel" states="assigned,confirmed,partially_available,draft,waiting" string="Cancel" groups="base.group_user" type="object"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,partially_available,assigned,done" statusbar_colors='{"shipping_except":"red","invoice_except":"red","waiting_date":"blue"}'/>
</header>
</xpath>
</field>
</record>
在模型上:
_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")
到目前为止,state
字段显示正常,没有问题,但我似乎无法使按钮工作,它们只是没有出现在视图上。
我想我需要像stock_picking
一样将这些功能与state
联系起来,但这些是功能字段......
关于如何实现这一目标的任何想法?
答案 0 :(得分:1)
你几乎得到了它。标头标记必须是表单标记的直接子标记。因此,将该行<xpath expr="//form//sheet//group[1]" position="before">
更改为<xpath expr="//form/sheet" position="before">
应该有所帮助。
至于调用这些函数,我会尝试:
from openerp import models, api
class FleetVehicleLogServices(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")
@api.multi
def action_confirm(self):
for record in self:
record.stock_picking.action_confirm()
return True
你可以用其他方法继续这种方式。