This question has been flagged
7530 Views

Want to implement a server action (in the end, such action pops up an account.voucher dialog) for invoices. Only true invoices to clients / supplier are considered, while refunds are not considered. In the odoo core, such 4 actions (client invoice, client refund, supplier invoice, supplier refund) are defined like this:

    <record id="action_invoice_tree1" model="ir.actions.act_window">
        <field name="name">Customer Invoices</field>
        <field name="res_model">account.invoice</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form,calendar,graph</field>
        <field eval="False" name="view_id"/>
        <field name="domain">[('type','=','out_invoice')]</field>
        <field name="context">{'default_type':'out_invoice', 'type':'out_invoice', 'journal_type': 'sale'}</field>
        <field name="search_view_id" ref="view_account_invoice_filter"/>
        <field name="help" type="html">
            bla bla bla
        </field>
    </record>

This is just an example. By replacing out_invoice with the other 4 types, you have all the 4 actions.

Now the funny part: I want to implement a server action (my server action triggers an account.invoice function) that processes a bulk of selected invoices in the TREE, but taking the value in the "type" key in the context.

    <record id="action_massive_pay" model="ir.actions.server">
        <field name="state">code</field>
        <field name="type">ir.actions.server</field>
        <field name="model_id" ref="model_account_invoice"/>
        <field name="code">action = self.massive_invoice_pay_wizard(cr, uid, context.get('active_ids', []), context)</field>
        <field name="condition">True</field>
        <field name="name">Register Massive Payment</field> 
    </record>

    <record id="action_massive_pay_more_link" model="ir.values">
        <field name="model_id" ref="model_account_invoice" />
        <field name="name">Register Massive Payment</field>
        <field name="key2">client_action_multi</field>
        <field name="value" eval="'ir.actions.server,' + str(ref('action_massive_pay'))"/>
        <field name="key">action</field>
        <field name="model">account.invoice</field> 
    </record>

In the implementation of massive_invoice_pay_wizard, I expect to be able to access the "type" key in the context, as it was provided by the originating actions (actions that displayed the tree), but the "type" key is not present while I ask for it in the context (type, default_type, and stuff like that as specified in the original actions are not present when I debug the context in my method).

So I tried to add the tag `<field name="context">{'type': type}</field>` both in the ir.values and the new server action records, but nothing happened: ir.values does not expect a context, and somehow the server action does not receive the context from the original action.

Finally, my goal is to have processing for two different invoice types, disallow credit/debit notes, and present an account.voucher dialog (one for all the selected invoices). How can I pass such context?

Avatar
Discard

ADD THIS TO THE code tage

<field name="code">

if records:

action = records.action_export_and_download()

</field>