commit 6a13fef24dc379da010989cf8d48422345e4074c Author: Suherdy Yacob Date: Wed May 13 16:54:22 2026 +0700 first commit diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..914f362 --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'Multi-Branch Employee Access', + 'version': '1.0', + 'category': 'Human Resources', + 'summary': 'Allows employees to be associated with multiple branch companies', + 'description': """ + This module overrides the standard Odoo restriction of one company per employee. + It allows an employee to be associated with multiple branch companies. + """, + 'author': 'Antigravity', + 'depends': ['hr', 'pos_hr', 'hr_attendance'], + 'data': [ + 'security/hr_security.xml', + 'security/hr_attendance_security.xml', + 'views/hr_employee_views.xml', + ], + 'installable': True, + 'application': False, + 'license': 'LGPL-3', +} diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..5242a15 --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_employee +from . import pos_config diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..0863982 Binary files /dev/null and b/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/hr_employee.cpython-312.pyc b/models/__pycache__/hr_employee.cpython-312.pyc new file mode 100644 index 0000000..a7ab789 Binary files /dev/null and b/models/__pycache__/hr_employee.cpython-312.pyc differ diff --git a/models/__pycache__/pos_config.cpython-312.pyc b/models/__pycache__/pos_config.cpython-312.pyc new file mode 100644 index 0000000..a97d88a Binary files /dev/null and b/models/__pycache__/pos_config.cpython-312.pyc differ diff --git a/models/hr_employee.py b/models/hr_employee.py new file mode 100644 index 0000000..8feae6a --- /dev/null +++ b/models/hr_employee.py @@ -0,0 +1,37 @@ +from odoo import models, fields, api, _ + +class HrEmployee(models.Model): + _inherit = 'hr.employee' + + company_ids = fields.Many2many( + 'res.company', + string='Branches', + domain="[('parent_id', '!=', False)]", + help="Branch companies this employee is associated with." + ) + + # Overriding company_id to be computed from company_ids + # This maintains compatibility with standard Odoo logic that expects a single company_id + company_id = fields.Many2one( + 'res.company', + string='Company', + compute='_compute_company_id', + store=True, + readonly=False, + required=True, + help="The primary company of the employee. Automatically set to the first branch in Branches." + ) + + attendance_manager_id = fields.Many2one( + 'res.users', + domain="[('share', '=', False), ('company_ids', 'in', company_ids)]" + ) + + @api.depends('company_ids') + def _compute_company_id(self): + for employee in self: + if employee.company_ids: + employee.company_id = employee.company_ids[0] + elif not employee.company_id: + # Fallback to current company if none specified + employee.company_id = self.env.company diff --git a/models/pos_config.py b/models/pos_config.py new file mode 100644 index 0000000..44c6f5f --- /dev/null +++ b/models/pos_config.py @@ -0,0 +1,19 @@ +from odoo import models, api +from odoo.fields import Domain + +class PosConfig(models.Model): + _inherit = 'pos.config' + + def _employee_domain(self, user_id): + # Override to check company_ids instead of company_id + # Standard pos_hr uses self._check_company_domain(self.company_id) + # which returns [('company_id', 'in', [self.company_id.id, False])] + + domain = [('company_ids', 'in', self.company_id.id)] + + if len(self.basic_employee_ids) > 0: + domain = Domain.AND([ + domain, + ['|', ('user_id', '=', user_id), ('id', 'in', self.basic_employee_ids.ids + self.advanced_employee_ids.ids + self.minimal_employee_ids.ids)] + ]) + return domain diff --git a/security/hr_attendance_security.xml b/security/hr_attendance_security.xml new file mode 100644 index 0000000..aba36f8 --- /dev/null +++ b/security/hr_attendance_security.xml @@ -0,0 +1,18 @@ + + + + + Attendance multi branch rule + + + ['|', ('employee_id.company_ids', '=', False), ('employee_id.company_ids', 'in', company_ids)] + + + + Overtime Line multi branch rule + + + ['|', ('employee_id.company_ids', '=', False), ('employee_id.company_ids', 'in', company_ids)] + + + diff --git a/security/hr_security.xml b/security/hr_security.xml new file mode 100644 index 0000000..c20b24b --- /dev/null +++ b/security/hr_security.xml @@ -0,0 +1,11 @@ + + + + + Employee multi branch rule + + + ['|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)] + + + diff --git a/views/hr_employee_views.xml b/views/hr_employee_views.xml new file mode 100644 index 0000000..e543a9e --- /dev/null +++ b/views/hr_employee_views.xml @@ -0,0 +1,17 @@ + + + + hr.employee.form.inherit.multi.company + hr.employee + + + + + + + + 1 + + + +