Skip to content

Commit

Permalink
[FIX] dms_field: Avoid access error in dms.access.groups linked to an…
Browse files Browse the repository at this point in the history
…other company's records

TT50390
  • Loading branch information
victoralmau committed Aug 5, 2024
1 parent 6fc406f commit 3f62f12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dms_field/models/dms_access_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class DmsAccessGroups(models.Model):
selection="_selection_reference_value",
string="DMS field reference",
)
company_id = fields.Many2one(
compute="_compute_company_id",
comodel_name="res.company",
string="Company",
store=True,
)

@api.model
def _selection_reference_value(self):
Expand All @@ -22,6 +28,15 @@ def _selection_reference_value(self):
)
return [(model.model, model.name) for model in models]

@api.depends("dms_field_ref")
def _compute_company_id(self):
for item in self.filtered("dms_field_ref"):
item.company_id = (
item.dms_field_ref.company_id
if "company_id" in item.dms_field_ref._fields
else False
)

def _get_item_from_dms_field_ref(self, record):
return self.env["dms.access.group"].search(
[("dms_field_ref", "=", "%s,%s" % (record._name, record.id))]
Expand Down
8 changes: 8 additions & 0 deletions dms_field/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
name="domain_force"
>['|',('company_id','=',False),('company_id','in',company_ids)]</field>
</record>
<record id="rule_multi_company_dms_access_group" model="ir.rule">
<field name="name">DMS Access Group multi-company</field>
<field name="model_id" ref="model_dms_access_group" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','in',company_ids)]</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions dms_field/tests/test_dms_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ def test_dms_access_group_constrains_dms_field_ref(self):
with self.assertRaises(UserError):
group.copy({"name": "Test 2"})

def test_dms_access_group_company_dms_field_ref_01(self):
self.partner.company_id = False
group = self.env["dms.access.group"].create(
{
"name": "Test 1",
"dms_field_ref": "%s,%s" % (self.partner._name, self.partner.id),
}
)
self.assertFalse(group.company_id)

def test_dms_access_group_company_dms_field_ref_02(self):
self.company = self.env.company
self.partner.company_id = self.company
group = self.env["dms.access.group"].create(
{
"name": "Test 1",
"dms_field_ref": "%s,%s" % (self.partner._name, self.partner.id),
}
)
self.assertEqual(group.company_id, self.company)

def test_template_directory(self):
self.assertTrue(self.template.dms_directory_ids)
self.assertIn(
Expand Down

0 comments on commit 3f62f12

Please sign in to comment.