Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
8452 มุมมอง

 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)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 24
2683
1
มิ.ย. 24
5145
1
ต.ค. 23
10855
1
ต.ค. 23
98
413 Request Entity Too Large แก้ไขแล้ว
1
ส.ค. 23
2193