diff --git a/sequence_date_range/README.rst b/sequence_date_range/README.rst new file mode 100644 index 000000000..5bfcf1969 --- /dev/null +++ b/sequence_date_range/README.rst @@ -0,0 +1,82 @@ +=================== +sequence_date_range +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/10.0/sequence_date_range + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-10-0/account-financial-tools-10-0-sequence_date_range + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Currently, the range_year is the date filled into the date_from. + +This add-on allow the user to pick the date field used as the range_year +parameter into sequence generation. + +Ex: date_from = '2018-10-01' and date_to = '2019-09-30'. +If you select 'date_to' as reference date, your range_year will be 2019 +(instead of 2018 if you let the default 'date_from'). + +You can setup this field into sequences configuration. + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* François Honoré (ACSONE SA/NV) + +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/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sequence_date_range/__init__.py b/sequence_date_range/__init__.py new file mode 100644 index 000000000..34bf09c71 --- /dev/null +++ b/sequence_date_range/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/sequence_date_range/__manifest__.py b/sequence_date_range/__manifest__.py new file mode 100644 index 000000000..4864566bb --- /dev/null +++ b/sequence_date_range/__manifest__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "sequence_date_range", + 'summary': """Module used to use the year of the date_to + into sequences (instead of date_from)""", + 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'website': "https://github.com/OCA/server-tools", + 'category': 'account', + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'depends': [ + 'base', + ], + 'demo': [ + 'demo/ir_sequence.xml', + ], + 'data': [ + 'views/ir_sequence.xml', + ], +} diff --git a/sequence_date_range/demo/ir_sequence.xml b/sequence_date_range/demo/ir_sequence.xml new file mode 100644 index 000000000..9216a40f7 --- /dev/null +++ b/sequence_date_range/demo/ir_sequence.xml @@ -0,0 +1,36 @@ + + + + + Demo sequence + custom.demo.sequence + STJ/%(range_year)s-%(range_month)s-%(range_day)s/ + date_to + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sequence_date_range/models/__init__.py b/sequence_date_range/models/__init__.py new file mode 100644 index 000000000..9f12f9d48 --- /dev/null +++ b/sequence_date_range/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import ir_sequence +from . import ir_sequence_date_range diff --git a/sequence_date_range/models/ir_sequence.py b/sequence_date_range/models/ir_sequence.py new file mode 100644 index 000000000..9fc98c9cc --- /dev/null +++ b/sequence_date_range/models/ir_sequence.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class IrSequence(models.Model): + _inherit = 'ir.sequence' + + date_range_field = fields.Selection( + selection=[ + ('date_from', 'From'), + ('date_to', 'To'), + ], + required=True, + default="date_from", + help="Define which date field must be used in case of date ranges as " + "the reference date to generate sequences.\n" + "Ex: date_from = '2018-10-01' and date_to = '2019-09-30'.\n" + "If you pick 'date_to' as reference date, your range_year will " + "be 2019 (2018 if you pick the 'date_from', who is the default)", + ) diff --git a/sequence_date_range/models/ir_sequence_date_range.py b/sequence_date_range/models/ir_sequence_date_range.py new file mode 100644 index 000000000..42aeea24d --- /dev/null +++ b/sequence_date_range/models/ir_sequence_date_range.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import api, models + + +class IrSequenceDateRange(models.Model): + _inherit = 'ir.sequence.date_range' + + @api.multi + def _next(self): + """ + Inherit to use the date_to (instead of date_from) as the base date + :return: str + """ + seq_date_range = self.env.context.get('ir_sequence_date_range') + if seq_date_range and self.sequence_id.date_range_field: + expected_value = self[self.sequence_id.date_range_field] + if seq_date_range != expected_value: + self = self.with_context(ir_sequence_date_range=expected_value) + return super(IrSequenceDateRange, self)._next() diff --git a/sequence_date_range/readme/CONTRIBUTORS.rst b/sequence_date_range/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..595a780d4 --- /dev/null +++ b/sequence_date_range/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* François Honoré (ACSONE SA/NV) diff --git a/sequence_date_range/readme/DESCRIPTION.rst b/sequence_date_range/readme/DESCRIPTION.rst new file mode 100644 index 000000000..5e8658429 --- /dev/null +++ b/sequence_date_range/readme/DESCRIPTION.rst @@ -0,0 +1,10 @@ +Currently, the range_year is the date filled into the date_from. + +This add-on allow the user to pick the date field used as the range_year +parameter into sequence generation. + +Ex: date_from = '2018-10-01' and date_to = '2019-09-30'. +If you select 'date_to' as reference date, your range_year will be 2019 +(instead of 2018 if you let the default 'date_from'). + +You can setup this field into sequences configuration. diff --git a/sequence_date_range/static/description/index.html b/sequence_date_range/static/description/index.html new file mode 100644 index 000000000..72cfcbd55 --- /dev/null +++ b/sequence_date_range/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +sequence_date_range + + + +
+

