Skip to content

Commit

Permalink
Fix transaction post_date being set to midnight local.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jralls committed Apr 30, 2020
1 parent 1e59819 commit b4177bc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions 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, \
Expand Down Expand Up @@ -56,8 +56,8 @@ def test_employee_name(self):
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):
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/dialog-transfer.c
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-tree-view-split-reg.c
Expand Up @@ -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(" ");
Expand Down
4 changes: 2 additions & 2 deletions libgnucash/engine/gncInvoice.c
Expand Up @@ -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);

Expand Down

0 comments on commit b4177bc

Please sign in to comment.