pos_session.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models
  4. class PosSession(models.Model):
  5. _inherit = 'pos.session'
  6. def _pos_data_process(self, loaded_data):
  7. super()._pos_data_process(loaded_data)
  8. if self.config_id.module_pos_hr:
  9. loaded_data['employee_by_id'] = {employee['id']: employee for employee in loaded_data['hr.employee']}
  10. def _pos_ui_models_to_load(self):
  11. result = super()._pos_ui_models_to_load()
  12. if self.config_id.module_pos_hr:
  13. new_model = 'hr.employee'
  14. if new_model not in result:
  15. result.append(new_model)
  16. return result
  17. def _loader_params_hr_employee(self):
  18. if len(self.config_id.employee_ids) > 0:
  19. domain = ['&', ('company_id', '=', self.config_id.company_id.id), '|', ('user_id', '=', self.user_id.id), ('id', 'in', self.config_id.employee_ids.ids)]
  20. else:
  21. domain = [('company_id', '=', self.config_id.company_id.id)]
  22. return {'search_params': {'domain': domain, 'fields': ['name', 'id', 'user_id'], 'load': False}}
  23. def _get_pos_ui_hr_employee(self, params):
  24. employees = self.env['hr.employee'].search_read(**params['search_params'])
  25. employee_ids = [employee['id'] for employee in employees]
  26. user_ids = [employee['user_id'] for employee in employees if employee['user_id']]
  27. manager_ids = self.env['res.users'].browse(user_ids).filtered(lambda user: self.config_id.group_pos_manager_id in user.groups_id).mapped('id')
  28. employees_barcode_pin = self.env['hr.employee'].browse(employee_ids).get_barcodes_and_pin_hashed()
  29. bp_per_employee_id = {bp_e['id']: bp_e for bp_e in employees_barcode_pin}
  30. for employee in employees:
  31. employee['role'] = 'manager' if employee['user_id'] and employee['user_id'] in manager_ids else 'cashier'
  32. employee['barcode'] = bp_per_employee_id[employee['id']]['barcode']
  33. employee['pin'] = bp_per_employee_id[employee['id']]['pin']
  34. return employees