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

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

Return to bug 18736