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 / +34 lines)
Lines 12-18 use C4::Acquisition; Link Here
12
use Koha::Acquisition::Booksellers;
12
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Orders;
13
use Koha::Acquisition::Orders;
14
use Koha::Patrons;
14
use Koha::Patrons;
15
use Koha::Acquisition::Funds;
15
use Koha::Number::Price;
16
use Koha::Number::Price;
17
use Koha::Items;
16
18
17
use t::lib::TestBuilder;
19
use t::lib::TestBuilder;
18
20
Lines 916-926 subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { Link Here
916
    is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected");
918
    is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected");
917
};
919
};
918
920
919
subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub {
921
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
920
922
921
    plan tests => 8;
923
    plan tests => 12;
922
924
923
#Let's build an order, we need a couple things though
925
#Let's build an order, we need a couple things though
926
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
924
927
925
    my $spent_biblio = $builder->build({ source => 'Biblio' });
928
    my $spent_biblio = $builder->build({ source => 'Biblio' });
926
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
929
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
Lines 967-972 subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub { Link Here
967
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
970
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
968
    is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity");
971
    is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity");
969
972
973
#Let's test some budget planning
974
#Regression tests for bug 18736
975
    #We need an item to test by BRANCHES
976
    my $item_1 = $builder->build({ source => 'Item' });
977
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
978
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
979
    my $cell = {
980
        authcat => 'MONTHS',
981
        cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here
982
        budget_id => $spent_order->{budget_id},
983
        budget_period_id => $spent_fund->budget_period_id,
984
    };
985
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
986
    my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
987
    is ( $actual, '9.854200', "We expect this to be an exact order cost"); #really we should expect cost*quantity but we don't
988
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
989
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
990
    is ( $actual, '9.8500', "We expect this to be a rounded order cost"); #really we should expect cost*quantity but we don't
991
    $cell->{authcat} = 'BRANCHES';
992
    $cell->{authvalue} = $item_1->{homebranch};
993
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
994
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
995
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
996
    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
997
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
998
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
999
    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
1000
1001
970
#Okay, now we can receive the order, giving the price as the user would
1002
#Okay, now we can receive the order, giving the price as the user would
971
1003
972
    $spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected
1004
    $spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected
973
- 

Return to bug 18736