From 88840c2df8868e03f67240a407f3580b22c33f64 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 4 Nov 2022 00:00:49 +0100 Subject: [PATCH] [IMP] account_fiscal_year_auto_create: black, isort, prettier --- .../__manifest__.py | 2 +- .../data/ir_cron.xml | 11 ++-- .../models/account_fiscal_year.py | 25 ++++----- .../tests/test_module.py | 51 +++++++++---------- .../addons/account_fiscal_year_auto_create | 1 + .../account_fiscal_year_auto_create/setup.py | 6 +++ 6 files changed, 48 insertions(+), 48 deletions(-) create mode 120000 setup/account_fiscal_year_auto_create/odoo/addons/account_fiscal_year_auto_create create mode 100644 setup/account_fiscal_year_auto_create/setup.py diff --git a/account_fiscal_year_auto_create/__manifest__.py b/account_fiscal_year_auto_create/__manifest__.py index d5f217d9..3c626186 100644 --- a/account_fiscal_year_auto_create/__manifest__.py +++ b/account_fiscal_year_auto_create/__manifest__.py @@ -10,7 +10,7 @@ "category": "Accounting", "author": "GRAP,Odoo Community Association (OCA)", "maintainers": ["legalsylvain"], - "website": "http://www.github.com/OCA/account-financial-tools", + "website": "https://github.com/OCA/account-financial-tools", "license": "AGPL-3", "depends": [ "account", diff --git a/account_fiscal_year_auto_create/data/ir_cron.xml b/account_fiscal_year_auto_create/data/ir_cron.xml index 55e7f1ab..38807d7d 100644 --- a/account_fiscal_year_auto_create/data/ir_cron.xml +++ b/account_fiscal_year_auto_create/data/ir_cron.xml @@ -1,21 +1,20 @@ - + - Auto Create Fiscal Years - - + + code model.cron_auto_create() 1 days - + -1 - + diff --git a/account_fiscal_year_auto_create/models/account_fiscal_year.py b/account_fiscal_year_auto_create/models/account_fiscal_year.py index 45c11651..09694f7e 100644 --- a/account_fiscal_year_auto_create/models/account_fiscal_year.py +++ b/account_fiscal_year_auto_create/models/account_fiscal_year.py @@ -3,6 +3,7 @@ # 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 @@ -16,12 +17,11 @@ class AccountFiscalYear(models.Model): 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) + [("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) + last_fiscal_year.date_to < datetime.now().date() + relativedelta(days=1) ): self.create(last_fiscal_year._prepare_next_fiscal_year()) @@ -33,18 +33,13 @@ class AccountFiscalYear(models.Model): # - "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) - ]): + 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 %s - %s") % ( - str(self.date_to), str(self.date_from) - ) + new_name = _("FY %s - %s") % (str(self.date_to), 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) diff --git a/account_fiscal_year_auto_create/tests/test_module.py b/account_fiscal_year_auto_create/tests/test_module.py index 8c1658cc..203fc7f7 100644 --- a/account_fiscal_year_auto_create/tests/test_module.py +++ b/account_fiscal_year_auto_create/tests/test_module.py @@ -2,53 +2,52 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests.common import TransactionCase - 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)", - }) + 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, - }) + 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): existing_fiscal_years = self.AccountFiscalYear.search([]) self.AccountFiscalYear.cron_auto_create() # Run cron should create a new fiscal year - new_fiscal_year = self.AccountFiscalYear.search([ - ("id", "not in", existing_fiscal_years.ids) - ]) + 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)) + 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() # Run cron should create a new fiscal year - new_fiscal_year = self.AccountFiscalYear.search([ - ("id", "not in", existing_fiscal_years.ids) - ]) + 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, +)