Skip to Content
Menu
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
Discard
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
Discard
Author

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
Discard
Author

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 Replies Views Activity
3
Aug 16
9081
4
Jun 15
6103
0
Oct 19
2145
0
Jan 16
4570
0
Mar 15
3392