@@ -, +, @@ --- C4/Acquisition.pm | 18 ++++++++++---- t/Prices.t | 61 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 11 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -3070,7 +3070,11 @@ sub populate_order_with_prices { $order->{rrp_tax_included} = $order->{rrp}; # price tax excluded = price tax included / ( 1 + tax rate ) - $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_ordering} ); + $order->{unitprice_tax_excluded} = + defined( $order->{unitprice_tax_included} ) + ? $order->{unitprice_tax_included} / + ( 1 + $order->{tax_rate_on_ordering} ) + : undef; $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} ); # ecost tax included = rrp tax included ( 1 - discount ) @@ -3081,8 +3085,8 @@ sub populate_order_with_prices { # tax value = quantity * ecost tax excluded * tax rate # we should use the unitprice if included - my $cost_tax_included = $order->{unitprice_tax_included} || $order->{ecost_tax_included}; - my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded}; + my $cost_tax_included = $order->{unitprice_tax_included} // $order->{ecost_tax_included}; + my $cost_tax_excluded = $order->{unitprice_tax_excluded} // $order->{ecost_tax_excluded}; $order->{tax_value_on_ordering} = ( get_rounded_price($cost_tax_included) - get_rounded_price($cost_tax_excluded) ) * $order->{quantity}; } @@ -3092,7 +3096,11 @@ sub populate_order_with_prices { $order->{rrp_tax_excluded} = $order->{rrp}; # price tax included = price tax excluded * ( 1 - tax rate ) - $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} ); + $order->{unitprice_tax_included} = + defined( $order->{unitprice_tax_excluded} ) + ? $order->{unitprice_tax_excluded} * + ( 1 + $order->{tax_rate_on_ordering} ) + : undef; $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} ); # ecost tax excluded = rrp tax excluded * ( 1 - discount ) @@ -3103,7 +3111,7 @@ sub populate_order_with_prices { # tax value = quantity * ecost tax included * tax rate # we should use the unitprice if included - my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded}; + my $cost_tax_excluded = $order->{unitprice_tax_excluded} // $order->{ecost_tax_excluded}; $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($cost_tax_excluded) * $order->{tax_rate_on_ordering}; } } --- a/t/Prices.t +++ a/t/Prices.t @@ -67,6 +67,7 @@ for my $currency_format ( qw( US FR ) ) { discount => 10.0000, datereceived => $today }; + $order_0_0 = C4::Acquisition::populate_order_with_prices( { order => $order_0_0, @@ -151,14 +152,13 @@ for my $currency_format ( qw( US FR ) ) { }; subtest 'Configuration 1: 1 1' => sub { - plan tests => 8; + plan tests => 9; my $biblionumber_1_1 = 43; my $order_1_1 = { biblionumber => $biblionumber_1_1, quantity => 2, listprice => 82.000000, - unitprice => 73.800000, quantityreceived => 2, basketno => $basketno_1_1, invoiceid => $invoiceid_1_1, @@ -218,6 +218,23 @@ for my $currency_format ( qw( US FR ) ) { } ); + $order_1_1->{unitprice} = 73.800000; + $order_1_1 = C4::Acquisition::populate_order_with_prices( + { + order => $order_1_1, + booksellerid => 4, + ordering => 1, + } + ); + compare( + { + got => $order_1_1->{tax_value_on_ordering}, + expected => 7.03, + conf => '1 1', + field => 'tax_value' + } + ); + $order_1_1 = C4::Acquisition::populate_order_with_prices( { order => $order_1_1, @@ -253,14 +270,13 @@ for my $currency_format ( qw( US FR ) ) { }; subtest 'Configuration 1: 1 0' => sub { - plan tests => 8; + plan tests => 9; my $biblionumber_1_0 = 44; my $order_1_0 = { biblionumber => $biblionumber_1_0, quantity => 2, listprice => 82.000000, - unitprice => 70.290000, quantityreceived => 2, basketno => $basketno_1_1, invoiceid => $invoiceid_1_1, @@ -320,6 +336,23 @@ for my $currency_format ( qw( US FR ) ) { } ); + $order_1_0->{unitprice} = 70.290000; + $order_1_0 = C4::Acquisition::populate_order_with_prices( + { + order => $order_1_0, + booksellerid => 4, + ordering => 1, + } + ); + compare( + { + got => $order_1_0->{tax_value_on_ordering}, + expected => 6.69, + conf => '1 0 unitprice', + field => 'tax_value' + } + ); + $order_1_0 = C4::Acquisition::populate_order_with_prices( { order => $order_1_0, @@ -355,14 +388,13 @@ for my $currency_format ( qw( US FR ) ) { }; subtest 'Configuration 1: 0 1' => sub { - plan tests => 8; + plan tests => 9; my $biblionumber_0_1 = 45; my $order_0_1 = { biblionumber => $biblionumber_0_1, quantity => 2, listprice => 82.000000, - unitprice => 77.490000, quantityreceived => 2, basketno => $basketno_1_1, invoiceid => $invoiceid_1_1, @@ -422,6 +454,23 @@ for my $currency_format ( qw( US FR ) ) { } ); + $order_0_1->{unitprice} = 77.490000; + $order_0_1 = C4::Acquisition::populate_order_with_prices( + { + order => $order_0_1, + booksellerid => 4, + ordering => 1, + } + ); + compare( + { + got => $order_0_1->{tax_value_on_ordering}, + expected => 7.38, + conf => '0 1 unitprice', + field => 'tax_value' + } + ); + $order_0_1 = C4::Acquisition::populate_order_with_prices( { order => $order_0_1, --