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. This module overrides the standard Odoo restriction of one company per employee.
It allows an employee to be associated with multiple branch companies. It allows an employee to be associated with multiple branch companies.
""", """,
'author': 'Antigravity', 'author': 'Suherdy Yacob',
'depends': ['hr', 'pos_hr', 'hr_attendance'], 'depends': ['hr', 'pos_hr', 'hr_attendance'],
'data': [ 'data': [
'security/hr_security.xml', 'security/hr_security.xml',

View File

@ -72,9 +72,12 @@ class HrEmployee(models.Model):
super()._register_hook() super()._register_hook()
rule = self.env.ref('base.res_partner_rule', raise_if_not_found=False) rule = self.env.ref('base.res_partner_rule', raise_if_not_found=False)
if rule: if rule:
new_domain = "['|', '|', '|', ('partner_share', '=', False), ('company_id', 'parent_of', company_ids), ('company_id', '=', False), ('employee_ids.company_ids', 'in', company_ids)]" # Revert res_partner_rule to standard Odoo 19 domain.
if rule.domain_force != new_domain: # The custom override traversed `employee_ids` (hr.employee relation), which throws AccessError
rule.sudo().write({'domain_force': new_domain}) # 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) rule_public = self.env.ref('hr.hr_employee_public_comp_rule', raise_if_not_found=False)
if rule_public: if rule_public:

View File

@ -14,9 +14,5 @@
<field name="global" eval="True"/> <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> <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>
<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> </data>
</odoo> </odoo>