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

In the latest Odoo, usage of Api decorators (api.onchange) to perform onchange functionalities eases our job,

however I wonder how to call such onchange methods into another method, by passing those required parameters.


Let me take an example of SaleOrderLine object& its onchange method, say product_id_change

Standard definition of product_id_change is something like as follows:

@api.onchange('product_id')    
def product_id_change(self):
if not self.product_id:
return {'domain': {'product_uom': []}}
...


Now, say in my custom module/method, am trying to call this onchange method, as it would be easier to create Sale-Order-line using those returned vals.

If it was traditional method, then I could have simply called it by passing its parameter as follows

sol_obj.product_id_change(PRODUCT_ID)

which would have returned those desired vals, however since we happen to use API decorator, I wonder how to pass those parameter.


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Solution:

For those who are looking for the same.


linevals = {'product_id': PRODUCT_ID, ...} # basic needed data for the execution of Onchange-Method

line = self.env['sale.order.line'].new(linevals)
line.product_id_change()
linevals = line._convert_to_write({name: line[name] for name in line._cache})
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi deep

Here is how with an example

https://www.odoo.com/es_ES/forum/ayuda-1/question/how-to-get-a-virtual-recordset-from-an-ordinary-recordset-111286#answer-111330

อวตาร
ละทิ้ง
ผู้เขียน

Wow, worked like a charm, after little changes, Will be adding it here for future reference. Thank you.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
เม.ย. 24
2674
0
พ.ย. 23
1117
2
ธ.ค. 22
7328
Return a view from a onchange function แก้ไขแล้ว
2
ม.ค. 17
8234
API onchange Odoo 10.0 แก้ไขแล้ว
1
ธ.ค. 22
3985