Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
9038 Lượt xem

I have an onchange of two fields that is launched when modifying one of them.

@api.onchange('name', 'address')
def onchange_name_address(self):
**function code**

I would like to know when it comes into the function of that onchange which field is exactly the one that has launched it, if it has been 'name' or has been 'address'

Is there any way to know it? Thanks in advance

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Refer this link

https://www.odoo.com/forum/help-1/question/how-to-know-which-field-triggers-an-api-depends-86317

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Two onchange - this is answer for you :)


def function_code(self, from)
**function code**

@api.onchange('name')
def onchange_name(self):
    self.function_code(from='name')
   
@api.onchange('address')
def onchange_address(self):  
    self.function_code(from='address')





Ảnh đại diện
Huỷ bỏ
Tác giả

I already considered the option of separating it into two different onchanges, but I wanted to know if there was any internal function or option that would return that value, anyway, thanks for the interest

Josemi, seems like you just can't do it in one onchange :(

Câu trả lời hay nhất

Hi josemi, 

Yes you can.

Check self.Field1 and self._origin.Field1
if they are different, that means Field1 has changed (User interface)
So, in your case you can apply it to name and address.

Let me know when you try it.
Upvote if this helps.

Regards.

Ảnh đại diện
Huỷ bỏ
Tác giả

No, I'll explain you, the onchange is in the lines of an sale order, when I change for example 'name' the line is not created yet, so I can not access self._origin because it does not exist yet

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 18
4525
1
thg 5 16
8432
3
thg 5 16
6294
1
thg 10 24
9073
2
thg 5 25
10392