diff --git a/sequence_reset_period/README.rst b/sequence_reset_period/README.rst new file mode 100644 index 0000000000..c83f17319e --- /dev/null +++ b/sequence_reset_period/README.rst @@ -0,0 +1,86 @@ +========================================= +Reset Sequences on selected period ranges +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7f18381e65f7e88cf7061788abbc5c6c5ae14ae62f13fbf222156b5b0ad18c86 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-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%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/17.0/sequence_reset_period + :alt: OCA/server-ux +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-ux-17-0/server-ux-17-0-sequence_reset_period + :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/server-ux&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module was written to reset the sequences on the specified times, +because by default they are reset yearly. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Access sequences and configurate the model to use. +- When sequence is computed, date_range will follow the specified rules + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Creu Blanca + +Contributors +------------ + +- Enric Tobella +- Jaume Planas +- Pimolnat Suntian +- Sunanda Chhatbar + +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. + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sequence_reset_period/__init__.py b/sequence_reset_period/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sequence_reset_period/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sequence_reset_period/__manifest__.py b/sequence_reset_period/__manifest__.py new file mode 100644 index 0000000000..b7c8cb8152 --- /dev/null +++ b/sequence_reset_period/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2017 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Reset Sequences on selected period ranges", + "version": "17.0.1.0.0", + "category": "Reporting", + "website": "https://github.com/OCA/server-ux", + "author": "Creu Blanca, Odoo Community Association (OCA)", + "license": "LGPL-3", + "installable": True, + "application": False, + "summary": "Auto-generate yearly/monthly/weekly/daily sequence period ranges", + "depends": ["base"], + "data": ["views/sequence_views.xml"], +} diff --git a/sequence_reset_period/i18n/es.po b/sequence_reset_period/i18n/es.po new file mode 100644 index 0000000000..fcd68cee34 --- /dev/null +++ b/sequence_reset_period/i18n/es.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_reset_period +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-08-27 16:07+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__daily +msgid "Daily" +msgstr "Diario" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__monthly +msgid "Monthly" +msgstr "Mensual" + +#. module: sequence_reset_period +#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence__range_reset +msgid "Range Reset" +msgstr "Reinicio del Rango" + +#. module: sequence_reset_period +#: model:ir.model,name:sequence_reset_period.model_ir_sequence +msgid "Sequence" +msgstr "Secuencia" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__weekly +msgid "Weekly" +msgstr "Semanal" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__yearly +msgid "Yearly" +msgstr "Anual" diff --git a/sequence_reset_period/i18n/fr_FR.po b/sequence_reset_period/i18n/fr_FR.po new file mode 100644 index 0000000000..1490153e50 --- /dev/null +++ b/sequence_reset_period/i18n/fr_FR.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_reset_period +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-04-11 18:46+0000\n" +"Last-Translator: Yves Le Doeuff \n" +"Language-Team: none\n" +"Language: fr_FR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__daily +msgid "Daily" +msgstr "Journalier" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__monthly +msgid "Monthly" +msgstr "Mensuel" + +#. module: sequence_reset_period +#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence__range_reset +msgid "Range Reset" +msgstr "Réinitialiser la plage" + +#. module: sequence_reset_period +#: model:ir.model,name:sequence_reset_period.model_ir_sequence +msgid "Sequence" +msgstr "" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__weekly +msgid "Weekly" +msgstr "Hebdomadaire" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__yearly +msgid "Yearly" +msgstr "Annuel" + +#~ msgid "Display Name" +#~ msgstr "Nom affiché" + +#~ msgid "Last Modified on" +#~ msgstr "Dernière modification le" diff --git a/sequence_reset_period/i18n/hr.po b/sequence_reset_period/i18n/hr.po new file mode 100644 index 0000000000..c356261f83 --- /dev/null +++ b/sequence_reset_period/i18n/hr.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_reset_period +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-12-04 12:04+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 3.9.1\n" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__daily +msgid "Daily" +msgstr "Dnevno" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__monthly +msgid "Monthly" +msgstr "Mjesečno" + +#. module: sequence_reset_period +#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence__range_reset +msgid "Range Reset" +msgstr "Reset raspona" + +#. module: sequence_reset_period +#: model:ir.model,name:sequence_reset_period.model_ir_sequence +msgid "Sequence" +msgstr "Sekvenca" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__weekly +msgid "Weekly" +msgstr "Tjedno" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__yearly +msgid "Yearly" +msgstr "Godišnje" diff --git a/sequence_reset_period/i18n/it.po b/sequence_reset_period/i18n/it.po new file mode 100644 index 0000000000..344118ef7c --- /dev/null +++ b/sequence_reset_period/i18n/it.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_reset_period +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-31 19:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__daily +msgid "Daily" +msgstr "Giornaliero" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__monthly +msgid "Monthly" +msgstr "Mensile" + +#. module: sequence_reset_period +#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence__range_reset +msgid "Range Reset" +msgstr "Resetta intervallo" + +#. module: sequence_reset_period +#: model:ir.model,name:sequence_reset_period.model_ir_sequence +msgid "Sequence" +msgstr "Sequenza" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__weekly +msgid "Weekly" +msgstr "Settimanale" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__yearly +msgid "Yearly" +msgstr "Annuale" diff --git a/sequence_reset_period/i18n/sequence_reset_period.pot b/sequence_reset_period/i18n/sequence_reset_period.pot new file mode 100644 index 0000000000..9643c022e8 --- /dev/null +++ b/sequence_reset_period/i18n/sequence_reset_period.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_reset_period +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__daily +msgid "Daily" +msgstr "" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__monthly +msgid "Monthly" +msgstr "" + +#. module: sequence_reset_period +#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence__range_reset +msgid "Range Reset" +msgstr "" + +#. module: sequence_reset_period +#: model:ir.model,name:sequence_reset_period.model_ir_sequence +msgid "Sequence" +msgstr "" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__weekly +msgid "Weekly" +msgstr "" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__yearly +msgid "Yearly" +msgstr "" diff --git a/sequence_reset_period/i18n/zh_CN.po b/sequence_reset_period/i18n/zh_CN.po new file mode 100644 index 0000000000..3741f93612 --- /dev/null +++ b/sequence_reset_period/i18n/zh_CN.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_reset_period +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-08-16 11:29+0000\n" +"Last-Translator: Dong \n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.10\n" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__daily +msgid "Daily" +msgstr "每天" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__monthly +msgid "Monthly" +msgstr "每月" + +#. module: sequence_reset_period +#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence__range_reset +msgid "Range Reset" +msgstr "重置周期" + +#. module: sequence_reset_period +#: model:ir.model,name:sequence_reset_period.model_ir_sequence +msgid "Sequence" +msgstr "序列号" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__weekly +msgid "Weekly" +msgstr "每周" + +#. module: sequence_reset_period +#: model:ir.model.fields.selection,name:sequence_reset_period.selection__ir_sequence__range_reset__yearly +msgid "Yearly" +msgstr "每年" diff --git a/sequence_reset_period/models/__init__.py b/sequence_reset_period/models/__init__.py new file mode 100644 index 0000000000..5b015772ab --- /dev/null +++ b/sequence_reset_period/models/__init__.py @@ -0,0 +1 @@ +from . import ir_sequence diff --git a/sequence_reset_period/models/ir_sequence.py b/sequence_reset_period/models/ir_sequence.py new file mode 100644 index 0000000000..221920457b --- /dev/null +++ b/sequence_reset_period/models/ir_sequence.py @@ -0,0 +1,73 @@ +# Copyright (C) 2017 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from datetime import date as datetime_date +from datetime import timedelta + +from dateutil.relativedelta import relativedelta + +from odoo import fields, models + + +class IrSequence(models.Model): + _inherit = "ir.sequence" + + range_reset = fields.Selection( + [ + ("daily", "Daily"), + ("weekly", "Weekly"), + ("monthly", "Monthly"), + ("yearly", "Yearly"), + ] + ) + + def _compute_date_from_to(self, date): + self.ensure_one() + date_from = date_to = date + if self.range_reset == "weekly": + date_from = date_from - timedelta(days=date_from.weekday()) + date_to = date_from + timedelta(days=6) + elif self.range_reset == "monthly": + date_from = datetime_date(date_from.year, date_from.month, 1) + date_to = date_from + relativedelta(months=1) + date_to += relativedelta(days=-1) + elif self.range_reset == "yearly": + date_from = datetime_date(date_from.year, 1, 1) + date_to = datetime_date(date_from.year, 12, 31) + return date_from, date_to + + def _create_date_range_seq(self, date): + self.ensure_one() + if not self.range_reset: + return super()._create_date_range_seq(date) + date_from, date_to = self._compute_date_from_to(date) + date_range = self.env["ir.sequence.date_range"].search( + [ + ("sequence_id", "=", self.id), + ("date_from", ">=", date), + ("date_from", "<=", date_to), + ], + order="date_from desc", + limit=1, + ) + if date_range: + date_to = date_range.date_from + timedelta(days=-1) + date_range = self.env["ir.sequence.date_range"].search( + [ + ("sequence_id", "=", self.id), + ("date_to", ">=", date_from), + ("date_to", "<=", date), + ], + order="date_to desc", + limit=1, + ) + if date_range: + date_from = date_range.date_to + timedelta(days=1) + seq_date_range = ( + self.env["ir.sequence.date_range"] + .sudo() + .create( + {"date_from": date_from, "date_to": date_to, "sequence_id": self.id} + ) + ) + return seq_date_range diff --git a/sequence_reset_period/pyproject.toml b/sequence_reset_period/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sequence_reset_period/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sequence_reset_period/readme/CONTRIBUTORS.md b/sequence_reset_period/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..9425e8efe7 --- /dev/null +++ b/sequence_reset_period/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Enric Tobella \<\> +- Jaume Planas \<\> +- Pimolnat Suntian \<\> +- Sunanda Chhatbar \<\> diff --git a/sequence_reset_period/readme/DESCRIPTION.md b/sequence_reset_period/readme/DESCRIPTION.md new file mode 100644 index 0000000000..b1b5db6b66 --- /dev/null +++ b/sequence_reset_period/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module was written to reset the sequences on the specified times, +because by default they are reset yearly. diff --git a/sequence_reset_period/readme/USAGE.md b/sequence_reset_period/readme/USAGE.md new file mode 100644 index 0000000000..72383f0564 --- /dev/null +++ b/sequence_reset_period/readme/USAGE.md @@ -0,0 +1,2 @@ +- Access sequences and configurate the model to use. +- When sequence is computed, date_range will follow the specified rules diff --git a/sequence_reset_period/static/description/icon.png b/sequence_reset_period/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sequence_reset_period/static/description/icon.png differ diff --git a/sequence_reset_period/static/description/index.html b/sequence_reset_period/static/description/index.html new file mode 100644 index 0000000000..84b7a6bf2a --- /dev/null +++ b/sequence_reset_period/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +Reset Sequences on selected period ranges + + + +
+

