Skip to content
Snippets Groups Projects
Commit e5b0d0a35339 authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Fix period selection around midnight to follow timezone

parent 56863a32554d
No related branches found
No related tags found
1 merge request!34Fix period selection around midnight to follow timezone
Pipeline #65566 passed
......@@ -2,6 +2,11 @@
Changelog
=========
11.0.1.3.0
----------
Fix period selection around midnight to follow timezone.
11.0.1.2
--------
......
......@@ -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/
......@@ -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"]},
}
......@@ -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
......
freezegun
......@@ -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.
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment