|
Lines 1-6
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
use Modern::Perl; |
2 |
use Modern::Perl; |
| 3 |
use Test::More tests => 144; |
3 |
use Test::More tests => 147; |
|
|
4 |
use JSON; |
| 4 |
|
5 |
|
| 5 |
BEGIN { |
6 |
BEGIN { |
| 6 |
use_ok('C4::Budgets') |
7 |
use_ok('C4::Budgets') |
|
Lines 9-14
use C4::Context;
Link Here
|
| 9 |
use C4::Biblio; |
10 |
use C4::Biblio; |
| 10 |
use C4::Acquisition; |
11 |
use C4::Acquisition; |
| 11 |
|
12 |
|
|
|
13 |
use Koha::ActionLogs; |
| 12 |
use Koha::Acquisition::Booksellers; |
14 |
use Koha::Acquisition::Booksellers; |
| 13 |
use Koha::Acquisition::Orders; |
15 |
use Koha::Acquisition::Orders; |
| 14 |
use Koha::Acquisition::Funds; |
16 |
use Koha::Acquisition::Funds; |
|
Lines 22-27
use Koha::DateUtils;
Link Here
|
| 22 |
|
24 |
|
| 23 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
| 24 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
26 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
|
|
27 |
t::lib::Mocks::mock_preference('AcqLog','1'); |
| 25 |
|
28 |
|
| 26 |
my $schema = Koha::Database->new->schema; |
29 |
my $schema = Koha::Database->new->schema; |
| 27 |
$schema->storage->txn_begin; |
30 |
$schema->storage->txn_begin; |
|
Lines 125-134
$bpid = AddBudgetPeriod($my_budgetperiod); #this is an active budget
Link Here
|
| 125 |
my $my_budget = { |
128 |
my $my_budget = { |
| 126 |
budget_code => 'ABCD', |
129 |
budget_code => 'ABCD', |
| 127 |
budget_amount => '123.132000', |
130 |
budget_amount => '123.132000', |
|
|
131 |
budget_expend => '789', |
| 128 |
budget_name => 'Periodiques', |
132 |
budget_name => 'Periodiques', |
| 129 |
budget_notes => 'This is a note', |
133 |
budget_notes => 'This is a note', |
| 130 |
budget_period_id => $bpid, |
134 |
budget_period_id => $bpid, |
| 131 |
budget_encumb => '', # Bug 21604 |
135 |
budget_encumb => '456', # Bug 21604 |
| 132 |
}; |
136 |
}; |
| 133 |
my $budget_id = AddBudget($my_budget); |
137 |
my $budget_id = AddBudget($my_budget); |
| 134 |
isnt( $budget_id, undef, 'AddBudget does not returns undef' ); |
138 |
isnt( $budget_id, undef, 'AddBudget does not returns undef' ); |
|
Lines 139-148
is( $budget->{budget_name}, $my_budget->{budget_name}, 'AddBudget stores the bud
Link Here
|
| 139 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' ); |
143 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' ); |
| 140 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' ); |
144 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' ); |
| 141 |
|
145 |
|
|
|
146 |
my @create_logs = Koha::ActionLogs->find({ module =>'ACQUISITIONS', action => 'CREATE_FUND', object => $budget->{budget_id} }); |
| 147 |
|
| 148 |
my $expected_create_payload = { |
| 149 |
budget_amount => $my_budget->{budget_amount}, |
| 150 |
budget_expend => $my_budget->{budget_expend}, |
| 151 |
budget_encumb => $my_budget->{budget_encumb}, |
| 152 |
}; |
| 153 |
|
| 154 |
my $actual_create_payload = from_json($create_logs[0]->info); |
| 155 |
|
| 156 |
is_deeply ($actual_create_payload, $expected_create_payload, 'ModBudget logs a budget creation with the correct payload'); |
| 157 |
|
| 158 |
my $before = $budget; |
| 142 |
|
159 |
|
| 143 |
$my_budget = { |
160 |
$my_budget = { |
| 144 |
budget_code => 'EFG', |
161 |
budget_code => 'EFG', |
| 145 |
budget_amount => '321.231000', |
162 |
budget_amount => '321.231000', |
|
|
163 |
budget_encumb => '567', |
| 164 |
budget_expend => '890', |
| 146 |
budget_name => 'Modified name', |
165 |
budget_name => 'Modified name', |
| 147 |
budget_notes => 'This is a modified note', |
166 |
budget_notes => 'This is a modified note', |
| 148 |
budget_period_id => $bpid, |
167 |
budget_period_id => $bpid, |
|
Lines 160-165
is( $budget->{budget_name}, $my_budget->{budget_name}, 'ModBudget updates the bu
Link Here
|
| 160 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' ); |
179 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' ); |
| 161 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' ); |
180 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' ); |
| 162 |
|
181 |
|
|
|
182 |
my @mod_logs = Koha::ActionLogs->find({ module =>'ACQUISITIONS', action => 'MODIFY_FUND', object => $budget->{budget_id} }); |
| 183 |
my $expected_mod_payload = { |
| 184 |
budget_amount_new => $my_budget->{budget_amount}, |
| 185 |
budget_encumb_new => $my_budget->{budget_encumb}, |
| 186 |
budget_expend_new => $my_budget->{budget_expend}, |
| 187 |
budget_amount_old => $before->{budget_amount}, |
| 188 |
budget_encumb_old => $before->{budget_encumb}, |
| 189 |
budget_expend_old => $before->{budget_expend}, |
| 190 |
budget_amount_change => 0 - ($before->{budget_amount} - $my_budget->{budget_amount}) |
| 191 |
}; |
| 192 |
my $actual_mod_payload = from_json($mod_logs[0]->info); |
| 193 |
is_deeply ($actual_mod_payload, $expected_mod_payload, 'ModBudget logs a budget modification with the correct payload'); |
| 163 |
|
194 |
|
| 164 |
$budgets = GetBudgets(); |
195 |
$budgets = GetBudgets(); |
| 165 |
is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' ); |
196 |
is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' ); |
|
Lines 219-224
is( DelBudget($budget_id), 1, 'DelBudget returns true' );
Link Here
|
| 219 |
$budgets = GetBudgets(); |
250 |
$budgets = GetBudgets(); |
| 220 |
is( @$budgets, 2, 'GetBudgets returns the correct number of budget periods' ); |
251 |
is( @$budgets, 2, 'GetBudgets returns the correct number of budget periods' ); |
| 221 |
|
252 |
|
|
|
253 |
my @delete_logs = Koha::ActionLogs->find({ module =>'ACQUISITIONS', action => 'DELETE_FUND', object => $budget_id }); |
| 254 |
|
| 255 |
is (scalar @delete_logs, 1, 'DelBudget logs a budget deletion'); |
| 222 |
|
256 |
|
| 223 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
257 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
| 224 |
my $budget_period_total = 10_000; |
258 |
my $budget_period_total = 10_000; |
| 225 |
- |
|
|