first commit
This commit is contained in:
commit
6a13fef24d
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
20
__manifest__.py
Normal file
20
__manifest__.py
Normal file
@ -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',
|
||||||
|
}
|
||||||
2
models/__init__.py
Normal file
2
models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from . import hr_employee
|
||||||
|
from . import pos_config
|
||||||
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/hr_employee.cpython-312.pyc
Normal file
BIN
models/__pycache__/hr_employee.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/pos_config.cpython-312.pyc
Normal file
BIN
models/__pycache__/pos_config.cpython-312.pyc
Normal file
Binary file not shown.
37
models/hr_employee.py
Normal file
37
models/hr_employee.py
Normal file
@ -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
|
||||||
19
models/pos_config.py
Normal file
19
models/pos_config.py
Normal file
@ -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
|
||||||
18
security/hr_attendance_security.xml
Normal file
18
security/hr_attendance_security.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data noupdate="0">
|
||||||
|
<record id="hr_attendance.hr_attendance_rule_employee_company" model="ir.rule">
|
||||||
|
<field name="name">Attendance multi branch rule</field>
|
||||||
|
<field name="model_id" ref="hr_attendance.model_hr_attendance"/>
|
||||||
|
<field name="global" eval="True"/>
|
||||||
|
<field name="domain_force">['|', ('employee_id.company_ids', '=', False), ('employee_id.company_ids', 'in', company_ids)]</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="hr_attendance.hr_attendance_overtime_line_rule_employee_company" model="ir.rule">
|
||||||
|
<field name="name">Overtime Line multi branch rule</field>
|
||||||
|
<field name="model_id" ref="hr_attendance.model_hr_attendance_overtime_line"/>
|
||||||
|
<field name="global" eval="True"/>
|
||||||
|
<field name="domain_force">['|', ('employee_id.company_ids', '=', False), ('employee_id.company_ids', 'in', company_ids)]</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
11
security/hr_security.xml
Normal file
11
security/hr_security.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data noupdate="0">
|
||||||
|
<record id="hr.hr_employee_comp_rule" model="ir.rule">
|
||||||
|
<field name="name">Employee multi branch rule</field>
|
||||||
|
<field name="model_id" ref="hr.model_hr_employee"/>
|
||||||
|
<field name="global" eval="True"/>
|
||||||
|
<field name="domain_force">['|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)]</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
17
views/hr_employee_views.xml
Normal file
17
views/hr_employee_views.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_employee_form_inherit_multi_company" model="ir.ui.view">
|
||||||
|
<field name="name">hr.employee.form.inherit.multi.company</field>
|
||||||
|
<field name="model">hr.employee</field>
|
||||||
|
<field name="inherit_id" ref="hr.view_employee_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<!-- Replace company_id with company_ids -->
|
||||||
|
<xpath expr="//field[@name='company_id']" position="after">
|
||||||
|
<field name="company_ids" widget="many2many_tags" options="{'no_create': True}"/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='company_id']" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in New Issue
Block a user