'Get employee data from imported Excel file based on the work phone of employee odoo 13

I have a custom module and I have created a model and its view. I have an excel sheet that contains employees' work phones. I want when I import this excel sheet to get data of employees by matching the work phone in the sheet and the work phone in the hr.employee model. when I create a record manually by entering a work phone I get the data after I click on the save button, but when I import it I get nothing. I have created on change method for that here is my code:

 class BillBill(models.Model):
_name = "bill.bill"
_inherit = ['mail.thread', 'mail.activity.mixin']


employee_id = fields.Many2one('hr.employee', string='Employee', help="Employee")

work_phone = fields.Char(string='work_phone')

@api.onchange('work_phone')
def _onchange_work_phone(self):
    employee_rec = self.env['hr.employee']
    if self.work_phone:
        employee = employee_rec.search([('work_phone', '=', self.work_phone)])
        if not employee:
            raise UserError(_("No Employee by this Phone."))
        else:
            self.employee_id = employee.id


Solution 1:[1]

You should add your code in the create and write method because the onchange methods are  executed only on the interfaces like JS code.

@api.model
def create(self, vals):
    values = self.check_existing_employee(vals)
    return super(ClassName, self).create(values)

@api.multi
def write(self, vals):
    values = self.check_existing_employee(vals)
    return super(ClassName, self).write(values)

def check_existing_employee(self, vals):
    if vals.get('work_phone'):
        employee = self.env['hr.employee'].search([
            ('work_phone', '=', vals['work_phone'])
        ])
        if not employee:
            raise UserError(_("No Employee by this Phone."))
        vals['employee_id'] = employee.id
    return vals

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1