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
101 changes: 101 additions & 0 deletions dms_file_sequence/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
=================
Dms File Sequence
=================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6265a2c2861d1f2f35eab12c1f176e783b72b504d39d82da67a897e2d4978734
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdms-lightgray.png?logo=github
:target: https://github.com/OCA/dms/tree/17.0/dms_file_sequence
:alt: OCA/dms
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/dms-17-0/dms-17-0-dms_file_sequence
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/dms&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds a configurable sequence for dms file records.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

- Navigate to Settings > Technical > Parameters > System Parameters.
- Setup a custom sequence on System parameter called
**dms_file_sequence.display_name_pattern**
- Test it when create a new record, by default if name is Test and
sequence code 01 the display name will be **01 - Test**

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/dms/issues>`_.
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
`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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* APSL-Nagarro

Contributors
------------

- `APSL-Nagarro <https://apsl.tech>`__

- Miquel Alzanillas <miquel.alzanillas@nagarro.com>
- Antoni Marroig <antoni.marroig@nagarro.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-miquelalzanillas| image:: https://github.com/miquelalzanillas.png?size=40px
:target: https://github.com/miquelalzanillas
:alt: miquelalzanillas
.. |maintainer-peluko00| image:: https://github.com/peluko00.png?size=40px
:target: https://github.com/peluko00
:alt: peluko00

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-miquelalzanillas| |maintainer-peluko00|

This module is part of the `OCA/dms <https://github.com/OCA/dms/tree/17.0/dms_file_sequence>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
7 changes: 7 additions & 0 deletions dms_file_sequence/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import models


def post_init_hook(env):
env["ir.config_parameter"].sudo().set_param(
"dms_file_sequence.display_name_pattern", "%(sequence_code)s - %(name)s"
)
19 changes: 19 additions & 0 deletions dms_file_sequence/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2025 APSL-Nagarro - Miquel Alzanillas, Antoni Marroig
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Dms File Sequence",
"version": "17.0.1.0.1",
"category": "Document Management",
"website": "https://github.com/OCA/dms",
"author": "APSL-Nagarro, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["dms"],
"data": [
"data/ir_sequence.xml",
"views/dms_file_views.xml",
"views/res_config_settings_view.xml",
],
"installable": True,
"maintainers": ["miquelalzanillas", "peluko00"],
"post_init_hook": "post_init_hook",
}
11 changes: 11 additions & 0 deletions dms_file_sequence/data/ir_sequence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="dms_file_sequence" model="ir.sequence">
<field name="name">DMS File Sequence</field>
<field name="code">dms.file.sequence</field>
<field name="prefix">%(range_y)s-</field>
<field name="use_date_range">True</field>
<field name="padding">5</field>
<field name="company_id" eval="False" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions dms_file_sequence/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import dms_file
from . import res_config_settings
72 changes: 72 additions & 0 deletions dms_file_sequence/models/dms_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2025 APSL-Nagarro - Miquel Alzanillas, Antoni Marroig
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class DmsFile(models.Model):
_inherit = "dms.file"

_sql_constraints = [
# Ensure compatibility with other modules that always expect a value in name
("name_required", "CHECK(name IS NOT NULL)", "File name is required"),
(
"sequence_code_unique",
"UNIQUE(sequence_code)",
"Sequence code must be unique",
),
]

sequence_code = fields.Char(
copy=False,
readonly=True,
)

name = fields.Char(
# We actually require it with the SQL constraint, but it is disabled
# here to let users create/write dms records without name, and let this module
# add a default name if needed
required=False,
)

@api.depends("sequence_code", "name")
def _compute_display_name(self):
res = super()._compute_display_name()
sequence_pattern = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"dms_file_sequence.display_name_pattern",
default="%(sequence_code)s - %(name)s",
)
)
for dms_file in self.filtered(
lambda file: file.sequence_code and file.sequence_code != file.name
):
dms_file.display_name = sequence_pattern % {
"name": dms_file.name,
"sequence_code": dms_file.sequence_code,
}
return res

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
"""Allow searching by sequence code by default."""
# Do not add any domain when user just clicked on search widget
if not (name == "" and operator == "ilike"):
# The dangling | is needed to combine with the domain added by super()
args = (args or []) + ["|", ("sequence_code", operator, name)]
return super().name_search(name, args, operator, limit)

@api.model_create_multi
def create(self, vals_list):
"""Apply sequence code and a default name if not set."""
for vals in vals_list:
if "sequence_code" not in vals:
vals["sequence_code"] = self.env["ir.sequence"].next_by_code(
"dms.file.sequence"
)
if not vals.get("name"):
vals["name"] = vals["sequence_code"]
res = super().create(vals_list)
return res
17 changes: 17 additions & 0 deletions dms_file_sequence/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 APSL-Nagarro - Miquel Alzanillas, Antoni Marroig
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

dms_file_display_name_pattern = fields.Char(
config_parameter="dms_file_sequence.display_name_pattern",
default="%(sequence_code)s - %(name)s",
help=(
"Use %(sequence_code)s and %(name)s to include the sequence code "
"and the name of the file in the display name."
),
)
3 changes: 3 additions & 0 deletions dms_file_sequence/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions dms_file_sequence/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [APSL-Nagarro](https://apsl.tech)
- Miquel Alzanillas \<<miquel.alzanillas@nagarro.com>\>
- Antoni Marroig \<<antoni.marroig@nagarro.com>\>
1 change: 1 addition & 0 deletions dms_file_sequence/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds a configurable sequence for dms file records.
5 changes: 5 additions & 0 deletions dms_file_sequence/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To use this module, you need to:

- Navigate to Settings > Technical > Parameters > System Parameters.
- Setup a custom sequence on System parameter called **dms_file_sequence.display_name_pattern**
- Test it when create a new record, by default if name is Test and sequence code 01 the display name will be **01 - Test**
Binary file added dms_file_sequence/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading