diff --git a/account_fiscal_year_auto_create/README.rst b/account_fiscal_year_auto_create/README.rst new file mode 100644 index 00000000..2cca26ff --- /dev/null +++ b/account_fiscal_year_auto_create/README.rst @@ -0,0 +1,105 @@ +================================= +Fiscal Years - Automatic Creation +================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/12.0/account_fiscal_year_auto_create + :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-12-0/account-financial-tools-12-0-account_fiscal_year_auto_create + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of Accounting Odoo module, to +auto generate fiscal years. + +Once installed, a cron is running each day. It will create, for each company, +a new fiscal year, if it is the last day of the current fiscal year. + +This module is interesting specially in multi company context, to avoid annoying setup every year. + +The fiscal year created has a classical "12 monthes" duration, but the accountant +can modify it, once created. + +Exemple +~~~~~~~ + +If a company has it last fiscal year, defined as: + +- ``name``: FY 2021-2022 +- ``date_from``: 2021-06-01 +- ``date_to``: 2022-05-31 + +When the cron will be executed on May 31, 2022, it will create the following fiscal year: + +- ``name``: FY 2022-2023 +- ``date_from``: 2022-06-01 +- ``date_to``: 2023-05-31 + +**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 +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Sylvain LE GAL + +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-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +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/account_fiscal_year_auto_create/__init__.py b/account_fiscal_year_auto_create/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_fiscal_year_auto_create/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_fiscal_year_auto_create/__manifest__.py b/account_fiscal_year_auto_create/__manifest__.py new file mode 100644 index 00000000..a97a3506 --- /dev/null +++ b/account_fiscal_year_auto_create/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Fiscal Years - Automatic Creation", + "summary": "Automatically create new fiscal years, based on the datas" + " of the last fiscal years", + "version": "16.0.1.0.1", + "category": "Accounting", + "author": "GRAP,Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "website": "https://github.com/OCA/account-financial-tools", + "license": "AGPL-3", + "depends": [ + "account_fiscal_year", + ], + "data": [ + "data/ir_cron.xml", + ], +} diff --git a/account_fiscal_year_auto_create/data/ir_cron.xml b/account_fiscal_year_auto_create/data/ir_cron.xml new file mode 100644 index 00000000..46b4e35b --- /dev/null +++ b/account_fiscal_year_auto_create/data/ir_cron.xml @@ -0,0 +1,20 @@ + + + + + Auto Create Fiscal Years + + + code + model.cron_auto_create() + 1 + days + + -1 + + + diff --git a/account_fiscal_year_auto_create/i18n/account_fiscal_year_auto_create.pot b/account_fiscal_year_auto_create/i18n/account_fiscal_year_auto_create.pot new file mode 100644 index 00000000..cdbc5c25 --- /dev/null +++ b/account_fiscal_year_auto_create/i18n/account_fiscal_year_auto_create.pot @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_fiscal_year_auto_create +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: account_fiscal_year_auto_create +#: model:ir.actions.server,name:account_fiscal_year_auto_create.cron_fiscal_year_auto_create_ir_actions_server +#: model:ir.cron,cron_name:account_fiscal_year_auto_create.cron_fiscal_year_auto_create +#: model:ir.cron,name:account_fiscal_year_auto_create.cron_fiscal_year_auto_create +msgid "Auto Create Fiscal Years" +msgstr "" + +#. module: account_fiscal_year_auto_create +#: code:addons/account_fiscal_year_auto_create/models/account_fiscal_year.py:45 +#, python-format +msgid "FY %s - %s" +msgstr "" + +#. module: account_fiscal_year_auto_create +#: model:ir.model,name:account_fiscal_year_auto_create.model_account_fiscal_year +msgid "Fiscal Year" +msgstr "" + diff --git a/account_fiscal_year_auto_create/i18n/fr.po b/account_fiscal_year_auto_create/i18n/fr.po new file mode 100644 index 00000000..34ea5145 --- /dev/null +++ b/account_fiscal_year_auto_create/i18n/fr.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_fiscal_year_auto_create +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-08-03 18:49+0000\n" +"Last-Translator: Pascal GOUHIER \n" +"Language-Team: none\n" +"Language: 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: account_fiscal_year_auto_create +#: model:ir.actions.server,name:account_fiscal_year_auto_create.cron_fiscal_year_auto_create_ir_actions_server +#: model:ir.cron,cron_name:account_fiscal_year_auto_create.cron_fiscal_year_auto_create +#: model:ir.cron,name:account_fiscal_year_auto_create.cron_fiscal_year_auto_create +msgid "Auto Create Fiscal Years" +msgstr "Créer Automatiquement Les Exercices Fiscaux" + +#. module: account_fiscal_year_auto_create +#: code:addons/account_fiscal_year_auto_create/models/account_fiscal_year.py:45 +#, python-format +msgid "FY %s - %s" +msgstr "AF %s - %s" + +#. module: account_fiscal_year_auto_create +#: model:ir.model,name:account_fiscal_year_auto_create.model_account_fiscal_year +msgid "Fiscal Year" +msgstr "Exercice Fiscal" diff --git a/account_fiscal_year_auto_create/models/__init__.py b/account_fiscal_year_auto_create/models/__init__.py new file mode 100644 index 00000000..562a420f --- /dev/null +++ b/account_fiscal_year_auto_create/models/__init__.py @@ -0,0 +1 @@ +from . import account_fiscal_year diff --git a/account_fiscal_year_auto_create/models/account_fiscal_year.py b/account_fiscal_year_auto_create/models/account_fiscal_year.py new file mode 100644 index 00000000..145dc5fc --- /dev/null +++ b/account_fiscal_year_auto_create/models/account_fiscal_year.py @@ -0,0 +1,54 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from datetime import datetime + +from dateutil.relativedelta import relativedelta + +from odoo import _, api, models + + +class AccountFiscalYear(models.Model): + _inherit = "account.fiscal.year" + + @api.model + def cron_auto_create(self): + companies = self.env["res.company"].search([]) + for company in companies: + last_fiscal_year = self.search( + [("company_id", "=", company.id)], order="date_to desc", limit=1 + ) + + if last_fiscal_year and ( + last_fiscal_year.date_to < datetime.now().date() + relativedelta(days=1) + ): + self.create(last_fiscal_year._prepare_next_fiscal_year()) + + def _prepare_next_fiscal_year(self): + self.ensure_one() + # try to generate a new name, based on the previous + # name replacing YYYY pattern by YYYY+1 value + # - "FY 2018" will be replace by "FY 2019" + # - "FY 2018-2019" will be replace by "FY 2019-2020" + new_name = self.name.replace( + str(self.date_to.year), str(self.date_to.year + 1) + ).replace(str(self.date_from.year), str(self.date_from.year + 1)) + if self.search( + [("name", "=", new_name), ("company_id", "=", self.company_id.id)] + ): + # the replace process fail to guess a correct unique name + new_name = _( + "FY %(date_to)s - %(date_from)s", + date_to=str(self.date_to), + date_from=str(self.date_from), + ) + # compute new dates, handling leap years + new_date_from = self.date_to + relativedelta(days=1) + new_date_to = new_date_from + relativedelta(years=1, days=-1) + return { + "name": new_name, + "company_id": self.company_id.id, + "date_from": new_date_from.strftime("%Y-%m-%d"), + "date_to": new_date_to.strftime("%Y-%m-%d"), + } diff --git a/account_fiscal_year_auto_create/readme/CONTRIBUTORS.rst b/account_fiscal_year_auto_create/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9f76a75b --- /dev/null +++ b/account_fiscal_year_auto_create/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/account_fiscal_year_auto_create/readme/DESCRIPTION.rst b/account_fiscal_year_auto_create/readme/DESCRIPTION.rst new file mode 100644 index 00000000..525ccd60 --- /dev/null +++ b/account_fiscal_year_auto_create/readme/DESCRIPTION.rst @@ -0,0 +1,25 @@ +This module extends the functionality of Accounting Odoo module, to +auto generate fiscal years. + +Once installed, a cron is running each day. It will create, for each company, +a new fiscal year, if it is the last day of the current fiscal year. + +This module is interesting specially in multi company context, to avoid annoying setup every year. + +The fiscal year created has a classical "12 monthes" duration, but the accountant +can modify it, once created. + +Example +~~~~~~~ + +If a company has it last fiscal year, defined as: + +- ``name``: FY 2021-2022 +- ``date_from``: 2021-06-01 +- ``date_to``: 2022-05-31 + +When the cron will be executed on May 31, 2022, it will create the following fiscal year: + +- ``name``: FY 2022-2023 +- ``date_from``: 2022-06-01 +- ``date_to``: 2023-05-31 diff --git a/account_fiscal_year_auto_create/static/description/icon.png b/account_fiscal_year_auto_create/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_fiscal_year_auto_create/static/description/icon.png differ diff --git a/account_fiscal_year_auto_create/static/description/index.html b/account_fiscal_year_auto_create/static/description/index.html new file mode 100644 index 00000000..2b1f1298 --- /dev/null +++ b/account_fiscal_year_auto_create/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +Fiscal Years - Automatic Creation + + + +
+

