Bug 9280 - Bad price calculation when filling a basket with staged records
Summary: Bad price calculation when filling a basket with staged records
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Jonathan Druart
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-13 12:32 UTC by Mathieu Saby
Modified: 2014-05-26 21:04 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 9280: FIX price calculation adding an order from a staged file (2.17 KB, patch)
2012-12-13 13:30 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 9280: Followup FIX price calculation adding an order from a staged file (1.42 KB, patch)
2012-12-13 13:58 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 9280: FIX price calculation adding an order from a staged file (2.07 KB, patch)
2012-12-13 15:00 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 9280: FIX price calculation adding an order from a staged file (2.13 KB, patch)
2012-12-13 16:33 UTC, Mathieu Saby
Details | Diff | Splinter Review
[Passed QA] Bug 9280: FIX price calculation adding an order from a staged file (2.21 KB, patch)
2013-01-18 15:50 UTC, Elliott Davis
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Mathieu Saby 2012-12-13 12:32:59 UTC
Koha does not manage the VAT properly when filling a basket with staged records.


Let's take a book whose Recommended Retail Price excluding tax is 39 euros.
On the vendor's website, I import the record for this book in iso2709
In the record (UNIMARC), the price is in 010$d after the ISBN. So, I found in my record 10$d39.00 EUR
I stage this record in Koha with Stage Marc Records Tools.

In Acquisition module, I create a vendor with:
- List item price includes tax: Yes
- Invoice item price includes tax: Yes
- Discount: 9.0000 %
- Tax rate: 5.5%

I create a new basket for this vendor.
I fill this basket with my stage record.

I think I should have for the command line in this basket :
- RRP tax included : 39 euros
- Ecost tax included : 39 euros - 3,51 euros = 35,49 euros
- RRP tax excluded : 39*100/105.5 = 36,96 euros
- Ecost tax excluded : 35,49*100/105.5 = 33,63 euros

BUT instead I see the following values :
- RRP tax included : 42.86 euros
- Ecost tax included : 39 euros
- RRP tax excluded : 40,63
- Ecost tax excluded : 36,97

So, Koha considered the "39 euros" value in my record as a Ecost price. I dont think it is normal, as as chose "List item price includes tax: Yes" in vendor record.

M. Saby
Rennes 2 University
Comment 1 Jonathan Druart 2012-12-13 13:30:29 UTC Comment hidden (obsolete)
Comment 2 Mathieu Saby 2012-12-13 13:49:58 UTC
It failed : 
I have got negative ecost inc. prices (for vendor with listprice =1 ; didn't test for listprice=0)

in record : 75 euros

RRP tax inc. : 75.00
ecost inc. : -675.00
Total tax in. : -675.00
GST rate 5%
GST : -32.14

M. Saby
Comment 3 Jonathan Druart 2012-12-13 13:58:05 UTC
Yep, bad test just before pushing :-/
Comment 4 Jonathan Druart 2012-12-13 13:58:14 UTC Comment hidden (obsolete)
Comment 5 Mathieu Saby 2012-12-13 14:30:58 UTC
I applied the 2 patches. Bug partially corrected : 

1st vendor : 
List item price includes tax: Yes
Invoice item price includes tax: Yes
Discount: 10.0000 %
Tax rate: 5.0%
=> OK :

=> Stage record with 27 euros in 010$d
=> line in a basket :
- RRP tax exc.  : 25,71
- ecost tax exc. : 23,14
- RRP tax inc. : 27
- ecost tax inc. : 24,30
- Total tax exc. (EURO) : 23,14
- Total tax inc. (EURO) : 24,30
- GST % : 5%
- GST :  1,16

Prices are correct : 
- (25,71 * 5 / 100) + 25,71 = 27
- 27 * 0.9 = 24,30
- 23,14 * 5 / 100 = 24,30


2d vendor :
1st vendor : 
List item price includes tax: No
Invoice item price includes tax: Yes
Discount: 10.0000 %
Tax rate: 5.0%
=> KO 

I have exactly the same values for 2d vendor, while I was waiting for 
RRP tax exc. = 27 euros

M. Saby
Comment 6 Jonathan Druart 2012-12-13 15:00:48 UTC Comment hidden (obsolete)
Comment 7 Jonathan Druart 2012-12-13 15:06:29 UTC
I'm a little bit lost...

I don't understand the behavior we want here.
The Bug 7180 includes a complex calculation and rewrite a big part of this page but I don't know what we want for this current version.

The patch does in *ALL* cases:
rrp = 010$d (or similar)
ecost = rrp * ( 1 - discount)

This 2 values are stored in the DB and the values are calculated on the fly depending of the bookseller parameters.
Comment 8 Mathieu Saby 2012-12-13 15:26:19 UTC
Yes, it is tiresome...
I found a way to explain what I mean : 

If you create a new order line from scratch (not from staged record), Koha ask for "Vendor price", and calculates other prices.
For me, 010$d is the equivalent of this "Vendor price", and should be treated in the same way.
And it is not currently the case.


M. Saby
Comment 9 Jonathan Druart 2012-12-13 15:35:58 UTC
With the last patch, what is wrong ?
Comment 10 Mathieu Saby 2012-12-13 15:45:55 UTC
you mean only with patch 14079 ? I did not test yet...
Comment 11 Mathieu Saby 2012-12-13 16:29:04 UTC
It is OK with patch 14079, I have :

-1d vendor :
List item price includes tax: Yes
Invoice item price includes tax: Yes
Discount: 10.0000 %
Tax rate: 5.0%

stage record with 010$d = 27 euros
RRP tax exc. = 25.71 euros
RRP tax incl. = 27 euros (wich is 25.71+ (25,71 * 5/100))
discount calculated correctly

-2d vendor :
List item price includes tax: No
Invoice item price includes tax: Yes
Discount: 10.0000 %
Tax rate: 5.0%

stage record with 010$d = 27 euros
RRP tax exc. = 27 euros
RRP tax incl. = 28.35 (which is 27 + (27*5/100))
discount calculated correctly

I sign off.
Comment 12 Mathieu Saby 2012-12-13 16:33:54 UTC Comment hidden (obsolete)
Comment 13 Paul Poulain 2012-12-14 10:19:09 UTC
Is this problem really minor ? It does not happen in a lot of places, but it's very annoying (and not "circumventable" ?). I would say "normal" or "major"
Comment 14 Jonathan Druart 2012-12-14 10:50:38 UTC
Changed to "normal"
Comment 15 Elliott Davis 2013-01-18 15:50:39 UTC
Created attachment 14707 [details] [review]
[Passed QA] Bug 9280: FIX price calculation adding an order from a staged file

Test plan:
Add an order from a staged file containing a price value (010$d for
UNIMARC user).
Check this patch with 2 different vendors (listprice=1 and listprice=0).
Check the calculated price (depending discount and gstrate).

Signed-off-by: mathieu saby <mathieu.saby@univ-rennes2.fr>
Signed-off-by: Elliott Davis <elliott@bywatersolions.com>
introduces no new bugs
Comment 16 Jared Camins-Esakov 2013-01-24 13:42:56 UTC
This patch has been pushed to master.
Comment 17 Chris Cormack 2013-02-01 08:34:49 UTC
Pushed to 3.10.x will be in 3.10.3