Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
8473 Zobrazení

 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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
čvc 24
2695
1
čvn 24
5153
1
říj 23
10880
1
říj 23
98
1
srp 23
2194