diff --git a/account_dms_field/__init__.py b/account_dms_field/__init__.py
new file mode 100644
index 000000000..0650744f6
--- /dev/null
+++ b/account_dms_field/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/account_dms_field/__manifest__.py b/account_dms_field/__manifest__.py
new file mode 100644
index 000000000..3e7dd89f7
--- /dev/null
+++ b/account_dms_field/__manifest__.py
@@ -0,0 +1,12 @@
+{
+ "name": "Add dms field for account",
+ "version": "16.0.1.0.0",
+ "category": "Accounting/Accounting",
+ "website": "https://www.agenterp.com",
+ "author": "Agent ERP GmbH",
+ "depends": ["account", "dms_field"],
+ "data": ["views/account_move_view.xml"],
+ "demo": ["demo/account_dms_data.xml"],
+ "installable": True,
+ "license": "LGPL-3",
+}
diff --git a/account_dms_field/demo/account_dms_data.xml b/account_dms_field/demo/account_dms_data.xml
new file mode 100644
index 000000000..92c641703
--- /dev/null
+++ b/account_dms_field/demo/account_dms_data.xml
@@ -0,0 +1,25 @@
+
+
+
+
+ Everyone for Account DMS
+
+
+
+
+
+
+
+
+ Account
+
+
+
+
+
+
+
+
+
+
+
diff --git a/account_dms_field/models/__init__.py b/account_dms_field/models/__init__.py
new file mode 100644
index 000000000..0510fa31f
--- /dev/null
+++ b/account_dms_field/models/__init__.py
@@ -0,0 +1,3 @@
+from . import dms_field_template
+from . import account_move
+from . import dms_directory
diff --git a/account_dms_field/models/account_move.py b/account_dms_field/models/account_move.py
new file mode 100644
index 000000000..751e4a51a
--- /dev/null
+++ b/account_dms_field/models/account_move.py
@@ -0,0 +1,6 @@
+from odoo import models
+
+
+class AccountMove(models.Model):
+ _name = "account.move"
+ _inherit = ["account.move", "dms.field.mixin"]
diff --git a/account_dms_field/models/dms_directory.py b/account_dms_field/models/dms_directory.py
new file mode 100644
index 000000000..b58f2f7e2
--- /dev/null
+++ b/account_dms_field/models/dms_directory.py
@@ -0,0 +1,37 @@
+from odoo import _, api, models
+from odoo.exceptions import ValidationError
+
+from odoo.addons.dms.tools.file import check_name
+
+
+class DmsDirectory(models.Model):
+ _inherit = "dms.directory"
+
+ @api.constrains("name")
+ def _check_name(self):
+ """Override a method to update the record name for the account.move model.
+ #Issue-249"""
+ for record in self:
+ # BAD customization start. #Issue-249
+ name = record.name
+ # Updated the name of account move record due to an issue caused by a (/)
+ # in the record name when opening the temporary directory created in the
+ # check_name method. #Issue-249
+ if record.res_model == "account.move":
+ name = name.replace("/", "-")
+ # BAD customization end. #Issue-249
+ if self.env.context.get("check_name", True) and not check_name(name):
+ raise ValidationError(_("The directory name is invalid."))
+ if record.is_root_directory:
+ childs = record.sudo().storage_id.root_directory_ids.name_get()
+ else:
+ childs = record.sudo().parent_id.child_directory_ids.name_get()
+ if list(
+ filter(
+ lambda child: child[1] == record.name and child[0] != record.id,
+ childs,
+ )
+ ):
+ raise ValidationError(
+ _("A directory with the same name already exists.")
+ )
diff --git a/account_dms_field/models/dms_field_template.py b/account_dms_field/models/dms_field_template.py
new file mode 100644
index 000000000..965c4d280
--- /dev/null
+++ b/account_dms_field/models/dms_field_template.py
@@ -0,0 +1,14 @@
+from odoo import models
+
+
+class DmsFieldTemplate(models.Model):
+ _inherit = "dms.field.template"
+
+ def _create_dms_directory(self):
+ """New 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()
diff --git a/account_dms_field/tests/__init__.py b/account_dms_field/tests/__init__.py
new file mode 100644
index 000000000..deac12019
--- /dev/null
+++ b/account_dms_field/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_account_dms_field
diff --git a/account_dms_field/tests/test_account_dms_field.py b/account_dms_field/tests/test_account_dms_field.py
new file mode 100644
index 000000000..a72c66e05
--- /dev/null
+++ b/account_dms_field/tests/test_account_dms_field.py
@@ -0,0 +1,59 @@
+from odoo.addons.base.tests.common import TransactionCase
+
+
+class TestAccountDmsField(TransactionCase):
+ def setUp(self):
+ """Inherited method to create records. #Issue-249"""
+ super(TestAccountDmsField, self).setUp()
+ self.template = self.env.ref("account_dms_field.field_template_account")
+ self.storage = self.template.storage_id
+ self.access_group = self.template.group_ids
+ self.account_model = self.env["account.move"]
+ self.partner = self.env.ref("base.res_partner_12")
+ self.test_directory = self.env["dms.directory"].create(
+ {
+ "name": "Test Directory",
+ "parent_id": self.template.dms_directory_ids[0].id,
+ "storage_id": self.template.storage_id.id,
+ }
+ )
+
+ def test_01_account_document_directory(self):
+ """New method to test account order documents field value. #Issue-249"""
+ template_ctx = self.template.with_context(
+ res_model=self.template._name, res_id=self.template.id
+ )
+ template_ctx._create_dms_directory()
+ account_move = self.account_model.create(
+ {
+ "partner_id": self.partner.id,
+ }
+ )
+ account_move.invalidate_model()
+ directory = account_move.dms_directory_ids
+ # Assert that only one directory is created for the account move. #Issue-249
+ self.assertEqual(len(directory), 1, "Directory length must be 1.")
+ # Assert that the storage associated with the directory is the same as the
+ # template's storage. #Issue-249
+ self.assertEqual(
+ directory.storage_id,
+ self.storage,
+ "Account move directory storage is different from the template storage.",
+ )
+ # Assert that the custom access group is present in the directory's group
+ # list. #Issue-249
+ self.assertIn(
+ self.access_group,
+ directory.group_ids,
+ "Account move directory groups are different from the template groups.",
+ )
+ # Map the names of child directories related to the account move directory.
+ # Issue-249
+ child_directory_names = directory.mapped("child_directory_ids.name")
+ # Assert that a specific child directory, "Test Directory", exists. #Issue-249
+ self.assertIn(
+ "Test Directory",
+ child_directory_names,
+ "Test Directory is not in the child directory of the account move "
+ "directory.",
+ )
diff --git a/account_dms_field/views/account_move_view.xml b/account_dms_field/views/account_move_view.xml
new file mode 100644
index 000000000..8ee4382d8
--- /dev/null
+++ b/account_dms_field/views/account_move_view.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ view.move.form.inherit.account.dms.field
+ account.move
+
+
+
+
+
+
+
+
+
+
+