Skip to Content
Menú
This question has been flagged

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
Descartar
Best Answer

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
Descartar
Autor

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

Best Answer

@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
Descartar
Autor

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...

Related Posts Respostes Vistes Activitat
3
d’ag. 16
10567
4
de juny 15
7054
0
d’oct. 19
2866
0
de gen. 16
5376
0
de març 15
4261