Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2097 Widoki

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

        

Awatar
Odrzuć
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']:

Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sie 25
2655
1
lip 25
1036
1
sie 25
1151
0
maj 25
1492
2
kwi 25
3647