Bug 12976: Use the centralize VAT and prices calculation - invoice.pl
Bug 12969 introduces a subroutine to centralize VAT and prices calculation. It should be use in the acqui/invoice.pl script. Test plan: 0/ Don't apply the patch 1/ Create 4 suppliers with the different configurations 2/ Create a basket and create several orders 3/ Receive the items and create an invoice 4/ Go on the invoice page acqui/invoice.pl?invoiceid=XXX 5/ Verify you don't see any difference before and after applying the patch on the invoice details table. Note: The only different you should see is the price formating for "Total tax exc.". Before this patch "432.10" was displayed "432.1". Signed-off-by: Paola Rossi <paola.rossi@cineca.it> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
6b12857de2
commit
4318eeef5f
|
|
@ -2870,23 +2870,26 @@ sub populate_order_with_prices {
|
|||
}
|
||||
}
|
||||
|
||||
# Not used yet
|
||||
#if ($receiving) {
|
||||
# if ( $bookseller->{invoiceincgst} ) {
|
||||
# $order->{unitpricegsti} = $order->{unitprice};
|
||||
# $order->{unitpricegste} =
|
||||
# $order->{unitpricegsti} / ( 1 + $order->{gstrate} );
|
||||
# }
|
||||
# else {
|
||||
# $order->{unitpricegste} = $order->{unitprice};
|
||||
# $order->{unitpricegsti} =
|
||||
# $order->{unitpricegste} * ( 1 + $order->{gstrate} );
|
||||
# }
|
||||
# $order->{gstvalue} =
|
||||
# $order->{quantityreceived} *
|
||||
# $order->{unitpricegste} *
|
||||
# $order->{gstrate};
|
||||
#}
|
||||
if ($receiving) {
|
||||
# The following is completely wrong. Will be fixed later.
|
||||
# See the unit tests to know what is wrong.
|
||||
if ( $bookseller->{listincgst} ) {
|
||||
$order->{unitpricegsti} = Koha::Number::Price->new( $order->{unitprice} )->round;
|
||||
$order->{unitpricegste} = Koha::Number::Price->new(
|
||||
$order->{unitpricegsti} / ( 1 + $order->{gstrate} ) )->round;
|
||||
}
|
||||
else {
|
||||
$order->{unitpricegste} = Koha::Number::Price->new( $order->{unitprice} )->round;
|
||||
$order->{unitpricegsti} = Koha::Number::Price->new(
|
||||
$order->{unitpricegste} * ( 1 + $order->{gstrate} ) )->round;
|
||||
}
|
||||
$order->{gstvalue} = Koha::Number::Price->new(
|
||||
( $order->{unitpricegsti} - $order->{unitpricegste} )
|
||||
* $order->{quantityreceived} )->round;
|
||||
|
||||
$order->{totalgste} = $order->{unitpricegste} * $order->{quantity};
|
||||
$order->{totalgsti} = $order->{unitpricegsti} * $order->{quantity};
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,9 +121,16 @@ my $total_gste = 0;
|
|||
my $total_gsti = 0;
|
||||
my $total_gstvalue = 0;
|
||||
foreach my $order (@$orders) {
|
||||
$order = C4::Acquisition::populate_order_with_prices(
|
||||
{
|
||||
order => $order,
|
||||
booksellerid => $bookseller->{id},
|
||||
receiving => 1,
|
||||
}
|
||||
);
|
||||
my $line = get_infos( $order, $bookseller);
|
||||
|
||||
$foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti};
|
||||
$foot{$$line{gstgsti}}{gstrate} = $$line{gstrate};
|
||||
$foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue};
|
||||
$total_gstvalue += $$line{gstvalue};
|
||||
$foot{$$line{gstgsti}}{quantity} += $$line{quantity};
|
||||
|
|
@ -193,23 +200,6 @@ sub get_infos {
|
|||
my %line = %{ $order };
|
||||
$line{order_received} = ( $qty == $order->{'quantityreceived'} );
|
||||
$line{budget_name} = $budget->{budget_name};
|
||||
if ( $bookseller->{'listincgst'} ) {
|
||||
$line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
|
||||
$line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) );
|
||||
$line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} );
|
||||
$line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) );
|
||||
$line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
|
||||
$line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
|
||||
$line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
|
||||
} else {
|
||||
$line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
|
||||
$line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 );
|
||||
$line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) );
|
||||
$line{actualcostgste} = sprintf( "%.2f", $line{unitprice} );
|
||||
$line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
|
||||
$line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
|
||||
$line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
|
||||
}
|
||||
|
||||
if ( $line{uncertainprice} ) {
|
||||
$template->param( uncertainprices => 1 );
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[% USE Koha %]
|
||||
[% USE KohaDates %]
|
||||
[% USE Price %]
|
||||
|
||||
[% INCLUDE 'doc-head-open.inc' %]
|
||||
<title>Koha › Acquisitions › Invoice</title>
|
||||
|
|
@ -160,13 +161,13 @@
|
|||
[% END %]
|
||||
</td>
|
||||
<td><p>[% order.branchcode %]</p></td>
|
||||
<td class="number gste">[% order.actualcostgste %]</td>
|
||||
<td class="number gsti">[% order.actualcostgsti %]</td>
|
||||
<td class="number gste">[% order.unitpricegste | $Price %]</td>
|
||||
<td class="number gsti">[% order.unitpricegsti | $Price %]</td>
|
||||
<td class="number">[% order.quantity %]</td>
|
||||
<td class="number gste">[% order.totalgste %]</td>
|
||||
<td class="number gsti">[% order.totalgsti %]</td>
|
||||
<td class="number">[% order.gstgsti %]</td>
|
||||
<td class="number">[% order.gstvalue %]</td>
|
||||
<td class="number gste">[% order.totalgste | $Price %]</td>
|
||||
<td class="number gsti">[% order.totalgsti | $Price %]</td>
|
||||
<td class="number">[% order.gstrate * 100 | $Price %]</td>
|
||||
<td class="number">[% order.gstvalue | $Price %]</td>
|
||||
<td>[% order.budget_name %]</td>
|
||||
</tr>
|
||||
[% END %]
|
||||
|
|
@ -174,13 +175,13 @@
|
|||
<tfoot>
|
||||
[% FOR tf IN foot_loop %]
|
||||
<tr>
|
||||
<th colspan='2'>Total (GST [% tf.gstgsti %] %)</th>
|
||||
<th colspan='2'>Total (GST [% tf.gstrate * 100 | $Price %] %)</th>
|
||||
<th class="gste"/><th class="gsti"/>
|
||||
<th>[% tf.quantity %]</th>
|
||||
<th class="gste">[% tf.totalgste %]</th>
|
||||
<th class="gsti">[% tf.totalgsti %]</th>
|
||||
<th class="gste">[% tf.totalgste | $Price %]</th>
|
||||
<th class="gsti">[% tf.totalgsti | $Price %]</th>
|
||||
<th> </th>
|
||||
<th>[% tf.gstvalue %]</th>
|
||||
<th>[% tf.gstvalue | $Price %]</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
[% END %]
|
||||
|
|
@ -188,10 +189,10 @@
|
|||
<th colspan='2'>Total ([% currency %])</th>
|
||||
<th class="gste"/><th class="gsti"/>
|
||||
<th>[% total_quantity %]</th>
|
||||
<th class="gste">[% total_gste %]</th>
|
||||
<th class="gsti">[% total_gsti %]</th>
|
||||
<th class="gste">[% total_gste | $Price %]</th>
|
||||
<th class="gsti">[% total_gsti | $Price %]</th>
|
||||
<th> </th>
|
||||
<th>[% total_gstvalue %]</th>
|
||||
<th>[% total_gstvalue | $Price %]</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
@ -199,10 +200,10 @@
|
|||
<th class="gste"></th>
|
||||
<th class="gsti"></th>
|
||||
<th>[% total_quantity %]</th>
|
||||
<th class="gste">[% total_gste_shipment %]</th>
|
||||
<th class="gsti">[% total_gsti_shipment %]</th>
|
||||
<th class="gste">[% total_gste_shipment | $Price %]</th>
|
||||
<th class="gsti">[% total_gsti_shipment | $Price %]</th>
|
||||
<th> </th>
|
||||
<th>[% total_gstvalue %]</th>
|
||||
<th>[% total_gstvalue | $Price %]</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
|
|
|||
210
t/Prices.t
210
t/Prices.t
|
|
@ -23,7 +23,7 @@ my $today;
|
|||
for my $currency_format ( qw( US FR ) ) {
|
||||
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
|
||||
subtest 'Configuration 1: 0 0' => sub {
|
||||
plan tests => 7;
|
||||
plan tests => 12;
|
||||
$bookseller_module->mock(
|
||||
'fetch',
|
||||
sub {
|
||||
|
|
@ -112,10 +112,61 @@ for my $currency_format ( qw( US FR ) ) {
|
|||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
|
||||
$order_0_0 = C4::Acquisition::populate_order_with_prices(
|
||||
{
|
||||
order => $order_0_0,
|
||||
booksellerid => 'just_something',
|
||||
receiving => 1,
|
||||
}
|
||||
);
|
||||
# Note that this configuration is *not* correct!
|
||||
# unitpricegsti should be 75.28
|
||||
# totalgst should be 150.56
|
||||
compare(
|
||||
{
|
||||
got => $order_0_0->{unitpricegsti},
|
||||
expected => 77.49,
|
||||
conf => '0 0',
|
||||
field => 'unitpricegsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_0->{unitpricegste},
|
||||
expected => 73.80,
|
||||
conf => '0 0',
|
||||
field => 'unitpricegste'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_0->{gstvalue},
|
||||
expected => 7.38,
|
||||
conf => '0 0',
|
||||
field => 'gstvalue'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_0->{totalgsti},
|
||||
expected => 154.98,
|
||||
conf => '0 0',
|
||||
field => 'totalgsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_0->{totalgste},
|
||||
expected => 147.60,
|
||||
conf => '0 0',
|
||||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
subtest 'Configuration 1: 1 1' => sub {
|
||||
plan tests => 7;
|
||||
plan tests => 12;
|
||||
$bookseller_module->mock(
|
||||
'fetch',
|
||||
sub {
|
||||
|
|
@ -205,10 +256,60 @@ for my $currency_format ( qw( US FR ) ) {
|
|||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
|
||||
$order_1_1 = C4::Acquisition::populate_order_with_prices(
|
||||
{
|
||||
order => $order_1_1,
|
||||
booksellerid => 'just_something',
|
||||
receiving => 1,
|
||||
}
|
||||
);
|
||||
# Note that this configuration is *not* correct!
|
||||
# gstvalue should be 7.03
|
||||
compare(
|
||||
{
|
||||
got => $order_1_1->{unitpricegsti},
|
||||
expected => 73.80,
|
||||
conf => '1 1',
|
||||
field => 'unitpricegsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_1->{unitpricegste},
|
||||
expected => 70.29,
|
||||
conf => '1 1',
|
||||
field => 'unitpricegste'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_1->{gstvalue},
|
||||
expected => 7.02,
|
||||
conf => '1 1',
|
||||
field => 'gstvalue'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_1->{totalgsti},
|
||||
expected => 147.60,
|
||||
conf => '1 1',
|
||||
field => 'totalgsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_1->{totalgste},
|
||||
expected => 140.58,
|
||||
conf => '1 1',
|
||||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
subtest 'Configuration 1: 1 0' => sub {
|
||||
plan tests => 7;
|
||||
plan tests => 12;
|
||||
$bookseller_module->mock(
|
||||
'fetch',
|
||||
sub {
|
||||
|
|
@ -300,10 +401,62 @@ for my $currency_format ( qw( US FR ) ) {
|
|||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
|
||||
$order_1_0 = C4::Acquisition::populate_order_with_prices(
|
||||
{
|
||||
order => $order_1_0,
|
||||
booksellerid => 'just_something',
|
||||
receiving => 1,
|
||||
}
|
||||
);
|
||||
# Note that this configuration is *not* correct!
|
||||
# unitpricegsti should be 71.69
|
||||
# totalgsti should be 143.38
|
||||
# gstvalue should be 7.03
|
||||
compare(
|
||||
{
|
||||
got => $order_1_0->{unitpricegsti},
|
||||
expected => 73.80,
|
||||
conf => '1 0',
|
||||
field => 'unitpricegsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_0->{unitpricegste},
|
||||
expected => 70.29,
|
||||
conf => '1 0',
|
||||
field => 'unitpricegste'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_0->{gstvalue},
|
||||
expected => 7.02,
|
||||
conf => '1 0',
|
||||
field => 'gstvalue'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_0->{totalgsti},
|
||||
expected => 147.60,
|
||||
conf => '1 0',
|
||||
field => 'totalgsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_1_0->{totalgste},
|
||||
expected => 140.58,
|
||||
conf => '1 0',
|
||||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
subtest 'Configuration 1: 0 1' => sub {
|
||||
plan tests => 7;
|
||||
plan tests => 12;
|
||||
$bookseller_module->mock(
|
||||
'fetch',
|
||||
sub {
|
||||
|
|
@ -392,6 +545,55 @@ for my $currency_format ( qw( US FR ) ) {
|
|||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
|
||||
$order_0_1 = C4::Acquisition::populate_order_with_prices(
|
||||
{
|
||||
order => $order_0_1,
|
||||
booksellerid => 'just_something',
|
||||
receiving => 1,
|
||||
}
|
||||
);
|
||||
# Note that this configuration is correct
|
||||
compare(
|
||||
{
|
||||
got => $order_0_1->{unitpricegsti},
|
||||
expected => 77.49,
|
||||
conf => '0 1',
|
||||
field => 'unitpricegsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_1->{unitpricegste},
|
||||
expected => 73.80,
|
||||
conf => '0 1',
|
||||
field => 'unitpricegste'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_1->{gstvalue},
|
||||
expected => 7.38,
|
||||
conf => '0 1',
|
||||
field => 'gstvalue'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_1->{totalgsti},
|
||||
expected => 154.98,
|
||||
conf => '0 1',
|
||||
field => 'totalgsti'
|
||||
}
|
||||
);
|
||||
compare(
|
||||
{
|
||||
got => $order_0_1->{totalgste},
|
||||
expected => 147.60,
|
||||
conf => '0 1',
|
||||
field => 'totalgste'
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue