This question has been flagged
2 Replies
7569 Views

 Hello! I want to pop a window (ir.actions.act_window) on the @api.onchange when the user selects a product on a sale.order.line. The problem is that i get no error, but there is no window poping up.

Here is my code on sale.order.line: 

class SaleOrderLine(models.Model):

_inherit = 'sale.order.line'

@api.onchange('product_id')

def check_product_qty(self):

if self.product_id:

self.open_back_order_window(self.product_id)

@api.multi

def open_back_order_window(self, product_id):

vals = {'product_id': product_id}

view_id = self.env['back.order.product.wizard']

new = view_id.create(vals)

form = self.env.ref('module.back_order_product_wizard', False)

return {

'type': 'ir.actions.act_window',

'name': _('Warning : This product is not available at the moment'),

'res_model': 'back.order.product.wizard',

'res_id': new.id,

'view_type': 'form',

'view_mode': 'form',

'views': [(form.id, 'form')],

'view_id': form.id,

'context': vals,

'target': 'new',

}

Here is the code in my wizard: 

from odoo import _, api, fields, models

class BackOrderProductWizard(models.TransientModel):

_name = 'back.order.product.wizard'

alternative_product_ids = fields.Many2many('product.template', string=_('Replacements products'))

@api.multi

def choose_product(self):

pass


Here is the form im trying to show in a window:

<?xml version="1.0" encoding="utf-8"?>

<odoo>

<record model="ir.ui.view" id="back_order_product_wizard">

<field name="name">Choose an alternative product when the one selected is B/O</field>

<field name="model">back.order.product.wizard</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form>

<group>

<span>The product you selected is not available. Please choose an alternative product</span>

</group>

<group>

<field name="alternative_product_ids"/>

</group>

<footer>

<button string="Cancel" special="cancel" class="oe_highlight"/>

<button name="choose_product" string="Choose product" type="object" class="oe_highlight"/>

</footer>

</form>

</field>

</record>

</odoo>


Avatar
Discard
Best Answer

Hi Vincent,

You cannot return action from the onchang. From the onchange you can only perform "Set Value", "Set Domain" and "Raise Warning Message".

Raise warning from onchange

Hope this will help you.


Avatar
Discard
Best Answer

use api.multi before @api.onchange

    @api.multi

    @api.onchange('product_id')

def check_product_qty(self):

if self.product_id:

self.open_back_order_window(self.product_id)

Avatar
Discard