View | Details | Raw Unified | Return to bug 18736
Collapse All | Expand All

(-)a/C4/Budgets.pm (-1 / +3 lines)
Lines 207-218 sub SetOwnerToFundHierarchy { Link Here
207
207
208
# -------------------------------------------------------------------
208
# -------------------------------------------------------------------
209
sub GetBudgetsPlanCell {
209
sub GetBudgetsPlanCell {
210
    my ( $cell, $period, $budget ) = @_;
210
    my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period or $budget
211
    my ($actual, $sth);
211
    my ($actual, $sth);
212
    my $dbh = C4::Context->dbh;
212
    my $dbh = C4::Context->dbh;
213
    my $roundsql = _get_rounding_sql(qq|ecost_tax_included|);
213
    my $roundsql = _get_rounding_sql(qq|ecost_tax_included|);
214
    if ( $cell->{'authcat'} eq 'MONTHS' ) {
214
    if ( $cell->{'authcat'} eq 'MONTHS' ) {
215
        # get the actual amount
215
        # get the actual amount
216
        # FIXME we should consider quantity
216
        $sth = $dbh->prepare( qq|
217
        $sth = $dbh->prepare( qq|
217
218
218
            SELECT SUM(| .  $roundsql . qq|) AS actual FROM aqorders
219
            SELECT SUM(| .  $roundsql . qq|) AS actual FROM aqorders
Lines 222-227 sub GetBudgetsPlanCell { Link Here
222
        $sth->execute( $cell->{'budget_id'} );
223
        $sth->execute( $cell->{'budget_id'} );
223
    } elsif ( $cell->{'authcat'} eq 'BRANCHES' ) {
224
    } elsif ( $cell->{'authcat'} eq 'BRANCHES' ) {
224
        # get the actual amount
225
        # get the actual amount
226
        # FIXME we should consider quantity
225
        $sth = $dbh->prepare( qq|
227
        $sth = $dbh->prepare( qq|
226
228
227
            SELECT SUM(| . $roundsql . qq|) FROM aqorders
229
            SELECT SUM(| . $roundsql . qq|) FROM aqorders
(-)a/t/db_dependent/Budgets.t (-3 / +33 lines)
Lines 14-19 use Koha::Acquisition::Orders; Link Here
14
use Koha::Acquisition::Funds;
14
use Koha::Acquisition::Funds;
15
use Koha::Patrons;
15
use Koha::Patrons;
16
use Koha::Number::Price;
16
use Koha::Number::Price;
17
use Koha::Items;
17
18
18
use t::lib::TestBuilder;
19
use t::lib::TestBuilder;
19
use Koha::DateUtils;
20
use Koha::DateUtils;
Lines 931-941 subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { Link Here
931
    is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected");
932
    is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected");
932
};
933
};
933
934
934
subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub {
935
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
935
936
936
    plan tests => 8;
937
    plan tests => 12;
937
938
938
#Let's build an order, we need a couple things though
939
#Let's build an order, we need a couple things though
940
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
939
941
940
    my $spent_biblio = $builder->build({ source => 'Biblio' });
942
    my $spent_biblio = $builder->build({ source => 'Biblio' });
941
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
943
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
Lines 982-987 subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub { Link Here
982
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
984
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
983
    is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity");
985
    is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity");
984
986
987
#Let's test some budget planning
988
#Regression tests for bug 18736
989
    #We need an item to test by BRANCHES
990
    my $item_1 = $builder->build({ source => 'Item' });
991
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
992
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
993
    my $cell = {
994
        authcat => 'MONTHS',
995
        cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here
996
        budget_id => $spent_order->{budget_id},
997
        budget_period_id => $spent_fund->budget_period_id,
998
    };
999
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
1000
    my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
1001
    is ( $actual, '9.854200', "We expect this to be an exact order cost"); #really we should expect cost*quantity but we don't
1002
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
1003
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
1004
    is ( $actual, '9.8500', "We expect this to be a rounded order cost"); #really we should expect cost*quantity but we don't
1005
    $cell->{authcat} = 'BRANCHES';
1006
    $cell->{authvalue} = $item_1->{homebranch};
1007
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
1008
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
1009
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
1010
    is ( $actual, '9.854200', "We expect this to be full cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered
1011
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
1012
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
1013
    is ( $actual, '9.8500', "We expect this to be rounded cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered
1014
1015
985
#Okay, now we can receive the order, giving the price as the user would
1016
#Okay, now we can receive the order, giving the price as the user would
986
1017
987
    $spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected
1018
    $spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected
988
- 

Return to bug 18736