Search code examples
xmlpython-2.7odoo-8odoo

Odoo change workflow state from "more" button


I'd like to change the state of some invoices from the 'more'-button. So when I select some invoices from the treeview and select a button 'cancel all' from under the 'more'-button.

Any help please


Solution

  • You have to use a server action to do that. Add the next code to a XML file in your customized module:

    <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>
    

    In code field, you must write action = whatever python code you want. You have to take in to account that Python code must behave as if you were working in account.invoice model.

    So you have to put this code in a Python file in your module:

    class account_invoice(models.Model):
        _inherit = 'account.invoice'
    
        @api.multi
        def your_method_to_change_state(self):
            self.write({'state': 'XXXXX'})