Odoo Help

2

2
7 Answers
1
Avatar

Niyas Raphy India

--Niyas Raphy--
27667
| 7 7 11
Wayanad, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

Twitter:https://twitter.com/niyasraphy
LinkedIn: https://www.linkedin.com/in/niyasraphy/
FB:https://www.facebook.com/niyasraphy123
Whatsapp : +917736136763
Happy to help :)

Niyas Raphy India
7/22/19, 2:47 AM

Hi,

There are two things you can do,

1. To rewrite the entire function by inheriting the corresponding model in your custom module. For this in the python file, inherit the corresponding model and copy the function into it and make necessary changes where ever you needed.


2. This method is to super the original function so that the both the function will get executed. For supering/overriding the existing function, see this:  Overriding method in a model


Example:

class HRLeave(models.Model):
_inherit = 'hr.leave'

@api.multi
def action_approve(self):
res = super(HRLeave, self).action_approve()
# add custom codes here
return res

In this the second method is the recommend one.

Thanks

4 Comments
Muhammad Anees Saudi Arabia
7/22/19, 10:08 AM

Hii @Niyas Raphy.

Thanks for the reply

Here is my code in inherited calss

class HrLeave(models.Model):

_inherit = 'hr.leave'

@api.multi

def action_approve(self):

record = super(HrLeave, self).action_approve()

record['state'] = 'confirm'

logging.warning("=======Called action_approve Method========")

return record

But it is never called...

logging.warning is not printed on terminal

record['state'] = 'confirm' is not set

What I am missing?

Thanks,

Niyas Raphy India
7/22/19, 11:14 AM

make sure that the python file is called in init file and also make sure that the module contain this code is installed

Muhammad Anees Saudi Arabia
7/22/19, 1:20 PM

Yes, the file is being called in the init. There are some other methods on the file working fine. Module containing this code is also installed.

Niyas Raphy India
7/22/19, 10:13 PM

This has to be worked, i think debug the code from your side and see.

2
Avatar

Muhammad Anees Saudi Arabia

--Muhammad Anees--

7439
| 7 3 9
Riyadh, Saudi Arabia
--Muhammad Anees--

Odoo, Dynamics AX and Web Developer.

Muhammad Anees Saudi Arabia
7/23/19, 6:17 AM

Its working

@api.multi
def action_confirm(self): record = super(HrLeave, self).action_confirm() if self.message_main_attachment_id.id is False and self.holiday_status_id.time_type == 'full_day_training': raise ValidationError("Please attach document for leave type: %s" % self.holiday_status_id.name) return record


0
Avatar

Manish Kumar Bohra India

--Manish Kumar Bohra--
11863
| 6 5 10
Bikaner, India
--Manish Kumar Bohra--


Manish Kumar Bohra India
7/22/19, 4:28 AM

Hello, 

For any method override, you can use a super method.

    @api.multi
def action_approve(self):
res = super(Class Name, self).action_approve()
# add your condition
return res


Ask a Question
Writer
Keep Informed
1 follower(s)
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