Skip to content

Commit 22a3f44

Browse files
committed
Merge PR #453 into 17.0
Signed-off-by etobella
2 parents 6e36321 + 06b079c commit 22a3f44

File tree

17 files changed

+907
-0
lines changed

17 files changed

+907
-0
lines changed

dms_file_sequence/README.rst

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
=================
2+
Dms File Sequence
3+
=================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:6265a2c2861d1f2f35eab12c1f176e783b72b504d39d82da67a897e2d4978734
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdms-lightgray.png?logo=github
20+
:target: https://github.com/OCA/dms/tree/17.0/dms_file_sequence
21+
:alt: OCA/dms
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/dms-17-0/dms-17-0-dms_file_sequence
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/dms&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module adds a configurable sequence for dms file records.
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Usage
39+
=====
40+
41+
To use this module, you need to:
42+
43+
- Navigate to Settings > Technical > Parameters > System Parameters.
44+
- Setup a custom sequence on System parameter called
45+
**dms_file_sequence.display_name_pattern**
46+
- Test it when create a new record, by default if name is Test and
47+
sequence code 01 the display name will be **01 - Test**
48+
49+
Bug Tracker
50+
===========
51+
52+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/dms/issues>`_.
53+
In case of trouble, please check there if your issue has already been reported.
54+
If you spotted it first, help us to smash it by providing a detailed and welcomed
55+
`feedback <https://github.com/OCA/dms/issues/new?body=module:%20dms_file_sequence%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
56+
57+
Do not contact contributors directly about support or help with technical issues.
58+
59+
Credits
60+
=======
61+
62+
Authors
63+
-------
64+
65+
* APSL-Nagarro
66+
67+
Contributors
68+
------------
69+
70+
- `APSL-Nagarro <https://apsl.tech>`__
71+
72+
- Miquel Alzanillas <miquel.alzanillas@nagarro.com>
73+
- Antoni Marroig <antoni.marroig@nagarro.com>
74+
75+
Maintainers
76+
-----------
77+
78+
This module is maintained by the OCA.
79+
80+
.. image:: https://odoo-community.org/logo.png
81+
:alt: Odoo Community Association
82+
:target: https://odoo-community.org
83+
84+
OCA, or the Odoo Community Association, is a nonprofit organization whose
85+
mission is to support the collaborative development of Odoo features and
86+
promote its widespread use.
87+
88+
.. |maintainer-miquelalzanillas| image:: https://github.com/miquelalzanillas.png?size=40px
89+
:target: https://github.com/miquelalzanillas
90+
:alt: miquelalzanillas
91+
.. |maintainer-peluko00| image:: https://github.com/peluko00.png?size=40px
92+
:target: https://github.com/peluko00
93+
:alt: peluko00
94+
95+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
96+
97+
|maintainer-miquelalzanillas| |maintainer-peluko00|
98+
99+
This module is part of the `OCA/dms <https://github.com/OCA/dms/tree/17.0/dms_file_sequence>`_ project on GitHub.
100+
101+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

dms_file_sequence/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from . import models
2+
3+
4+
def post_init_hook(env):
5+
env["ir.config_parameter"].sudo().set_param(
6+
"dms_file_sequence.display_name_pattern", "%(sequence_code)s - %(name)s"
7+
)

dms_file_sequence/__manifest__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 APSL-Nagarro - Miquel Alzanillas, Antoni Marroig
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Dms File Sequence",
5+
"version": "17.0.1.0.1",
6+
"category": "Document Management",
7+
"website": "https://github.com/OCA/dms",
8+
"author": "APSL-Nagarro, Odoo Community Association (OCA)",
9+
"license": "AGPL-3",
10+
"depends": ["dms"],
11+
"data": [
12+
"data/ir_sequence.xml",
13+
"views/dms_file_views.xml",
14+
"views/res_config_settings_view.xml",
15+
],
16+
"installable": True,
17+
"maintainers": ["miquelalzanillas", "peluko00"],
18+
"post_init_hook": "post_init_hook",
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record id="dms_file_sequence" model="ir.sequence">
4+
<field name="name">DMS File Sequence</field>
5+
<field name="code">dms.file.sequence</field>
6+
<field name="prefix">%(range_y)s-</field>
7+
<field name="use_date_range">True</field>
8+
<field name="padding">5</field>
9+
<field name="company_id" eval="False" />
10+
</record>
11+
</odoo>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import dms_file
2+
from . import res_config_settings
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2025 APSL-Nagarro - Miquel Alzanillas, Antoni Marroig
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class DmsFile(models.Model):
8+
_inherit = "dms.file"
9+
10+
_sql_constraints = [
11+
# Ensure compatibility with other modules that always expect a value in name
12+
("name_required", "CHECK(name IS NOT NULL)", "File name is required"),
13+
(
14+
"sequence_code_unique",
15+
"UNIQUE(sequence_code)",
16+
"Sequence code must be unique",
17+
),
18+
]
19+
20+
sequence_code = fields.Char(
21+
copy=False,
22+
readonly=True,
23+
)
24+
25+
name = fields.Char(
26+
# We actually require it with the SQL constraint, but it is disabled
27+
# here to let users create/write dms records without name, and let this module
28+
# add a default name if needed
29+
required=False,
30+
)
31+
32+
@api.depends("sequence_code", "name")
33+
def _compute_display_name(self):
34+
res = super()._compute_display_name()
35+
sequence_pattern = (
36+
self.env["ir.config_parameter"]
37+
.sudo()
38+
.get_param(
39+
"dms_file_sequence.display_name_pattern",
40+
default="%(sequence_code)s - %(name)s",
41+
)
42+
)
43+
for dms_file in self.filtered(
44+
lambda file: file.sequence_code and file.sequence_code != file.name
45+
):
46+
dms_file.display_name = sequence_pattern % {
47+
"name": dms_file.name,
48+
"sequence_code": dms_file.sequence_code,
49+
}
50+
return res
51+
52+
@api.model
53+
def name_search(self, name="", args=None, operator="ilike", limit=100):
54+
"""Allow searching by sequence code by default."""
55+
# Do not add any domain when user just clicked on search widget
56+
if not (name == "" and operator == "ilike"):
57+
# The dangling | is needed to combine with the domain added by super()
58+
args = (args or []) + ["|", ("sequence_code", operator, name)]
59+
return super().name_search(name, args, operator, limit)
60+
61+
@api.model_create_multi
62+
def create(self, vals_list):
63+
"""Apply sequence code and a default name if not set."""
64+
for vals in vals_list:
65+
if "sequence_code" not in vals:
66+
vals["sequence_code"] = self.env["ir.sequence"].next_by_code(
67+
"dms.file.sequence"
68+
)
69+
if not vals.get("name"):
70+
vals["name"] = vals["sequence_code"]
71+
res = super().create(vals_list)
72+
return res
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 APSL-Nagarro - Miquel Alzanillas, Antoni Marroig
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
dms_file_display_name_pattern = fields.Char(
11+
config_parameter="dms_file_sequence.display_name_pattern",
12+
default="%(sequence_code)s - %(name)s",
13+
help=(
14+
"Use %(sequence_code)s and %(name)s to include the sequence code "
15+
"and the name of the file in the display name."
16+
),
17+
)

dms_file_sequence/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [APSL-Nagarro](https://apsl.tech)
2+
- Miquel Alzanillas \<<miquel.alzanillas@nagarro.com>\>
3+
- Antoni Marroig \<<antoni.marroig@nagarro.com>\>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module adds a configurable sequence for dms file records.

0 commit comments

Comments
 (0)