diff --git a/NEWS.rst b/NEWS.rst index 56863a32554d71340f02c82f3486702e5da0d497_TkVXUy5yc3Q=..e5b0d0a3533945bf1e6d2a170c717aef34783910_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,11 @@ Changelog ========= +11.0.1.3.0 +---------- + +Fix period selection around midnight to follow timezone. + 11.0.1.2 -------- diff --git a/README.rst b/README.rst index 56863a32554d71340f02c82f3486702e5da0d497_UkVBRE1FLnJzdA==..e5b0d0a3533945bf1e6d2a170c717aef34783910_UkVBRE1FLnJzdA== 100644 --- a/README.rst +++ b/README.rst @@ -14,3 +14,8 @@ This module also adds a transaction date in accounting documents. Inspired from what used to be available in previous Odoo versions. + +Python Dependencies +------------------- + +freezegun: https://pypi.org/project/freezegun/ diff --git a/__manifest__.py b/__manifest__.py index 56863a32554d71340f02c82f3486702e5da0d497_X19tYW5pZmVzdF9fLnB5..e5b0d0a3533945bf1e6d2a170c717aef34783910_X19tYW5pZmVzdF9fLnB5 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -22,7 +22,7 @@ "name": "Accounting Periods", "license": "AGPL-3", "summary": "Add period accounting concept", - "version": "11.0.1.2", + "version": "11.0.1.3.0", "category": "Accounting", "author": "XCG Consulting", "website": "https://orbeet.io/", @@ -37,4 +37,5 @@ ], "demo": ["demo/account_fiscalyear_and_periods.xml"], "installable": True, + "external_dependencies": {"python": ["freezegun"]}, } diff --git a/models/account_move.py b/models/account_move.py index 56863a32554d71340f02c82f3486702e5da0d497_bW9kZWxzL2FjY291bnRfbW92ZS5weQ==..e5b0d0a3533945bf1e6d2a170c717aef34783910_bW9kZWxzL2FjY291bnRfbW92ZS5weQ== 100644 --- a/models/account_move.py +++ b/models/account_move.py @@ -18,8 +18,6 @@ # ############################################################################## -import datetime - from odoo import _, api, exceptions, fields, models @@ -104,10 +102,10 @@ - Only select open periods. """ - acc_date = datetime.date.today() + today = fields.Date.context_today(self) for accdoc in self: # Cache some data. company = accdoc.company_id @@ -108,9 +106,9 @@ for accdoc in self: # Cache some data. company = accdoc.company_id - # Set the acc_date only if the force_period_on_date - # context has provided. + # Based on context key, we may base period on the "date" field + # instead of the actual validation date (which is today). if self.env.context.get("force_period_on_date"): @@ -116,6 +114,7 @@ if self.env.context.get("force_period_on_date"): - # If accounting document date is empty, get today date. - acc_date = fields.Date.from_string(accdoc.date) or acc_date + acc_date = accdoc.date or today + else: + acc_date = today # Periods are ordered by date so selecting the first one is fine. period = self.env["account.period"].search( @@ -137,7 +136,7 @@ # last day of the period. in_cutoff = False if accdoc.journal_id.type == "sale": - period_end = fields.Date.from_string(period.date_stop) + period_end = period.date_stop in_cutoff = acc_date > period_end acc_date = period_end if in_cutoff else acc_date diff --git a/requirements b/requirements new file mode 100644 index 0000000000000000000000000000000000000000..e5b0d0a3533945bf1e6d2a170c717aef34783910_cmVxdWlyZW1lbnRz --- /dev/null +++ b/requirements @@ -0,0 +1,1 @@ +freezegun diff --git a/tests/test_account_period.py b/tests/test_account_period.py index 56863a32554d71340f02c82f3486702e5da0d497_dGVzdHMvdGVzdF9hY2NvdW50X3BlcmlvZC5weQ==..e5b0d0a3533945bf1e6d2a170c717aef34783910_dGVzdHMvdGVzdF9hY2NvdW50X3BlcmlvZC5weQ== 100644 --- a/tests/test_account_period.py +++ b/tests/test_account_period.py @@ -26,6 +26,8 @@ from .util.singleton import Singleton from .util.uuidgen import genUuid +from freezegun import freeze_time + log = logging.getLogger(__name__) @@ -93,6 +95,7 @@ # Find the period around today. We should have one in demo data. today = odoo.fields.Date.today() + year = odoo.fields.Date.from_string(today).year period_today = self._getTodayPeriod() # Control: Default dates & period around today. @@ -120,6 +123,17 @@ ) self.assertEqual(accentries.mapped("period_id").id, period_today.id) + # Ensure period selection around midnight follows timezone. + # In this test we simulate an invoice at 31/01 23:50 UTC, which becomes + # 01/02 00:50 (or 01:50) in the Paris timezone. + self.env.user.tz = "Europe/Paris" + with freeze_time(f"{year}-01-31 23:50:00"): + invoice = self._makeInvoice() + self._validateInvoice(invoice) + accdoc = invoice.move_id + self.assertEqual(accdoc.date, f"{year}-02-01") + self.assertEqual(accdoc.period_id.date_start, f"{year}-02-01") + def test_0900_close_period(self): """Check the "Close period" dialog box. """