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

NOTE: This question is similar to this one, but its case is a different one with a completely different solution..


I have this situation:

field_1 has a compute method, which uses @api.depends('field_2', 'field_3').

But here comes the important part... the value given to field_1 depends on which field (field_2 or field_3) is modified by ORM (thus triggering the @api.depends).


Is there a way to know which field triggers a multi-triggered @api.depends?

I know I can capture that overriding write, but I would like to be reflected in view.

And I could use a onchange on field_2 and another on field_3, but then it would only be useful in views, no in ORM modifications.


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

hii

its not possible

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

I feared so. So I solved it with an aid field, @api.depends, @api.onchange, write and create override.

@ Alejandro Santana Okay

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


Try this:

from odoo.models import BaseModel
basemodel_modified = BaseModel.modified

@api.multi
def modified_wrapper(self, fnames):
basemodel_modified(self, fnames)
self.env.context = dict(self.env.context, modifier_fnames=fnames, modifier_records=self)

BaseModel.modified = modified_wrapper


Now just look for modifier_names and modifier_records in env.context !


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

You could have a common method and control based on field triggered

 def main_method(self, field_triggered):
# Control with field_triggered field value
#     ....
    pass  

@api.onchange('field1')
def field1_trigger(self):
    self.main_method('field1')

@api.onchange('field2')
def field2_trigger(self):
    self.main_method('field2')


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

OK, I would like to use @api.depends instead of @api.onchange (to get changes in ORM, not only in vies), but I guess it could be. The thing is: you propose I use "compute='main_method'" in my field, but actually triggered with any other methods. Am I right? Mmm... I have to test it.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
8168
3
thg 7 25
8871
1
thg 5 25
1125
0
thg 1 24
1814
1
thg 2 22
23978