refactor: revert res_partner_rule to standard domain to prevent AccessError and update module author

This commit is contained in:
Suherdy Yacob 2026-05-28 15:00:07 +07:00
parent 2c1870f076
commit e5998791e9
4 changed files with 7 additions and 8 deletions

View File

@ -7,7 +7,7 @@
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',
'author': 'Suherdy Yacob',
'depends': ['hr', 'pos_hr', 'hr_attendance'],
'data': [
'security/hr_security.xml',

View File

@ -72,9 +72,12 @@ class HrEmployee(models.Model):
super()._register_hook()
rule = self.env.ref('base.res_partner_rule', raise_if_not_found=False)
if rule:
new_domain = "['|', '|', '|', ('partner_share', '=', False), ('company_id', 'parent_of', company_ids), ('company_id', '=', False), ('employee_ids.company_ids', 'in', company_ids)]"
if rule.domain_force != new_domain:
rule.sudo().write({'domain_force': new_domain})
# Revert res_partner_rule to standard Odoo 19 domain.
# The custom override traversed `employee_ids` (hr.employee relation), which throws AccessError
# for portal/public/new/guest users who do not have access to the hr.employee model.
original_domain = "['|', '|', ('partner_share', '=', False), ('company_id', 'parent_of', company_ids), ('company_id', '=', False)]"
if rule.domain_force != original_domain:
rule.sudo().write({'domain_force': original_domain})
rule_public = self.env.ref('hr.hr_employee_public_comp_rule', raise_if_not_found=False)
if rule_public:

View File

@ -14,9 +14,5 @@
<field name="global" eval="True"/>
<field name="domain_force">['|', '|', '|', '|', ('company_ids', 'in', company_ids), ('company_id', 'in', company_ids + [False]), ('parent_id.user_id', '=', user.id), ('id', '=', user.employee_id.parent_id.id), ('user_id', '=', user.id)]</field>
</record>
<record id="base.res_partner_rule" model="ir.rule">
<field name="domain_force">['|', '|', '|', ('partner_share', '=', False), ('company_id', 'parent_of', company_ids), ('company_id', '=', False), ('employee_ids.company_ids', 'in', company_ids)]</field>
</record>
</data>
</odoo>