Fiscal Years - Automatic Creation

+ + +

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

+

This module extends the functionality of Accounting Odoo module, to +auto generate fiscal years.

+

Once installed, a cron is running each day. It will create, for each company, +a new fiscal year, if it is the last day of the current fiscal year.

+

This module is interesting specially in multi company context, to avoid annoying setup every year.

+

The fiscal year created has a classical “12 monthes” duration, but the accountant +can modify it, once created.

+
+

Exemple

+

If a company has it last fiscal year, defined as:

+
    +
  • name: FY 2021-2022
  • +
  • date_from: 2021-06-01
  • +
  • date_to: 2022-05-31
  • +
+

When the cron will be executed on May 31, 2022, it will create the following fiscal year:

+
    +
  • name: FY 2022-2023
  • +
  • date_from: 2022-06-01
  • +
  • date_to: 2023-05-31
  • +
+

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.

+
+ +
+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

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.

+

Current maintainer:

+

legalsylvain

+

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/account_fiscal_year_auto_create/tests/__init__.py b/account_fiscal_year_auto_create/tests/__init__.py new file mode 100644 index 00000000..d9b96c4f --- /dev/null +++ b/account_fiscal_year_auto_create/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/account_fiscal_year_auto_create/tests/test_module.py b/account_fiscal_year_auto_create/tests/test_module.py new file mode 100644 index 00000000..379af291 --- /dev/null +++ b/account_fiscal_year_auto_create/tests/test_module.py @@ -0,0 +1,52 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from datetime import date, datetime + +from odoo.tests.common import TransactionCase + + +class TestModule(TransactionCase): + def setUp(self): + super().setUp() + self.AccountFiscalYear = self.env["account.fiscal.year"] + self.company = self.env["res.company"].create( + { + "name": "Demo Company (account_fiscal_year_auto_create)", + } + ) + + # create a fiscal year + self.last_year = datetime.now().year - 1 + self.last_fiscal_year = self.AccountFiscalYear.create( + { + "name": "FY %d" % (self.last_year), + "date_from": date(self.last_year, 1, 1).strftime("%Y-%m-%d"), + "date_to": date(self.last_year, 12, 31).strftime("%Y-%m-%d"), + "company_id": self.company.id, + } + ) + + def test_cron(self): + # Run cron should create a new fiscal year + existing_fiscal_years = self.AccountFiscalYear.search([]) + self.AccountFiscalYear.cron_auto_create() + + new_fiscal_year = self.AccountFiscalYear.search( + [("id", "not in", existing_fiscal_years.ids)] + ) + self.assertTrue(new_fiscal_year) + self.assertEqual(new_fiscal_year.name, "FY %d" % (self.last_year + 1)) + self.assertEqual(new_fiscal_year.date_from, date(self.last_year + 1, 1, 1)) + self.assertEqual(new_fiscal_year.date_from, date(self.last_year + 1, 1, 1)) + self.assertEqual(new_fiscal_year.name, "FY %d" % (self.last_year + 1)) + + # Rerun cron should not create a new fiscal year + existing_fiscal_years = self.AccountFiscalYear.search([]) + self.AccountFiscalYear.cron_auto_create() + + new_fiscal_year = self.AccountFiscalYear.search( + [("id", "not in", existing_fiscal_years.ids)] + ) + self.assertFalse(new_fiscal_year) diff --git a/setup/account_fiscal_year_auto_create/odoo/addons/account_fiscal_year_auto_create b/setup/account_fiscal_year_auto_create/odoo/addons/account_fiscal_year_auto_create new file mode 120000 index 00000000..77a626fe --- /dev/null +++ b/setup/account_fiscal_year_auto_create/odoo/addons/account_fiscal_year_auto_create @@ -0,0 +1 @@ +../../../../account_fiscal_year_auto_create \ No newline at end of file diff --git a/setup/account_fiscal_year_auto_create/setup.py b/setup/account_fiscal_year_auto_create/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_fiscal_year_auto_create/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)