Bug 14680: Always subtract discount from price to calculate estimated cost

This patch simply removes a discrepancty where when a discount is provided on the order form
we add the discount to the price, and when it comes form the vendor we subtract the discount.

Discounts should always descrease the estimated cost

To test:
 0 - Have a vendor with a discount of 10% specified
 1 - Export a record from your Koha
 2 - Stage the record for import and match on biblionumber
 3 - Add to a basket in acq from the staged file
 4 - Select the title, and set order price to $10 and do not fill the discount field
 5 - Add the order - note $10 RRP and $9 actual/budgeted cost
 6 - Repeat 2&3
 7 - Select the tile, set price $10 and discount 50%
 8 - Add the order - note $20 RRP and $10 actual/budgeted cost! FAIL
 9 - Apply patch, restart all
10 - Repeat 2-7
11 - Add the order, note $10 RRP and $5 actual.budgeted cost

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 7c734c6903)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 96eed0f5e0)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
(cherry picked from commit da1633125f)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
This commit is contained in:
Nick Clemens 2022-07-12 18:10:54 +00:00 committed by Victor Grousset/tuxayo
parent 76095f9dc9
commit b494df730f
1 changed files with 4 additions and 10 deletions

View File

@ -275,11 +275,8 @@ if ($op eq ""){
$orderinfo{tax_rate} = $bookseller->tax_rate;
my $c = $c_discount ? $c_discount : $bookseller->discount / 100;
$orderinfo{discount} = $c;
if ( $c_discount ) {
$orderinfo{ecost} = $price;
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c );
} else {
$orderinfo{ecost} = $price * ( 1 - $c );
if ( $c ) {
$orderinfo{ecost} = $price * ( 1 - $c / 100 );
$orderinfo{rrp} = $price;
}
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
@ -336,11 +333,8 @@ if ($op eq ""){
$orderinfo{tax_rate} = $bookseller->tax_rate;
my $c = $c_discount ? $c_discount : $bookseller->discount / 100;
$orderinfo{discount} = $c;
if ( $c_discount ) {
$orderinfo{ecost} = $c_price;
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c );
} else {
$orderinfo{ecost} = $c_price * ( 1 - $c );
if ( $c ) {
$orderinfo{ecost} = $c_price * ( 1 - $c / 100 );
$orderinfo{rrp} = $c_price;
}
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;