diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/pos_hr/models/hr_employee.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/pos_hr/models/hr_employee.py')
| -rw-r--r-- | addons/pos_hr/models/hr_employee.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/addons/pos_hr/models/hr_employee.py b/addons/pos_hr/models/hr_employee.py new file mode 100644 index 00000000..5ad415c2 --- /dev/null +++ b/addons/pos_hr/models/hr_employee.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import hashlib + +from odoo import api, models, _ +from odoo.exceptions import UserError + +class HrEmployee(models.Model): + + _inherit = 'hr.employee' + + def get_barcodes_and_pin_hashed(self): + if not self.env.user.has_group('point_of_sale.group_pos_user'): + return [] + # Apply visibility filters (record rules) + visible_emp_ids = self.search([('id', 'in', self.ids)]) + employees_data = self.sudo().search_read([('id', 'in', visible_emp_ids.ids)], ['barcode', 'pin']) + + for e in employees_data: + e['barcode'] = hashlib.sha1(e['barcode'].encode('utf8')).hexdigest() if e['barcode'] else False + e['pin'] = hashlib.sha1(e['pin'].encode('utf8')).hexdigest() if e['pin'] else False + return employees_data + + def unlink(self): + configs_with_employees = self.env['pos.config'].search([('module_pos_hr', '=', 'True')]).filtered(lambda c: c.current_session_id) + configs_with_all_employees = configs_with_employees.filtered(lambda c: not c.employee_ids) + configs_with_specific_employees = configs_with_employees.filtered(lambda c: c.employee_ids & self) + if configs_with_all_employees or configs_with_specific_employees: + error_msg = _("You cannot delete an employee that may be used in an active PoS session, close the session(s) first: \n") + for employee in self: + config_ids = configs_with_all_employees | configs_with_specific_employees.filtered(lambda c: employee in c.employee_ids) + if config_ids: + error_msg += _("Employee: %s - PoS Config(s): %s \n") % (employee.name, ', '.join(config.name for config in config_ids)) + + raise UserError(error_msg) + return super(HrEmployee, self).unlink() |
