GNOME Bugzilla – Bug 734183
Importing invoices with discounts yields invoice line items with incorrect subtotals and bizzare editing behavior
Last modified: 2018-06-29 23:32:36 UTC
Found on a Debian Jessie/Sid amd64 system running GnuCash 2.6.3 When importing an invoice line item via CSV that contains a unit price and a percentage discount, the subtotal and invoice total shown does not reflect the applied discount. When editing the imported line item, the subtotal for the line reflects the discount, but when the changes are registered (by tabbing off the line, or hitting enter), the subtotal reverts to no reflecting the applied discount. How to reproduce: 1. Create a new GnuCash file (wizard options: USD, default book options, business accounts, default account setup). 2. Under Business->Customer->New Customer... create a customer with a customer ID of "EXA" 3. Under Edit->Preferences->Date/Time, set Date Format to ISO 4. Under File->Import->Import Bills and Invoices, choose to import buggy-invoice.csv (attached to this bug report) as an invoice, comma separated, and open the imported documents in tabs. 5. In the newly opened invoice, add a second line item with Unit Price $75 and a discount of 25%. 6. Click on the imported line item. 7. Edit the unit price on the imported line item to be $120, and hit "tab" (not enter) to leave the Unit Price field. 8. Hit "enter" to finish editing the line item. 9. Repeat steps 7-8 with the manually entered line. 10. Edit the discount on the imported line to be 20%, and hit "enter" to finish editing What I expected: 1. Until step 7, I expected the subtotal of the imported line item to match the subtotal of the manually entered line item, as $56.25 2. After step 7, I expected the subtotal of the imported line to be $90 3. After step 8, I expected the subtotal of the imported line to still be $90 4. After step 9, I expected both lines to have a subtotal of $90 5. After step 10, I expected the subtotal of the imported line to be $96 What I actually saw: 1. Until step 7, I saw the imported line subtotal to be $75 and the manual line subtotal to be $56.25 2. After step 7, I saw the imported line subtotal to be $90, as expected. 3. After step 8, I saw the imported line subtotal to be $120 4. After step 9, I saw the imported line to be $120, and the manual line to be $90. 5. After step 10, I saw the imported line to be $96, as expected. Why I think this is a bug: I don't believe I should be seeing multiple entered line items with the same unit price and discount but different subtotals. I don't believe the subtotal on a line item should change when I finish editing the line.
Created attachment 282349 [details] Sample invoice CSV file with discount
Also found on GnuCash 2.6.1 on an Ubuntu 14.04 amd64 system.
The denominator on the currency and discount values were being set to 1 instead of the currency denom value. Committed to maint, so the fix will be in the next release. Commit ID: b465fef9ac9ad615a5a9
I think, in fixing this bug another bug was introduced. If the "discount" field in the CSV file is empty, the value of the "price" field is inserted there. I think this is related to the fact that the statement on line 739 of src/plugins/bi_import/dialog-bi-import.c (before the commit) n = gnc_numeric_zero (); was removed without an appropriate replacement. This means that the variable "value" is basically uninitialized and not changed if the field is empty. Therefore, it "inherits" the value of the previously parsed field which is the "price" field.
Just for reference. Copy/Paste from IRC to record it here. Also re-open. [20:49] <arnd_> hi, i recently upgraded to gnucash 2.6.4 and i'm using the bi_import module. the csv files which i've always used are now imported with a non-zero discount, even though the field is empty in the file. [20:51] <arnd_> interestingly, the discount is exactly the price of the split. [20:51] <arnd_> do you have any idea what might be going wrong or how i could debug this? [21:41] <arnd_> ok, i think i tracked it down [21:41] <arnd_> https://github.com/Gnucash/gnucash/commit/b465fef9ac9ad615a5a90018dec685a3379ff03b#diff-edb1d0bbd7fb8b76b43b49a82d61b8d3L739 [21:42] <arnd_> this changeset removed the line where the variable is set to 0 before parsing the next value [21:43] <arnd_> (line 739 in src/plugins/bi_import/dialog-bi-import.c) [21:47] <arnd_> and therefore the price is incorrectly also inserted as the discount if the field is empty [22
(In reply to Arnd Behring from comment #4) > I think, in fixing this bug another bug was introduced. If the "discount" > field in the CSV file is empty, the value of the "price" field is inserted > there. I think this is related to the fact that the statement on line 739 of > src/plugins/bi_import/dialog-bi-import.c (before the commit) > > n = gnc_numeric_zero (); > > was removed without an appropriate replacement. This means that the variable > "value" is basically uninitialized and not changed if the field is empty. > Therefore, it "inherits" the value of the previously parsed field which is > the "price" field. Spot on. I've restored the initialisation to gnc_numeric_zero(); Committed to maint as 240e36f73b2
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=734183. Please update any external references or bookmarks.