跳至內容
選單
此問題已被標幟
2 回覆
8455 瀏覽次數

 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>


頭像
捨棄
最佳答案

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.


頭像
捨棄
最佳答案

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)

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
7月 24
2686
1
6月 24
5148
1
10月 23
10865
1
10月 23
98
1
8月 23
2193