sequence_date_range

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runbot

+

This add-on allow the user to pick the date field used as the range_year +parameter into sequence generation.

+

Actually, the range_year is the date filled into the date_from. +Ex: date_from = ‘2018-10-01’ and date_to = ‘2019-09-30’. +If you select ‘date_to’ as reference date, your range_year will be 2019 +(instead of 2018 if you let the default ‘date_from’).

+

You can setup this field into sequences configuration.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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/account-financial-tools project on GitHub.

+

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

+
+
+
+ + diff --git a/sequence_date_range/tests/__init__.py b/sequence_date_range/tests/__init__.py new file mode 100644 index 000000000..f97ad8303 --- /dev/null +++ b/sequence_date_range/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_ir_sequence_date_range diff --git a/sequence_date_range/tests/test_ir_sequence_date_range.py b/sequence_date_range/tests/test_ir_sequence_date_range.py new file mode 100644 index 000000000..0c76b6888 --- /dev/null +++ b/sequence_date_range/tests/test_ir_sequence_date_range.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.tests.common import TransactionCase +from odoo import fields + + +class TestIrSequenceDateRange(TransactionCase): + """ + Tests for ir.sequence.date_range + """ + + def setUp(self): + super(TestIrSequenceDateRange, self).setUp() + self.sequence = self.env.ref( + "sequence_date_range.ir_sequence_demo") + + def _get_current_date_range(self, sequence=False): + """ + Get the sequence date range related to the current date + :param sequence: ir.sequence recordset + :return: ir.sequence.date_range recordset + """ + sequence = sequence or self.sequence + today = fields.Date.today() + if self.env.context.get('ir_sequence_date'): + today = self.env.context.get('ir_sequence_date') + seq_date = self.env['ir.sequence.date_range'].search([ + ('sequence_id', '=', sequence.id), + ('date_from', '<=', today), + ('date_to', '>=', today), + ], limit=1) + return seq_date + + def test_using_date_range1(self): + """ + Test the date range sequence. + Check if the date (used into the generated sequence) is the one set + into the date_to field (instead of date_from) + :return: + """ + self.assertEquals(self.sequence.date_range_field, 'date_to') + current_date_range = self._get_current_date_range() + date_to = fields.Date.from_string(current_date_range.date_to) + value = self.sequence._next() + expected_str = date_to.strftime("%Y-%m-%d") + self.assertIn(expected_str, value) + return + + def test_using_date_range2(self): + """ + Test the date range sequence. + Check if the date (used into the generated sequence) is the one set + into the date_from field + :return: + """ + self.sequence.write({ + 'date_range_field': 'date_from', + }) + self.assertEquals(self.sequence.date_range_field, 'date_from') + current_date_range = self._get_current_date_range() + date_from = fields.Date.from_string(current_date_range.date_from) + value = self.sequence._next() + expected_str = date_from.strftime("%Y-%m-%d") + self.assertIn(expected_str, value) + return diff --git a/sequence_date_range/views/ir_sequence.xml b/sequence_date_range/views/ir_sequence.xml new file mode 100644 index 000000000..8da1e2c8d --- /dev/null +++ b/sequence_date_range/views/ir_sequence.xml @@ -0,0 +1,16 @@ + + + + + ir.sequence.form (in sequence_date_range) + ir.sequence + + + + + + + + + diff --git a/setup/sequence_date_range/odoo/__init__.py b/setup/sequence_date_range/odoo/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/sequence_date_range/odoo/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/sequence_date_range/odoo/addons/__init__.py b/setup/sequence_date_range/odoo/addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/sequence_date_range/odoo/addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/sequence_date_range/odoo/addons/sequence_date_range b/setup/sequence_date_range/odoo/addons/sequence_date_range new file mode 120000 index 000000000..ee7a856cd --- /dev/null +++ b/setup/sequence_date_range/odoo/addons/sequence_date_range @@ -0,0 +1 @@ +../../../../sequence_date_range \ No newline at end of file diff --git a/setup/sequence_date_range/setup.py b/setup/sequence_date_range/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sequence_date_range/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)