将按钮功能从一个模型继承到另一个模型 - Odoo v9 community

Inherit button function from one model into another - Odoo v9 community

我正在尝试将 stock.picking 模型中的 functions/buttons 用于 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 所做的那样,但这些是函数字段...

关于如何实现这一点有什么想法吗?

你差不多明白了。 header 标签必须是 form 标签的直接子标签。因此,将 <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

你可以用其他方法继续这种方式。