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
28 changes: 15 additions & 13 deletions dms_field/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========
DMS Field
=========
Expand All @@ -17,7 +13,7 @@ DMS Field
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdms-lightgray.png?logo=github
Expand Down Expand Up @@ -81,9 +77,9 @@ Usage
Known issues / Roadmap
======================

- Add drag & drop compatibility to the dms_tree mode
- Multiple selection support (e.g. cut several files and paste to
another folder).
- Add drag & drop compatibility to the dms_tree mode
- Multiple selection support (e.g. cut several files and paste to
another folder).

Bug Tracker
===========
Expand All @@ -106,12 +102,18 @@ Authors
Contributors
------------

- Enric Tobella <[email protected]>
- Jaime Arroyo <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:
- Enric Tobella <[email protected]>

- Jaime Arroyo <[email protected]>

- `Tecnativa <https://www.tecnativa.com>`__:

- Víctor Martínez
- Carlos Roca

- `PyTech <https://www.pytech.it>`__:

- Víctor Martínez
- Carlos Roca
- Simone Rubino [email protected]

Maintainers
-----------
Expand Down
20 changes: 15 additions & 5 deletions dms_field/models/dms_access_group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# Copyright 2025 Simone Rubino - PyTech
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.osv import expression


class DmsAccessGroups(models.Model):
Expand Down Expand Up @@ -38,18 +40,26 @@ def _compute_company_id(self):
else False
)

def _get_domain_for_item_from_dms_field_ref(self, record):
return [
("dms_field_ref", "=", f"{record._name},{record.id}"),
]

def _get_item_from_dms_field_ref(self, record):
return self.env["dms.access.group"].search(
[("dms_field_ref", "=", f"{record._name},{record.id}")]
self._get_domain_for_item_from_dms_field_ref(record)
)

@api.constrains("dms_field_ref")
def _check_dms_field_ref(self):
for item in self.filtered("dms_field_ref"):
dms_field_ref = f"{item.dms_field_ref._name},{item.dms_field_ref.id}"
if self.search(
[("dms_field_ref", "=", dms_field_ref), ("id", "!=", item.id)]
):
domain = expression.AND(
[
item._get_domain_for_item_from_dms_field_ref(item.dms_field_ref),
[("id", "!=", item.id)],
]
)
if self.search(domain):
raise UserError(
_("There is already an access group created for this record.")
)
24 changes: 19 additions & 5 deletions dms_field/models/dms_field_template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# Copyright 2025 Simone Rubino - PyTech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
Expand Down Expand Up @@ -152,16 +153,29 @@ def _get_autogenerated_group(self, record):
# Create the autogenerated group linked to the record
return group_model.create(self._prepare_autogenerated_group(record))

def _prepare_child_directory_vals(self, parent, template_child_directory):
"""Values to create child directories on the record.

:param parent: Directory already created from the template for the record
:param template_child_directory: Directory in the template directories structure
"""
return {
"name": template_child_directory.name,
"is_root_directory": False,
"parent_id": parent.id,
"inherit_group_ids": template_child_directory.inherit_group_ids,
"group_ids": [
fields.Command.link(group.id)
for group in template_child_directory.group_ids
],
}

def _create_child_directories(self, parent, directory):
# Create child directories (all leves) + files
directory_model = self.env["dms.directory"].sudo()
for child_directory in directory.child_directory_ids:
child = directory_model.create(
{
"name": child_directory.name,
"is_root_directory": False,
"parent_id": parent.id,
}
self._prepare_child_directory_vals(parent, child_directory)
)
self._copy_files_from_directory(child_directory, child)
self._create_child_directories(child, child_directory)
Expand Down
3 changes: 3 additions & 0 deletions dms_field/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
- [Tecnativa](https://www.tecnativa.com):
- Víctor Martínez
- Carlos Roca

- [PyTech](https://www.pytech.it):
- Simone Rubino <[email protected]>
34 changes: 16 additions & 18 deletions dms_field/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>DMS Field</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="dms-field">
<h1 class="title">DMS Field</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="dms-field">
<h1>DMS Field</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c17ee23c249e8e476d58be65c77504fdf832032429a14fc0edc91aa4485d78b4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/dms/tree/18.0/dms_field"><img alt="OCA/dms" src="https://img.shields.io/badge/github-OCA%2Fdms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/dms-18-0/dms-18-0-dms_field"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/dms&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/dms/tree/18.0/dms_field"><img alt="OCA/dms" src="https://img.shields.io/badge/github-OCA%2Fdms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/dms-18-0/dms-18-0-dms_field"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/dms&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon creates a new kind of view and allows to define a folder
related to a record.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -393,7 +388,7 @@ <h1>DMS Field</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To use the embedded view in any module, the module must inherit from the
mixin dms.field.mixin (You have an example with res.partner in this
module).</p>
Expand All @@ -419,7 +414,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
</ol>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<ol class="arabic simple">
<li>Go to the form view of an existing partner and click on the “DMS” tab
icon, a hierarchy of folders and files linked to that record will be
Expand All @@ -429,31 +424,31 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Add drag &amp; drop compatibility to the dms_tree mode</li>
<li>Multiple selection support (e.g. cut several files and paste to
another folder).</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/dms/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/dms/issues/new?body=module:%20dms_field%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-6">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>Creu Blanca</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li>Enric Tobella &lt;<a class="reference external" href="mailto:etobella&#64;creublanca.es">etobella&#64;creublanca.es</a>&gt;</li>
<li>Jaime Arroyo &lt;<a class="reference external" href="mailto:jaime.arroyo&#64;creublanca.es">jaime.arroyo&#64;creublanca.es</a>&gt;</li>
Expand All @@ -462,10 +457,14 @@ <h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
<li>Carlos Roca</li>
</ul>
</li>
<li><a class="reference external" href="https://www.pytech.it">PyTech</a>:<ul>
<li>Simone Rubino <a class="reference external" href="mailto:simone.rubino&#64;pytech.it">simone.rubino&#64;pytech.it</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -480,6 +479,5 @@ <h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
34 changes: 34 additions & 0 deletions dms_field/tests/test_dms_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,37 @@ def test_parents(self):
{"id": directory.id, "name": directory.name},
directory.search_read_parents(fields=["id", "name"]),
)

def test_child_values(self):
"""Values of the child directory in the template
are propagated to the new directories."""
# Arrange
partner = self.partner
access_group = self.env["dms.access.group"].create(
{
"name": "Test Access group",
}
)
child_dir = self.subdirectory_1
child_dir.inherit_group_ids = False
child_dir.group_ids = access_group

# Act
self.env["dms.field.template"].with_context(
res_model=partner._name,
res_id=partner.id,
).create_dms_directory()

# Assert
partner.invalidate_model()
new_subdirectory_1 = partner.dms_directory_ids.child_directory_ids.filtered(
lambda d, dir_name=child_dir.name: d.name == dir_name
)
self.assertFalse(new_subdirectory_1.inherit_group_ids)
self.assertEqual(new_subdirectory_1.group_ids, access_group)

new_subdirectory_2 = partner.dms_directory_ids.child_directory_ids.filtered(
lambda d, dir_name=self.subdirectory_2.name: d.name == dir_name
)
self.assertTrue(new_subdirectory_2.inherit_group_ids)
self.assertIn(self.group, new_subdirectory_2.complete_group_ids.group_ids)