diff --git a/yuthon_hr_employee/__manifest__.py b/yuthon_hr_employee/__manifest__.py index 400697772..e5713961a 100644 --- a/yuthon_hr_employee/__manifest__.py +++ b/yuthon_hr_employee/__manifest__.py @@ -11,7 +11,7 @@ 'license': 'LGPL-3', 'author': 'pengyuthon', 'website': 'https://www.pengyuthon.com', - 'depends': ['hr'], + 'depends': ['base', 'hr'], 'data': [ 'data/hr_department_data.xml', 'data/user_role_data.xml', @@ -21,6 +21,7 @@ 'views/yuthon_hr_department_views.xml', 'views/yuthon_job_lv_views.xml', 'views/yuthon_user_role_views.xml', + 'views/inherit_res_user_views.xml', ], 'installable': True, 'application': False, diff --git a/yuthon_hr_employee/models/__init__.py b/yuthon_hr_employee/models/__init__.py index 508c8ec7c..1af45361c 100644 --- a/yuthon_hr_employee/models/__init__.py +++ b/yuthon_hr_employee/models/__init__.py @@ -1,4 +1,5 @@ from . import yuthon_hr_employee from . import yuthon_job_lv from . import yuthon_user_role -from . import yuthon_hr_department \ No newline at end of file +from . import yuthon_hr_department +from . import inherit_res_user diff --git a/yuthon_hr_employee/models/inherit_res_user.py b/yuthon_hr_employee/models/inherit_res_user.py new file mode 100644 index 000000000..4c4f2dedb --- /dev/null +++ b/yuthon_hr_employee/models/inherit_res_user.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class ResUsers(models.Model): + _inherit = "res.users" + + def all_create_users(self): + employee_ids = self.browse(self._context.get('active_ids', self._context.get('active_id'))) + for employee in employee_ids: + employee_id = self.env['hr.employee'].search([('name', '=', employee.name)]) + if not employee_id: + employee_data = { + 'name': employee.name, + 'company_id': employee.env.company.id, + } + self.env['hr.employee'].create(employee_data) + else: + raise UserError('该用户:%s已经创建员工,请不要重复操作' % employee_id.name) + + diff --git a/yuthon_hr_employee/views/inherit_res_user_views.xml b/yuthon_hr_employee/views/inherit_res_user_views.xml new file mode 100644 index 000000000..7e5f894f5 --- /dev/null +++ b/yuthon_hr_employee/views/inherit_res_user_views.xml @@ -0,0 +1,10 @@ + + + + 批量创建员工 + + + code + records.all_create_users() + + \ No newline at end of file