Odoo Help

Welcome!

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

0

How to override an @api.depends decorated method?

By
Marie Pinto
on 11/3/15, 4:44 PM 728 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

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
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

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/3/15, 4:44 PM
Seen: 728 times
Last updated: 4/8/16, 3:13 PM