GnuCash
Contact   Instructions
Bug 796986 - Import Bills & Invoices: in case of invalid posting date in import file, invoice is posted with unexpected date
Summary: Import Bills & Invoices: in case of invalid posting date in import file, invo...
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Import - CSV (show other bugs)
Version: git-maint
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rob Laan
QA Contact: import
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-19 14:36 EST by Rob Laan
Modified: 2020-01-30 15:57 EST (History)
2 users (show)

See Also:


Attachments

Description Rob Laan 2018-12-19 14:36:46 EST
In the Import Bills & Invoices function, if the date_posted provided in the import file is not a valid date, the invoice will be posted with an accidental date, either the date of the line item, or the zero date of the operating system (e.g. 01-01-1970 on OS X).

dialog-bi-import.c

On line 776, qof_scan_date attempts to set the day, month and year based on date_posted. However, if date_posted is not a valid date, qof_scan_date leaves day, month and year unchanged. These values may previously have been set by qof_scan_date of the date of the last line item processed (line 692), or may even be initial, if the date of the line item is also invalid date (see bug 796984). So the invoice will be posted with an accidental posting date (line 790), either the date of the last line item processed, or a zero date . That same date may be passed to the due date as well.


770                 // autopost this invoice
771                 GHashTable *foreign_currs;
772                 gboolean auto_pay;
773                 time64 p_date, d_date;
774                 guint curr_count;
775                 gboolean scan_date_r;
776                 scan_date_r = qof_scan_date (date_posted, &day, &month, &year);
777                 DEBUG("Invoice %s is marked to be posted because...", id);
778                 DEBUG("qof_scan_date = %d", scan_date_r);
779                 if (g_ascii_strcasecmp (type, "INVOICE") == 0)
780                     auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_AUTO_PAY);
781                 else
782                     auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
783                 // Do we have any foreign currencies to deal with?
784                 foreign_currs = gncInvoiceGetForeignCurrencies (invoice);
785                 curr_count = g_hash_table_size (foreign_currs);
786                 DEBUG("curr_count = %d",curr_count);
787                 // Only auto-post if there's a single currency involved
788                 if(curr_count == 0)
789                 {
790                     p_date = gnc_dmy2time64 (day, month, year);
791                     // Check for the return value of qof_scan_date


A possible solution would be to change the logic in gnc_bi_import_fix_bis. At line 356, the code checks if the date_posted is a valid date. If not, it leaves the date_posted as it is. Instead, if the date_posted is not valid and not "", it should either reject the line with an message to the user, or set the date_posted to "" (so that the system will not attempt to post it in subsequent processing). The latter seems to be the better option, as the former may result in some items of an invoice deleted, and some posted.
Comment 1 Rob Laan 2020-01-30 15:57:27 EST
Pull request #457 merged into maint, https://github.com/Gnucash/gnucash/pull/457.

Note You need to log in before you can comment on or make changes to this bug.