Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] dms_field: Avoid access error in dms.access.groups linked to an other company's records #355

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 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,16 @@ def _selection_reference_value(self):
)
return [(model.model, model.name) for model in models]

@api.depends("dms_field_ref")
def _compute_company_id(self):
self.company_id = False
for item in self.filtered("dms_field_ref"):
victoralmau marked this conversation as resolved.
Show resolved Hide resolved
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
Loading