Odoo Help

2

2
7 回答
1
アバター

Niyas Raphy インド

--Niyas Raphy--
29518
| 7 7 11
Wayanad, インド
--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 インド
2019/07/22 2:47

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 コメント
Muhammad Anees サウジアラビア
2019/07/22 10:08

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 インド
2019/07/22 11:14

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 サウジアラビア
2019/07/22 13:20

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 インド
2019/07/22 22:13

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

2
アバター

Muhammad Anees サウジアラビア

--Muhammad Anees--

7468
| 7 3 9
Riyadh, サウジアラビア
--Muhammad Anees--

Odoo, Dynamics AX and Web Developer.

Muhammad Anees サウジアラビア
2019/07/23 6:17

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
アバター

Manish Kumar Bohra インド

--Manish Kumar Bohra--
11921
| 6 5 10
Bikaner, インド
--Manish Kumar Bohra--
  • 2.5+ years of experience in the Information Technology Industry.

  • Experience in enterprise resource application architecture, development, testing, configuration, and implementation.  

  • Knowledge in Odoo (OpenERP), Python, XML, PostgreSQL

  • Domain knowledge of CRM, Project Management, Sale Management, Inventory Management, Purchase Management, HR Management, Singapore Payroll Management, Learning Management

  • Integrate odoo with Native mobile app and provides a rest api odoo

Manish Kumar Bohra インド
2019/07/22 4:28

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


質問する
Writer
タグ
Keep Informed
1 フォロワー
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