Odoo Help

0

How to override an @api.depends decorated method?

By
Marie Pinto
on 11/3/15, 4:44 PM 1,297 views

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?

2
Anil R. Kesariya
On 11/4/15, 1:50 AM

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.





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

Marie Pinto
on 11/4/15, 9:18 AM
1
Akhil P Sivan
On 11/3/15, 9:13 PM

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

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

Marie Pinto
on 11/4/15, 9:22 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 11/3/15, 4:44 PM
Seen: 1297 times
Last updated: 9/13/17, 6:48 AM