İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
10774 Görünümler

I've created an @api.depends decorated method for the model project.task, which depends on date_deadline and date_end.

class my_project_task(models.Model): 
_inherit = 'project.task'
@api.depends('date_end','date_deadline')
def method_one(...)

Then, I've created another model, inheriting project.task, named project.maintenance (prototype inheritance). Now, I need to create another @api.depends decorated method for this new model project.maintenance, depending on the same fields (date_deadline and date_end).

class maintenance(models.Model): 
_inherit = 'project.task'
_name = 'project.maintenance'
@api.depends('date_end','date_deadline')
def method_two(...)

The problem is that, when date_deadline and date_end values are changed for the model project.maintenance, the method triggered is method_one and not method_two.

How can I override method_one in this scenario?

Avatar
Vazgeç
En İyi Yanıt

Hi Marie Pinto,

What is the purpose of changing the method name? while both are behaves same.

If your both methods are depends on the same fields you don't need to define another method with different name agreed with Akhil's Ans.

You just need to override the method_first and do changes accordingly in the same method it will work.

@Note: You can handle multile operation via single method if you know the proper use of context.

Hope it will help.

Rgds,

Anil.





Avatar
Vazgeç
Üretici

Thanks for your answer, Anil, however, the method_one and method_two behave completly different.

En İyi Yanıt

@api.depends decorated method is used for compute field. The same method can be used to set values of multiple fields.

Method 1 sets the value of a field1 in project.task. You don't need to create Method 2 in project.maintenance. Try by redefining the same Method 1 in project.maintenance to set the value of both fields.

Avatar
Vazgeç
Üretici

Thank you, @Akhil, but method_one is something like "compute_task_urgency" and method_two is something like "set_schedule_date_end". They do different tasks and I think it would be better to have different method names...

İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Ağu 16
10563
4
Haz 15
7050
0
Eki 19
2861
0
Oca 16
5371
0
Mar 15
4261