Bug 28157: Regression tests
[srvgit] / t / Prices.t
old mode 100644 (file)
new mode 100755 (executable)
index b82e17d..5c2c861
@@ -18,7 +18,7 @@ use_ok('C4::Acquisition');
 use_ok('C4::Context');
 use_ok('Koha::Number::Price');
 
-t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
+t::lib::Mocks::mock_preference( 'TaxRates', '0.02|0.05|0.196' );
 
 use Test::DBIx::Class;
 
@@ -42,8 +42,8 @@ fixtures_ok [
 
 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
 
-my ( $basketno_0_0,  $basketno_1_1,  $basketno_1_0,  $basketno_0_1 );
-my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
+my ( $basketno_0_0,  $basketno_1_1 );
+my ( $invoiceid_0_0, $invoiceid_1_1 );
 my $today;
 
 for my $currency_format ( qw( US FR ) ) {
@@ -56,15 +56,15 @@ for my $currency_format ( qw( US FR ) ) {
         my $order_0_0 = {
             biblionumber     => $biblionumber_0_0,
             quantity         => 2,
-            listprice        => 82.000000,
-            unitprice        => 73.80000,
+            listprice        => 82,
+            unitprice        => 73.80,
             quantityreceived => 2,
             basketno         => $basketno_0_0,
             invoiceid        => $invoiceid_0_0,
             rrp              => 82.00,
             ecost            => 73.80,
             tax_rate         => 0.0500,
-            discount         => 10.0000,
+            discount         => 10,
             datereceived     => $today
         };
         $order_0_0 = C4::Acquisition::populate_order_with_prices(
@@ -151,21 +151,21 @@ for my $currency_format ( qw( US FR ) ) {
     };
 
     subtest 'Configuration 1: 1 1 (Vendor List prices do include tax / Invoice prices include tax)' => sub {
-        plan tests => 8;
+        plan tests => 11;
 
         my $biblionumber_1_1 = 43;
         my $order_1_1        = {
             biblionumber     => $biblionumber_1_1,
             quantity         => 2,
-            listprice        => 82.000000,
-            unitprice        => 73.800000,
+            listprice        => 82,
+            unitprice        => 73.80,
             quantityreceived => 2,
             basketno         => $basketno_1_1,
             invoiceid        => $invoiceid_1_1,
             rrp              => 82.00,
             ecost            => 73.80,
             tax_rate         => 0.0500,
-            discount         => 10.0000,
+            discount         => 10,
             datereceived     => $today
         };
 
@@ -250,6 +250,55 @@ for my $currency_format ( qw( US FR ) ) {
                 field    => 'tax_value'
             }
         );
+
+        # When unitprice is 0.00 C4::Acquisition->populate_order_with_prices() falls back to using ecost_tax_included and ecost_tax_excluded
+        $order_1_1        = {
+            biblionumber     => $biblionumber_1_1,
+            quantity         => 1,
+            listprice        => 10,
+            unitprice        => '0.00',
+            quantityreceived => 1,
+            basketno         => $basketno_1_1,
+            invoiceid        => $invoiceid_1_1,
+            rrp              => 10.00,
+            ecost            => 10.00,
+            tax_rate         => 0.1500,
+            discount         => 0,
+            datereceived     => $today
+        };
+
+        $order_1_1 = C4::Acquisition::populate_order_with_prices(
+            {
+                order        => $order_1_1,
+                booksellerid => 4,
+                ordering     => 1,
+            }
+        );
+
+        compare(
+            {
+                got      => $order_1_1->{ecost_tax_included},
+                expected => 10.00,
+                conf     => '1 1',
+                field    => 'ecost_tax_included'
+            }
+        );
+        compare(
+            {
+                got      => $order_1_1->{ecost_tax_excluded},
+                expected => 8.70,
+                conf     => '1 1',
+                field    => 'ecost_tax_excluded'
+            }
+        );
+        compare(
+            {
+                got      => $order_1_1->{tax_value_on_ordering},
+                expected => 1.30,
+                conf     => '1 1',
+                field    => 'tax_value'
+            }
+        );
     };
 
     subtest 'Configuration 1: 1 0 (Vendor List prices include tax / Invoice prices do not include tax)' => sub {
@@ -259,7 +308,7 @@ for my $currency_format ( qw( US FR ) ) {
         my $order_1_0        = {
             biblionumber     => $biblionumber_1_0,
             quantity         => 2,
-            listprice        => 82.000000,
+            listprice        => 82,
             unitprice        => 0,
             quantityreceived => 2,
             basketno         => $basketno_1_1,
@@ -267,7 +316,7 @@ for my $currency_format ( qw( US FR ) ) {
             rrp              => 82.00,
             ecost            => 73.80,
             tax_rate         => 0.0500,
-            discount         => 10.0000,
+            discount         => 10,
             datereceived     => $today
         };
 
@@ -380,7 +429,7 @@ for my $currency_format ( qw( US FR ) ) {
         my $order_0_1        = {
             biblionumber     => $biblionumber_0_1,
             quantity         => 2,
-            listprice        => 82.000000,
+            listprice        => 82,
             unitprice        => 0,
             quantityreceived => 2,
             basketno         => $basketno_1_1,
@@ -388,7 +437,7 @@ for my $currency_format ( qw( US FR ) ) {
             rrp              => 82.00,
             ecost            => 73.80,
             tax_rate         => 0.0500,
-            discount         => 10.0000,
+            discount         => 10,
             datereceived     => $today
         };
 
@@ -492,6 +541,7 @@ for my $currency_format ( qw( US FR ) ) {
             }
         );
     };
+
 }
 
 sub compare {