Bug 31631: (QA follow-up) Tidy code
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
53e719a001
commit
ef16271ed5
3 changed files with 66 additions and 44 deletions
|
@ -52,7 +52,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
||||||
);
|
);
|
||||||
|
|
||||||
# Get correct unitprice field
|
# Get correct unitprice field
|
||||||
my ( $unitprice_field ) = C4::Budgets->FieldsForCalculatingFundValues();
|
my ($unitprice_field) = C4::Budgets->FieldsForCalculatingFundValues();
|
||||||
|
|
||||||
my $query = <<EOQ;
|
my $query = <<EOQ;
|
||||||
SELECT
|
SELECT
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bug_number => "31631",
|
bug_number => "31631",
|
||||||
description => "Add new system preference CalculateFundValuesIncludingTax",
|
description => "Add new system preference CalculateFundValuesIncludingTax",
|
||||||
up => sub {
|
up => sub {
|
||||||
my ($args) = @_;
|
my ($args) = @_;
|
||||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||||
|
|
||||||
$dbh->do(q{INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('CalculateFundValuesIncludingTax', '1', NULL, 'Include tax in the calculated fund values (spent, ordered) for all supplier configurations', 'YesNo')});
|
$dbh->do(
|
||||||
|
q{INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('CalculateFundValuesIncludingTax', '1', NULL, 'Include tax in the calculated fund values (spent, ordered) for all supplier configurations', 'YesNo')}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1219,31 +1219,49 @@ subtest 'FieldsForCalculatingFundValues with a vendor NOT including tax in their
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
# Test FieldsForCalculatingFundValues()
|
# Test FieldsForCalculatingFundValues()
|
||||||
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
|
t::lib::Mocks::mock_preference( 'CalculateFundValuesIncludingTax', '1' );
|
||||||
my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues();
|
my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues();
|
||||||
is ( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" );
|
is( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" );
|
||||||
is ( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" );
|
is( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" );
|
||||||
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
|
t::lib::Mocks::mock_preference( 'CalculateFundValuesIncludingTax', '0' );
|
||||||
( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues();
|
( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues();
|
||||||
is ( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" );
|
is( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" );
|
||||||
is ( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" );
|
is( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" );
|
||||||
|
|
||||||
# Test GetBudgetOrdered()
|
# Test GetBudgetOrdered()
|
||||||
# -----------------------
|
# -----------------------
|
||||||
|
|
||||||
# Build an order
|
# Build an order
|
||||||
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
|
t::lib::Mocks::mock_preference( 'OrderPriceRounding', 'nearest_cent' );
|
||||||
my $item_1 = $builder->build_sample_item;
|
my $item_1 = $builder->build_sample_item;
|
||||||
my $invoice = $builder->build({ source => 'Aqinvoice'});
|
my $invoice = $builder->build( { source => 'Aqinvoice' } );
|
||||||
my $currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'BOO' } });
|
my $currency = $builder->build(
|
||||||
my $vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, invoiceincgst => 0, listprice => $currency->{currency}, invoiceprice => $currency->{currency} } });
|
{
|
||||||
my $basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0, booksellerid => $vendor->{id} } });
|
source => 'Currency',
|
||||||
my $budget_period = $builder->build({ source => 'Aqbudgetperiod' });
|
value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'BOO' }
|
||||||
my $budget = $builder->build({ source => 'Aqbudget', value => {
|
|
||||||
budget_period_id => $budget_period->{budget_period_id},
|
|
||||||
budget_parent_id => undef,
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
my $vendor = $builder->build(
|
||||||
|
{
|
||||||
|
source => 'Aqbookseller',
|
||||||
|
value => {
|
||||||
|
listincgst => 0, invoiceincgst => 0, listprice => $currency->{currency},
|
||||||
|
invoiceprice => $currency->{currency}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
my $basket =
|
||||||
|
$builder->build( { source => 'Aqbasket', value => { is_standing => 0, booksellerid => $vendor->{id} } } );
|
||||||
|
my $budget_period = $builder->build( { source => 'Aqbudgetperiod' } );
|
||||||
|
my $budget = $builder->build(
|
||||||
|
{
|
||||||
|
source => 'Aqbudget',
|
||||||
|
value => {
|
||||||
|
budget_period_id => $budget_period->{budget_period_id},
|
||||||
|
budget_parent_id => undef,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
my $orderdata = {
|
my $orderdata = {
|
||||||
basketno => $basket->{basketno},
|
basketno => $basket->{basketno},
|
||||||
booksellerid => $vendor->{id},
|
booksellerid => $vendor->{id},
|
||||||
|
@ -1269,49 +1287,51 @@ subtest 'FieldsForCalculatingFundValues with a vendor NOT including tax in their
|
||||||
$orderdata = $order->unblessed();
|
$orderdata = $order->unblessed();
|
||||||
|
|
||||||
# Place the order
|
# Place the order
|
||||||
$order = $builder->build({ source => 'Aqorder', value => $orderdata });
|
$order = $builder->build( { source => 'Aqorder', value => $orderdata } );
|
||||||
|
|
||||||
# Check order values with different CalculateFundValuesIncludingTax options
|
# Check order values with different CalculateFundValuesIncludingTax options
|
||||||
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
|
t::lib::Mocks::mock_preference( 'CalculateFundValuesIncludingTax', '0' );
|
||||||
my $budget_ordered = GetBudgetOrdered( $order->{budget_id} );
|
my $budget_ordered = GetBudgetOrdered( $order->{budget_id} );
|
||||||
is ( $budget_ordered, 10, "We expect this to be the tax exclusive value" );
|
is( $budget_ordered, 10, "We expect this to be the tax exclusive value" );
|
||||||
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
|
t::lib::Mocks::mock_preference( 'CalculateFundValuesIncludingTax', '1' );
|
||||||
$budget_ordered = GetBudgetOrdered( $order->{budget_id} );
|
$budget_ordered = GetBudgetOrdered( $order->{budget_id} );
|
||||||
is ( $budget_ordered, 11.5, "We expect this to be the tax inclusive value" );
|
is( $budget_ordered, 11.5, "We expect this to be the tax inclusive value" );
|
||||||
|
|
||||||
# Test GetBudgetSpent() and GetBudgetHierarchy()
|
# Test GetBudgetSpent() and GetBudgetHierarchy()
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
|
|
||||||
# Receive the order
|
# Receive the order
|
||||||
$orderdata->{unitprice} = 10; #we are paying what we expected
|
$orderdata->{unitprice} = 10; #we are paying what we expected
|
||||||
|
|
||||||
# Do some maths
|
# Do some maths
|
||||||
$order = Koha::Acquisition::Order->new($orderdata);
|
$order = Koha::Acquisition::Order->new($orderdata);
|
||||||
$order->populate_with_prices_for_receiving();
|
$order->populate_with_prices_for_receiving();
|
||||||
$orderdata = $order->unblessed();
|
$orderdata = $order->unblessed();
|
||||||
my $received_order = $builder->build({ source => 'Aqorder', value => $orderdata });
|
my $received_order = $builder->build( { source => 'Aqorder', value => $orderdata } );
|
||||||
|
|
||||||
# Receive a copy of the order
|
# Receive a copy of the order
|
||||||
ModReceiveOrder({
|
ModReceiveOrder(
|
||||||
biblionumber => $orderdata->{biblionumber},
|
{
|
||||||
order => $received_order,
|
biblionumber => $orderdata->{biblionumber},
|
||||||
invoice => $invoice,
|
order => $received_order,
|
||||||
|
invoice => $invoice,
|
||||||
quantityreceived => 1,
|
quantityreceived => 1,
|
||||||
budget_id => $orderdata->{budget_id},
|
budget_id => $orderdata->{budget_id},
|
||||||
received_items => [],
|
received_items => [],
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
|
t::lib::Mocks::mock_preference( 'CalculateFundValuesIncludingTax', '0' );
|
||||||
my $spent_amount = GetBudgetSpent( $orderdata->{budget_id} );
|
my $spent_amount = GetBudgetSpent( $orderdata->{budget_id} );
|
||||||
is ( $spent_amount, 10, "We expect this to be the tax exclusive value" );
|
is( $spent_amount, 10, "We expect this to be the tax exclusive value" );
|
||||||
my $gbh = GetBudgetHierarchy($budget->{budget_period_id});
|
my $gbh = GetBudgetHierarchy( $budget->{budget_period_id} );
|
||||||
is ( @$gbh[0]->{budget_spent}, 10, "We expect this value to be the tax exclusive value");
|
is( @$gbh[0]->{budget_spent}, 10, "We expect this value to be the tax exclusive value" );
|
||||||
|
|
||||||
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
|
t::lib::Mocks::mock_preference( 'CalculateFundValuesIncludingTax', '1' );
|
||||||
$spent_amount = GetBudgetSpent( $orderdata->{budget_id} );
|
$spent_amount = GetBudgetSpent( $orderdata->{budget_id} );
|
||||||
is ( $spent_amount, 11.5, "We expect this to be the tax inclusive value" );
|
is( $spent_amount, 11.5, "We expect this to be the tax inclusive value" );
|
||||||
$gbh = GetBudgetHierarchy($budget->{budget_period_id});
|
$gbh = GetBudgetHierarchy( $budget->{budget_period_id} );
|
||||||
is ( @$gbh[0]->{budget_spent}, 11.5, "We expect this value to be the tax inclusive value");
|
is( @$gbh[0]->{budget_spent}, 11.5, "We expect this value to be the tax inclusive value" );
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue