Skip to content
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
1 change: 1 addition & 0 deletions dms_auto_classification/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_dms_classification_template_user,dms_classification_template_user,model_dms_classification_template,dms.group_dms_user,1,0,0,0
access_dms_classification_template_manager,dms_classification_template_manager,model_dms_classification_template,dms.group_dms_manager,1,1,1,1
access_wizard_dms_classification_manager,wizard_dms_classification_manager,model_wizard_dms_classification,dms.group_dms_user,1,1,1,1
access_wizard_dms_classification_detail_user,wizard_dms_classification_detail_user,model_dms_classification_template,dms.group_dms_user,1,1,1,0
access_wizard_dms_classification_detail_manager,wizard_dms_classification_detail_manager,model_wizard_dms_classification_detail,dms.group_dms_user,1,1,1,1
12 changes: 10 additions & 2 deletions dms_auto_classification/wizards/wizard_dms_classification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# Copyright 2024-2026 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import base64
import re
Expand All @@ -13,6 +13,12 @@ class WizardDmsClassification(models.TransientModel):
_name = "wizard.dms.classification"
_description = "Wizard Dms Classification"

company_id = fields.Many2one(
comodel_name="res.company",
required=True,
default=lambda self: self.env.company,
string="Company",
)
state = fields.Selection(
selection=[
("draft", "Draft"),
Expand All @@ -24,6 +30,7 @@ class WizardDmsClassification(models.TransientModel):
comodel_name="dms.classification.template",
string="Template",
required=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
)
data_file = fields.Binary(
string="File",
Expand Down Expand Up @@ -175,7 +182,8 @@ def _compute_file_name(self):

@api.depends("file_name")
def _compute_directory_id(self):
directories = self.env["dms.directory"].sudo().search([])
domain = [("company_id", "=", self.parent_id.company_id.id)]
directories = self.env["dms.directory"].search(domain)
for item in self:
item.directory_id = self.parent_id._get_directory_from_pattern(
self.parent_id.template_id.directory_pattern, directories
Expand Down
16 changes: 11 additions & 5 deletions dms_field_auto_classification/wizards/wizard_dms_classification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# Copyright 2024-2026 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import re

Expand Down Expand Up @@ -33,6 +33,11 @@ def _compute_record_ref(self):
directory = False
if record.directory_id.res_model and record.directory_id.res_id:
directory = record.directory_id
elif (
record.directory_id.parent_id.res_model
and record.directory_id.parent_id.res_id
):
directory = record.directory_id.parent_id
elif (
record.directory_id.root_directory_id.res_model
and record.directory_id.root_directory_id.res_id
Expand All @@ -46,9 +51,12 @@ def _compute_record_ref(self):
def _compute_directory_id(self):
"""Overwrite to redefine the directory if the template has a linked model."""
self_with_model = self.filtered(lambda x: x.template_id.model_id)
directory_model = self.env["dms.directory"].sudo()
_self = self - self_with_model
res = super(WizardDmsClassificationDetail, _self)._compute_directory_id()
directory_model = self.env["dms.directory"]
for item in self_with_model:
domain = [
("company_id", "=", self.parent_id.company_id.id),
("res_model", "=", item.template_id.model_id.model),
("res_id", ">", 0),
]
Expand All @@ -72,6 +80,4 @@ def _compute_directory_id(self):
item.directory_id = self.parent_id._get_directory_from_pattern(
directory_pattern, directories
)
return super(
WizardDmsClassificationDetail, (self - self_with_model)
)._compute_directory_id()
return res