Skip to content

Commit

Permalink
[IMP] dms_version: constrain that attachments storage cannot be versi…
Browse files Browse the repository at this point in the history
…oned
  • Loading branch information
len-foss committed Dec 16, 2023
1 parent 0eb2226 commit 8b6999b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
16 changes: 15 additions & 1 deletion dms_version/models/dms_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class DmsDirectory(models.Model):
Expand All @@ -13,6 +14,19 @@ class DmsDirectory(models.Model):
help="Indicates if files have an active version control.",
)

@api.constrains("has_versioning")
def _check_can_be_versioned(self):
for directory in self:
if (
directory.has_versioning
and directory.storage_id_save_type == "attachment"
):
msg = _(
"Attachment storages cannot be versioned. "
"Please check the directory storage."
)
raise ValidationError(msg)

@api.onchange("storage_id")
def _onchange_storage_id(self):
for record in self:
Expand Down
14 changes: 14 additions & 0 deletions dms_version/models/dms_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, exceptions, fields, models
from odoo.exceptions import ValidationError


class DmsFile(models.Model):
Expand Down Expand Up @@ -71,6 +72,19 @@ class DmsFile(models.Model):
)
]

@api.constrains("has_versioning")
def _check_can_be_versioned(self):
for file in self:
if (
file.has_versioning
and file.directory.storage_id_save_type == "attachment"
):
msg = _(
"Attachment storages cannot be versioned. "
"Please check the directory storage."
)
raise ValidationError(msg)

@api.constrains("unrevisioned_name", "revision_number", "directory_id")
def check_unique_name_revision_number(self):
if self.env.context.get("ignore_revision_unique"):
Expand Down
9 changes: 8 additions & 1 deletion dms_version/models/dms_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class DmsStorage(models.Model):
Expand All @@ -12,3 +13,9 @@ class DmsStorage(models.Model):
default=False,
help="Indicates if files have an active version control.",
)

@api.constrains("has_versioning")
def _check_can_be_versioned(self):
for storage in self:
if storage.has_versioning and storage.save_type == "attachment":
raise ValidationError(_("Attachment storages cannot be versioned."))

0 comments on commit 8b6999b

Please sign in to comment.