Skip to Content
Menu
This question has been flagged
1 Reply
1905 Views

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

        

Avatar
Discard
Author

@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']:

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 25
37
0
May 25
379
2
Apr 25
2542
1
Feb 25
856
2
Feb 25
1375