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

hi all , iam trying to override the create method of hr.employee , what iam trying to odoo is when i create a employee it should create a contact record too both at same time . please check my code below tell me what i did wrong there



class ResPartnerInherit(models.Model):

    _inherit = 'hr.employee'


    @api.model

    def create(self, vals):

        res = super(ResPartnerInherit, self).create(vals)

        pdb.set_trace()

        if vals['name']:

            vals= self.env['res.partner'].create({'name':vals['name']})

        return res

        

อวตาร
ละทิ้ง
ผู้เขียน

@api.model

def create(self, vals):

res = super(ResPartnerInherit, self).create(vals)

pdb.set_trace()

#if vals['name']:

#if self.name:

if vals.get('name'):

#vals = self.env['res.partner'].create({'name':vals['name']})

vals = self.env['res.partner'].create({'name': self.name})

return res

i even tried like this seems like the prob is here if vals['name']:

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

Hi,

Try this :class HREmployee(models.Model):

    _inherit = 'hr.employee'


    @api.model

    def create(self, vals):

        # Call super to create the employee

        employee = super(HREmployee, self).create(vals)


        # Create a contact if the employee has a name

        if 'name' in vals:

            self.env['res.partner'].create({'name': vals['name']})


        return employee


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 25
2646
1
ก.ค. 25
1032
1
ส.ค. 25
1151
0
พ.ค. 25
1490
2
เม.ย. 25
3645