From 89c98487c814bff1b4b5d97c4af09e01752bc860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 1 Oct 2024 09:20:16 +0200 Subject: [PATCH] [IMP] dms_field + hr_dms_field: Create dms directory automatically in the creation in install mode --- dms_field/models/dms_field_template.py | 10 ++++++++++ hr_dms_field/demo/dms_data.xml | 3 --- hr_dms_field/models/__init__.py | 1 - hr_dms_field/models/dms_field_template.py | 17 ----------------- 4 files changed, 10 insertions(+), 21 deletions(-) delete mode 100644 hr_dms_field/models/dms_field_template.py diff --git a/dms_field/models/dms_field_template.py b/dms_field/models/dms_field_template.py index d32294db8..ba95beac2 100644 --- a/dms_field/models/dms_field_template.py +++ b/dms_field/models/dms_field_template.py @@ -59,6 +59,16 @@ def _compute_model(self): def _get_template_from_model(self, model): return self.search([("model", "=", model)], limit=1) + @api.model_create_multi + def create(self, vals_list): + """Create dms directory automatically in the creation in install mode.""" + result = super().create(vals_list) + if self.env.context.get("install_mode"): + for item in result: + item_ctx = item.with_context(res_model=item._name, res_id=item.id) + item_ctx.create_dms_directory() + return result + @api.model def create_dms_directory(self): """According to the model, create the directory linked to that record diff --git a/hr_dms_field/demo/dms_data.xml b/hr_dms_field/demo/dms_data.xml index dafdbc9a7..20efbaad7 100644 --- a/hr_dms_field/demo/dms_data.xml +++ b/hr_dms_field/demo/dms_data.xml @@ -14,7 +14,4 @@ - - - diff --git a/hr_dms_field/models/__init__.py b/hr_dms_field/models/__init__.py index 9cf62bd2e..39b647b36 100644 --- a/hr_dms_field/models/__init__.py +++ b/hr_dms_field/models/__init__.py @@ -1,5 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from . import dms_field_template from . import hr_employee from . import hr_employee_public diff --git a/hr_dms_field/models/dms_field_template.py b/hr_dms_field/models/dms_field_template.py deleted file mode 100644 index 22e325047..000000000 --- a/hr_dms_field/models/dms_field_template.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2024 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import models - - -class DmsFieldTemplate(models.Model): - _inherit = "dms.field.template" - - def _create_dms_directory(self): - """Custom method to define the directory automatically in demo data avoiding - error if it already exists.""" - self.ensure_one() - if not self.dms_directory_ids: - self.with_context( - res_model=self._name, res_id=self.id - ).create_dms_directory()