Skip to Content
Menú
This question has been flagged
1 Respondre
2085 Vistes

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
Descartar
Autor

@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
Descartar
Related Posts Respostes Vistes Activitat
2
d’ag. 25
2646
1
de jul. 25
1032
1
d’ag. 25
1151
0
de maig 25
1490
2
d’abr. 25
3645