This question has been flagged
1 Reply
3496 Views

I need a button in the view redirect to a website view, but nothing happens when the button is clicked, I checked the button with  a raise Warning and it works, but never redirects

xml:

<record id="quotation_details_tree" model="ir.ui.view">
        <field name="name">Detalle de cotizaciones</field>
        <field name="model">insurance.quotation_detail</field>
        <field name="arch" type="xml">
            <tree string="Detalles Cotizaciones">
                <field name="coverage" />
                <field name="payment_method" />
                <field name="price" />
                <field name="fee_amount" />
                <field name="company_id" />
                <button class="btn btn-primary btn-sm" type="object" name="issue_policy" string="Emitir" />
            </tree>
        </field>
    </record>

and python code in the quotation detail model:

def issue_policy(self):
        return {
            'type': 'ir.actions.act_url',
            'name': "Emitir póliza",
            'url': 'seguro/issue_policy/',
            'target': 'self',
            'context': self,
        }


The qweb page it is working, I can access it through the url.

What is the problem?

Version Odoo 13.0
Avatar
Discard
Best Answer

Hello,

Your action 'context' key messes up the redirect.
During the controller handling of the server response, if there is a 'context' key, it will try to find 'active_id' and 'active_ids' inside that key-value and pass it to the state. In your example, you pass the self directly. Which is just the string representation of the record you are on.

Anyway, in your case, where you redirect to a website view/URL you don't need to pass the context key so you can just return :

def issue_policy(self):
return {
'type': 'ir.actions.act_url',
'name': "Emitir póliza",
'url': 'seguro/issue_policy/',
'target': 'self'    
}

Or you correct your context key like that:

def issue_policy(self):
return {
'type': 'ir.actions.act_url',
'name': "Emitir póliza",
'url': 'seguro/issue_policy/',
'target': 'self',
'context': self._context,
}
Avatar
Discard
Author

Thanks! It worked