Reset Sequences on selected period ranges

+ + +

Beta License: LGPL-3 OCA/server-ux Translate me on Weblate Try me on Runboat

+

This module was written to reset the sequences on the specified times, +because by default they are reset yearly.

+

Table of contents

+ +
+

Usage

+
    +
  • Access sequences and configurate the model to use.
  • +
  • When sequence is computed, date_range will follow the specified rules
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/server-ux project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sequence_reset_period/tests/__init__.py b/sequence_reset_period/tests/__init__.py new file mode 100644 index 0000000000..6021908c4a --- /dev/null +++ b/sequence_reset_period/tests/__init__.py @@ -0,0 +1 @@ +from . import test_period diff --git a/sequence_reset_period/tests/test_period.py b/sequence_reset_period/tests/test_period.py new file mode 100644 index 0000000000..fbf72e57c5 --- /dev/null +++ b/sequence_reset_period/tests/test_period.py @@ -0,0 +1,99 @@ +# Copyright 2017 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + + +from datetime import date + +from odoo.tests import common + + +class TestSequence(common.TransactionCase): + def setUp(self): + super().setUp() + self.date = date(2018, 3, 14) + + def get_sequence(self, method): + return self.env["ir.sequence"].create( + { + "name": "Test sequence", + "implementation": "standard", + "use_date_range": True, + "range_reset": method, + "padding": "5", + } + ) + + def test_none(self): + sequence = self.get_sequence(False) + self.assertFalse(sequence.date_range_ids) + self.assertEqual( + "00001", sequence.with_context(ir_sequence_date=self.date).next_by_id() + ) + xrange = sequence.date_range_ids + self.assertTrue(xrange) + self.assertEqual(date(2018, 1, 1), xrange.date_from) + self.assertEqual(date(2018, 12, 31), xrange.date_to) + + def test_daily(self): + sequence = self.get_sequence("daily") + self.assertFalse(sequence.date_range_ids) + self.assertEqual( + "00001", sequence.with_context(ir_sequence_date=self.date).next_by_id() + ) + xrange = sequence.date_range_ids + self.assertTrue(xrange) + self.assertEqual(self.date, xrange.date_from) + self.assertEqual(self.date, xrange.date_to) + + def test_weekly(self): + sequence = self.get_sequence("weekly") + self.assertFalse(sequence.date_range_ids) + self.assertEqual( + "00001", sequence.with_context(ir_sequence_date=self.date).next_by_id() + ) + xrange = sequence.date_range_ids + self.assertTrue(xrange) + self.assertEqual(date(2018, 3, 12), xrange.date_from) + self.assertEqual(date(2018, 3, 18), xrange.date_to) + + def test_monthly(self): + sequence = self.get_sequence("monthly") + self.assertFalse(sequence.date_range_ids) + self.assertEqual( + "00001", sequence.with_context(ir_sequence_date=self.date).next_by_id() + ) + xrange = sequence.date_range_ids + self.assertTrue(xrange) + self.assertEqual(date(2018, 3, 1), xrange.date_from) + self.assertEqual(date(2018, 3, 31), xrange.date_to) + + def test_yearly(self): + sequence = self.get_sequence("yearly") + self.assertFalse(sequence.date_range_ids) + self.assertEqual( + "00001", sequence.with_context(ir_sequence_date=self.date).next_by_id() + ) + xrange = sequence.date_range_ids + self.assertTrue(xrange) + self.assertEqual(date(2018, 1, 1), xrange.date_from) + self.assertEqual(date(2018, 12, 31), xrange.date_to) + + def test_monthly_existing(self): + sequence = self.get_sequence("monthly") + self.env["ir.sequence.date_range"].create( + { + "date_from": date(2018, 3, 1), + "date_to": date(2018, 3, 10), + "sequence_id": sequence.id, + } + ) + self.env["ir.sequence.date_range"].create( + { + "date_from": date(2018, 3, 20), + "date_to": date(2018, 3, 25), + "sequence_id": sequence.id, + } + ) + self.assertEqual( + "00001", sequence.with_context(ir_sequence_date=self.date).next_by_id() + ) diff --git a/sequence_reset_period/views/sequence_views.xml b/sequence_reset_period/views/sequence_views.xml new file mode 100644 index 0000000000..900a58d80a --- /dev/null +++ b/sequence_reset_period/views/sequence_views.xml @@ -0,0 +1,12 @@ + + + + ir.sequence + + + + + + + +