gnucash maint: Fix transaction post_date being set to midnight local.
John Ralls
jralls at code.gnucash.org
Thu Apr 30 15:20:56 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/b4177bc6 (commit)
from https://github.com/Gnucash/gnucash/commit/1e598191 (commit)
commit b4177bc60abc1ed60a2d80a791376680493c0659
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Apr 30 11:30:03 2020 -0700
Fix transaction post_date being set to midnight local.
Reported for Invoices on gnucash-user. Checked all other uses of
xaccTransSetPostDateSecs(), fixed the ones that weren't passing an
already normalized time64. For Invoices change the post_date to also be
normalized so that it stays the same as the transaction post_date. That
also protects it from the displayed date changing depending on timezone.
The python binding invoice post_time test had to be changed to match.
diff --git a/bindings/python/tests/test_business.py b/bindings/python/tests/test_business.py
index 0238d9d74..97528ec71 100644
--- a/bindings/python/tests/test_business.py
+++ b/bindings/python/tests/test_business.py
@@ -1,6 +1,6 @@
from unittest import main
-from datetime import datetime, timedelta
+from datetime import datetime, timezone
from gnucash import Account, \
ACCT_TYPE_RECEIVABLE, ACCT_TYPE_INCOME, ACCT_TYPE_BANK, \
@@ -56,8 +56,8 @@ class TestBusiness(BusinessSession):
self.assertEqual( NAME, self.employee.GetUsername() )
def test_post(self):
- self.assertEqual(self.today - timedelta(0, 0, self.today.microsecond),
- self.invoice.GetDatePosted())
+ self.assertEqual(datetime.now(timezone.utc).replace(hour=10, minute=59, second=0, microsecond=0).astimezone(),
+ self.invoice.GetDatePosted().astimezone())
self.assertTrue( self.invoice.IsPosted() )
def test_owner(self):
diff --git a/gnucash/gnome-utils/dialog-transfer.c b/gnucash/gnome-utils/dialog-transfer.c
index 70a1aec77..1657d77ff 100644
--- a/gnucash/gnome-utils/dialog-transfer.c
+++ b/gnucash/gnome-utils/dialog-transfer.c
@@ -1514,7 +1514,7 @@ create_transaction(XferDialog *xferData, time64 time,
xaccTransBeginEdit(trans);
xaccTransSetCurrency(trans, xferData->from_commodity);
- xaccTransSetDatePostedSecs(trans, time);
+ xaccTransSetDatePostedSecsNormalized(trans, time);
/* Trans-Num or Split-Action set with gnc_set_num_action below per book
* option */
diff --git a/gnucash/gnome-utils/gnc-tree-view-split-reg.c b/gnucash/gnome-utils/gnc-tree-view-split-reg.c
index 533c3293b..016021211 100644
--- a/gnucash/gnome-utils/gnc-tree-view-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-view-split-reg.c
@@ -2450,7 +2450,7 @@ gtv_sr_begin_edit (GncTreeViewSplitReg *view, Transaction *trans)
//is a new transaction and set the time to current time to show current
//date on new transactions
time = gnc_time (NULL);
- xaccTransSetDatePostedSecs (trans, time);
+ xaccTransSetDatePostedSecsNormalized (trans, time);
}
}
LEAVE(" ");
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index 9ad48692c..a399e6580 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -1506,8 +1506,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
/* Entered and Posted at date */
xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
- xaccTransSetDatePostedSecs (txn, post_date);
- gncInvoiceSetDatePosted (invoice, post_date);
+ xaccTransSetDatePostedSecsNormalized (txn, post_date);
+ gncInvoiceSetDatePosted (invoice, xaccTransRetDatePosted(txn));
xaccTransSetDateDue (txn, due_date);
Summary of changes:
bindings/python/tests/test_business.py | 6 +++---
gnucash/gnome-utils/dialog-transfer.c | 2 +-
gnucash/gnome-utils/gnc-tree-view-split-reg.c | 2 +-
libgnucash/engine/gncInvoice.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
More information about the gnucash-changes
mailing list