In the model, I have defined a function 'FOO'; a user create a record 'X' of this model and saved it.
after that, I want the funciton 'FOO' would run automatically once the user open the existed record 'X'; is this possible?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
In the model, I have defined a function 'FOO'; a user create a record 'X' of this model and saved it.
after that, I want the funciton 'FOO' would run automatically once the user open the existed record 'X'; is this possible?
Hello,
They Have Two Options :
Option 1:
You can use fields_view_get method. Try below code maybe it helps you
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
res = super(Project, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
# add here your condition
return res
Option 2:
You can use the compute method but in your case, this method not depends on any field mean you can use @api.multi in place of @api.depends
Thanks
thank you very much.
A few approaches came to my mind.
The first 'hacky' way is to introduce some dummy field with a compute method, but which is not stored. An example:
@api.multi
def _compute_dummy_field(self):
# the method is triggered since a field should be re-computed
self.my_method() # now trigger your function
dummy_field = fields.Char(
compute=_compute_dummy_field,
store=False,
)
Do not forget to add dummy_field to a form view or any xml which reload should result in your function. Otherwise, 'compute' would not be launched.
Take also into account that in such a way you tigger a method, but you would not be able to return some window action. Just some calculations.
The second it to re-define the 'open' method on Javascript level (not simple!). Here you can apply an RPC method. For hints have a look here: https://odoo-master.readthedocs.io/en/latest/reference/javascript.html#rpc
thank you for you reply.
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 9 22
|
3800 | ||
|
1
thg 7 25
|
363 | ||
|
0
thg 7 25
|
397 | ||
|
1
thg 5 25
|
889 | ||
|
0
thg 3 25
|
1020 |