Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
11697 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi, Bhavik


You can follow below code in order to achieve this part.

class CustomModel(models.Model):
    _inherit = "custom.model"
    
    @api.multi
    def write(self, vals):
        ## Definition
        return super(models.Model, self).write(vals)

Here only this function and write function of "model.Model" will call.

Feel free to ask in case you have any confusion.


Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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,

อวตาร
ละทิ้ง

THanks for this answer.

คำตอบที่ดีที่สุด

How about same situation with new api ?


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Thanks for your answer, Temur!

I never suspected it would be this obvious...

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Dependency priorities on calling super แก้ไขแล้ว
1
ต.ค. 23
2637
Create function problem แก้ไขแล้ว
2
มิ.ย. 23
2341
Overriding method in a model แก้ไขแล้ว
1
มิ.ย. 20
35387
1
พ.ย. 17
3338
1
มิ.ย. 16
4852