GnuCash
Contact   Instructions
Bug 796984 - Import Bills & Invoices: date of line item is not validated; can lead to unexpected results
Summary: Import Bills & Invoices: date of line item is not validated; can lead to unex...
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 09:48 EST by Rob Laan
Modified: 2020-01-30 15:58 EST (History)
2 users (show)

See Also:


Attachments

Description Rob Laan 2018-12-19 09:48:45 EST
In the Import Bills & Invoice function, when the date of the line item provided in the import file (the 'date' field) is not valid, the date of the line item is accidentally set to either the date_opened (when a new invoice has previously been created) or the zero date, e.g. 01.01.1970 on OS X (when updating an invoice).

See code in dialog-bi-import.c, gnc_bi_import_create_bis

For an invalid date, qof_scan_date on line 692 leaves day, month and year untouched. These values may have been set to the values of date_opened, if in the same import an invoice was created; otherwise these values are still initial. Because date has a value (albeit invalid), the date of the line item will be set using these accidental values (701-703). E.g. creating line items with a date of 01-01-1970 on OS X.

A solution would be to already validate the date field in gnc_bi_import_fix_bis, which already validates other fields of the import. E.g. if empty or invalid date, fix with date_opened or today's date. So that gnc_bi_import_create_bis can be sure that the date field holds a valid date. 

Furthermore, lines 693-697 seem te be a leftover from a previous correction.

691         // FIXME: Must check for the return value of qof_scan_date!
692         qof_scan_date (date, &day, &month, &year);
693         {
694             GDate *date = g_date_new_dmy(day, month, year);
695             gncEntrySetDateGDate (entry, date);
696             g_date_free (date);
697         }
698         today = gnc_time (NULL);        // set today to the current date
699         if (strlen (date) != 0) // If a date is specified in CSV
700         {
701             GDate *date = g_date_new_dmy(day, month, year);
702             gncEntrySetDateGDate(entry, date);
703             gncEntrySetDateEntered(entry, gnc_dmy2time64 (day, month, year));
704         }
705         else
706         {
707             GDate *date = gnc_g_date_new_today();
708             gncEntrySetDateGDate(entry, date);
709             gncEntrySetDateEntered(entry, today);
710         }
Comment 1 Rob Laan 2020-01-30 15:58:24 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.