Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
8461 Näkymät

 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
Hylkää
Paras vastaus

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
Hylkää
Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
heinäk. 24
2687
1
kesäk. 24
5151
1
lokak. 23
10868
1
lokak. 23
98
1
elok. 23
2193