summaryrefslogtreecommitdiff
path: root/addons/pos_hr
diff options
context:
space:
mode:
authorPierre Masereel <pim@odoo.com>2019-08-19 07:22:23 +0000
committerPierre Masereel <pim@odoo.com>2019-08-19 08:04:31 +0000
commita248171d96de3ad6d8e22c855886dfae61e145e2 (patch)
treeed416e643bba74244cee0a8df9b32d9cb300973b /addons/pos_hr
parent1699be05dab39a8ef4641df113178e688ce13a29 (diff)
[IMP] point_of_sale: improve consistencies between models
The deletion of some records can create inconsistencies in the point_of_sale. It can create inconsistencies when a session is open, for example if you delete a partner that can be set on a pos order. You'll also got problems if you remove an employee and this employee can be used in an open session. We also avoid to get point_of_sale config inconsistencies, by deleting models required by it. If you delete a picking type used in a pos config or a sequence. To avoid all this consistencies, we have restricted the deletion of some records in specific cases. TASK-ID: 1879971 closes odoo/odoo#35793 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_hr')
-rw-r--r--addons/pos_hr/models/hr_employee.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/addons/pos_hr/models/hr_employee.py b/addons/pos_hr/models/hr_employee.py
index fc5a3f9b154..5ad415c2f11 100644
--- a/addons/pos_hr/models/hr_employee.py
+++ b/addons/pos_hr/models/hr_employee.py
@@ -3,7 +3,8 @@
import hashlib
-from odoo import api, models
+from odoo import api, models, _
+from odoo.exceptions import UserError
class HrEmployee(models.Model):
@@ -20,3 +21,17 @@ class HrEmployee(models.Model):
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()