2

I have this action server:

def obtener_todos_los_adjuntos_en_un_zip(self):
        
        tab_id = []
        
        for invoice in self:
            tab_id.append(invoice.id)

        base_url = self.env['ir.config_parameter'].get_param('web.base.url')

        url = f'{base_url}/web/binary/descargar_adjuntos?ids={"-".join(str(x) for x in tab_id)}'
        
        return {
            "type": "ir.actions.act_url",
            "url": url,
            "target": "new",
        }

In my xml:

<odoo>

    <record id="account_move_action_server"
        model="ir.actions.server">
        <field name="name">Descargar todos los adjuntos</field>
        <field name="model_id"
            ref="model_account_move" />
        <field name="binding_model_id"
            ref="model_account_move" />
        <field name="state">code</field>
        <field name="code">
        if records:
            records.obtener_todos_los_adjuntos_en_un_zip()
            
        </field>
    </record>

</odoo>

But it is not doing anything with the url passed to it. What do I need to do to make this action.url work?

Legna
  • 460
  • 6
  • 19

1 Answers1

1

So I need to return to a "action" var:

<odoo>

    <record id="account_move_action_server"
        model="ir.actions.server">
        <field name="name">Descargar todos los adjuntos</field>
        <field name="model_id"
            ref="model_account_move" />
        <field name="binding_model_id"
            ref="model_account_move" />
        <field name="state">code</field>
        <field name="code">
        if records:
            action = records.obtener_todos_los_adjuntos_en_un_zip()
            
        </field>
    </record>

</odoo>

From odoo docs:

The code segment can define a variable called action, which will be >returned to the client as the next action to execute:

<record model="ir.actions.server" id="print_instance">
    <field name="name">Res Partner Server Action</field>
    <field name="model_id" ref="model_res_partner"/>
    <field name="state">code</field>
    <field name="code">
        if record.some_condition():
            action = {
                "type": "ir.actions.act_window",
                "view_mode": "form",
                "res_model": record._name,
                "res_id": record.id,
            }
    </field>
</record>

will ask the client to open a form for the record if it fulfills some condition

Legna
  • 460
  • 6
  • 19