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 24-29
use YAML;
Link Here
|
24 |
|
26 |
|
25 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
26 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
28 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
|
|
29 |
t::lib::Mocks::mock_preference('AcqLog','1'); |
27 |
|
30 |
|
28 |
my $schema = Koha::Database->new->schema; |
31 |
my $schema = Koha::Database->new->schema; |
29 |
$schema->storage->txn_begin; |
32 |
$schema->storage->txn_begin; |
Lines 127-136
$bpid = AddBudgetPeriod($my_budgetperiod); #this is an active budget
Link Here
|
127 |
my $my_budget = { |
130 |
my $my_budget = { |
128 |
budget_code => 'ABCD', |
131 |
budget_code => 'ABCD', |
129 |
budget_amount => '123.132000', |
132 |
budget_amount => '123.132000', |
|
|
133 |
budget_expend => '789', |
130 |
budget_name => 'Periodiques', |
134 |
budget_name => 'Periodiques', |
131 |
budget_notes => 'This is a note', |
135 |
budget_notes => 'This is a note', |
132 |
budget_period_id => $bpid, |
136 |
budget_period_id => $bpid, |
133 |
budget_encumb => '', # Bug 21604 |
137 |
budget_encumb => '456', # Bug 21604 |
134 |
}; |
138 |
}; |
135 |
my $budget_id = AddBudget($my_budget); |
139 |
my $budget_id = AddBudget($my_budget); |
136 |
isnt( $budget_id, undef, 'AddBudget does not returns undef' ); |
140 |
isnt( $budget_id, undef, 'AddBudget does not returns undef' ); |
Lines 141-150
is( $budget->{budget_name}, $my_budget->{budget_name}, 'AddBudget stores the bud
Link Here
|
141 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' ); |
145 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' ); |
142 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' ); |
146 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' ); |
143 |
|
147 |
|
|
|
148 |
my @create_logs = Koha::ActionLogs->find({ module =>'ACQUISITIONS', action => 'CREATE_FUND', object => $budget->{budget_id} }); |
149 |
|
150 |
my $expected_create_payload = { |
151 |
budget_amount => $my_budget->{budget_amount}, |
152 |
budget_expend => $my_budget->{budget_expend}, |
153 |
budget_encumb => $my_budget->{budget_encumb}, |
154 |
}; |
155 |
|
156 |
my $actual_create_payload = from_json($create_logs[0]->info); |
157 |
|
158 |
is_deeply ($actual_create_payload, $expected_create_payload, 'ModBudget logs a budget creation with the correct payload'); |
159 |
|
160 |
my $before = $budget; |
144 |
|
161 |
|
145 |
$my_budget = { |
162 |
$my_budget = { |
146 |
budget_code => 'EFG', |
163 |
budget_code => 'EFG', |
147 |
budget_amount => '321.231000', |
164 |
budget_amount => '321.231000', |
|
|
165 |
budget_encumb => '567', |
166 |
budget_expend => '890', |
148 |
budget_name => 'Modified name', |
167 |
budget_name => 'Modified name', |
149 |
budget_notes => 'This is a modified note', |
168 |
budget_notes => 'This is a modified note', |
150 |
budget_period_id => $bpid, |
169 |
budget_period_id => $bpid, |
Lines 162-167
is( $budget->{budget_name}, $my_budget->{budget_name}, 'ModBudget updates the bu
Link Here
|
162 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' ); |
181 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' ); |
163 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' ); |
182 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' ); |
164 |
|
183 |
|
|
|
184 |
my @mod_logs = Koha::ActionLogs->find({ module =>'ACQUISITIONS', action => 'MODIFY_FUND', object => $budget->{budget_id} }); |
185 |
my $expected_mod_payload = { |
186 |
budget_amount_new => $my_budget->{budget_amount}, |
187 |
budget_encumb_new => $my_budget->{budget_encumb}, |
188 |
budget_expend_new => $my_budget->{budget_expend}, |
189 |
budget_amount_old => $before->{budget_amount}, |
190 |
budget_encumb_old => $before->{budget_encumb}, |
191 |
budget_expend_old => $before->{budget_expend}, |
192 |
budget_amount_change => 0 - ($before->{budget_amount} - $my_budget->{budget_amount}) |
193 |
}; |
194 |
my $actual_mod_payload = from_json($mod_logs[0]->info); |
195 |
is_deeply ($actual_mod_payload, $expected_mod_payload, 'ModBudget logs a budget modification with the correct payload'); |
165 |
|
196 |
|
166 |
$budgets = GetBudgets(); |
197 |
$budgets = GetBudgets(); |
167 |
is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' ); |
198 |
is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' ); |
Lines 221-226
is( DelBudget($budget_id), 1, 'DelBudget returns true' );
Link Here
|
221 |
$budgets = GetBudgets(); |
252 |
$budgets = GetBudgets(); |
222 |
is( @$budgets, 2, 'GetBudgets returns the correct number of budget periods' ); |
253 |
is( @$budgets, 2, 'GetBudgets returns the correct number of budget periods' ); |
223 |
|
254 |
|
|
|
255 |
my @delete_logs = Koha::ActionLogs->find({ module =>'ACQUISITIONS', action => 'DELETE_FUND', object => $budget_id }); |
256 |
|
257 |
is (scalar @delete_logs, 1, 'DelBudget logs a budget deletion'); |
224 |
|
258 |
|
225 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
259 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
226 |
my $budget_period_total = 10_000; |
260 |
my $budget_period_total = 10_000; |
227 |
- |
|
|