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.

2

How to override an unwanted super method?

By
bg00071
on 10/7/14, 5:17 AM 1,205 views

After an upgrade to Odoo 8, I noticed a new write method in hr_holidays:

    def write(self, cr, uid, ids, vals, context=None):
        if vals.get('state') and vals['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'):
            raise osv.except_osv(_('Warning!'), _('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % vals.get('state'))
        return super(hr_holidays, self).write(cr, uid, ids, vals, context=context)

I want to be able to give users the right to approve leave requests without having to add them to the group 'base.group_hr_user'. In OpenERP 6.1, I created a group called 'Leave Approvers' for this reason.

Is it possible to change this new write method without having to modify the addon itself?

2

Temur

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 10/7/14, 8:34 AM

hi,

Yes, it's possible by inheriting "hr_holidays" and overriding write function as follows:

def write(self, cr, uid, ids, vals, context=None):
    osv.osv.write(self, cr, uid, ids, vals, context=context)

-it will skip write function in "hr_holidays" and will call directly write function of ORM. 

regards,

0
bg00071
On 10/9/14, 9:04 AM

Thanks for your answer, Temur!

I never suspected it would be this obvious...

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

2 follower(s)

Stats

Asked: 10/7/14, 5:17 AM
Seen: 1205 times
Last updated: 5/18/16, 11:38 PM