Odoo 从 "more" 按钮更改工作流状态

Odoo change workflow state from "more" button

我想通过 'more' 按钮更改某些发票的状态。因此,当我 select 来自树视图的一些发票和 select 来自 'more' 按钮下方的按钮 'cancel all' 时。

请帮忙

您必须使用服务器操作来执行此操作。将下一个代码添加到自定义模块中的 XML 文件中:

<record id="change_state_action" model="ir.actions.server">
    <field name="name">Change invoice state</field>
    <field name="model_id" ref="model_account_invoice"/>
    <field name="state">code</field>
    <field name="code">
action = self.your_method_to_change_state(cr, user.id, context.get('active_ids', []), context=context)
    </field>
</record>

<record id="change_state_option" model="ir.values">
    <field name="name">Change invoice state</field>
    <field name="key2" eval="'client_action_multi'"/>
    <field name="model" eval="'account.invoice'"/>
    <field name="value" eval="'ir.actions.server,%d'%change_state_action"/>
</record>

code字段中,您必须填写action = whatever python code you want。您必须考虑到 Python 代码的行为必须像您在 account.invoice 模型中工作一样。

因此您必须将此代码放入模块中的 Python 文件中:

class account_invoice(models.Model):
    _inherit = 'account.invoice'

    @api.multi
    def your_method_to_change_state(self):
        self.write({'state': 'XXXXX'})