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

(-)a/C4/Budgets.pm (-1 / +1 lines)
Lines 206-212 sub SetOwnerToFundHierarchy { Link Here
206
206
207
# -------------------------------------------------------------------
207
# -------------------------------------------------------------------
208
sub GetBudgetsPlanCell {
208
sub GetBudgetsPlanCell {
209
    my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period or $budget
209
    my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period
210
    my ($actual, $sth);
210
    my ($actual, $sth);
211
    my $dbh = C4::Context->dbh;
211
    my $dbh = C4::Context->dbh;
212
    my $roundsql = _get_rounding_sql(qq|ecost_tax_included|);
212
    my $roundsql = _get_rounding_sql(qq|ecost_tax_included|);
(-)a/t/db_dependent/Budgets.t (-36 / +71 lines)
Lines 807-838 is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting cat Link Here
807
807
808
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
808
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
809
809
810
    plan tests => 12;
810
    plan tests => 16;
811
811
812
#Let's build an order, we need a couple things though
812
#Let's build an order, we need a couple things though
813
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
813
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
814
814
815
    my $spent_biblio = $builder->build({ source => 'Biblio' });
815
    my $spent_biblio   = $builder->build({ source => 'Biblio' });
816
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
816
    my $item_1         = $builder->build({ source => 'Item', value => { biblionumber => $spent_biblio->{biblionumber} } });
817
    my $spent_invoice = $builder->build({ source => 'Aqinvoice'});
817
    my $biblioitem_1   = $builder->build({ source => 'Biblioitem', value => { biblionumber => $spent_biblio->{biblionumber}, itemnumber => $item_1->{itemnumber} } });
818
    my $spent_basket   = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
819
    my $spent_invoice  = $builder->build({ source => 'Aqinvoice'});
818
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
820
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
819
    my $spent_vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } });
821
    my $spent_vendor   = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } });
822
    my $budget_authcat = $builder->build({ source => 'AuthorisedValueCategory', value => {} });
823
    my $spent_sort1    = $builder->build({ source => 'AuthorisedValue', value => {
824
            category => $budget_authcat->{category_name},
825
            authorised_value => 'PICKLE',
826
        }
827
    });
828
    my $spent_budget = $builder->build({ source => 'Aqbudget', value => {
829
            sort1_authcat => $budget_authcat->{category_name},
830
        }
831
    });
820
    my $spent_orderinfo = {
832
    my $spent_orderinfo = {
821
        basketno => $spent_basket->{basketno},
833
        basketno                => $spent_basket->{basketno},
822
        booksellerid => $spent_vendor->{id},
834
        booksellerid            => $spent_vendor->{id},
823
        rrp => 16.99,
835
        rrp                     => 16.99,
824
        discount => .42,
836
        discount                => .42,
825
        ecost => 16.91,
837
        ecost                   => 16.91,
826
        biblionumber => $spent_biblio->{biblionumber},
838
        biblionumber            => $spent_biblio->{biblionumber},
827
        currency => $spent_currency->{currency},
839
        currency                => $spent_currency->{currency},
828
        tax_rate_on_ordering => 0,
840
        tax_rate_on_ordering    => 0,
829
        tax_value_on_ordering => 0,
841
        tax_value_on_ordering   => 0,
830
        tax_rate_on_receiving => 0,
842
        tax_rate_on_receiving   => 0,
831
        tax_value_on_receiving => 0,
843
        tax_value_on_receiving  => 0,
832
        quantity => 8,
844
        quantity                => 8,
833
        quantityreceived => 0,
845
        quantityreceived        => 0,
834
        datecancellationprinted => undef,
846
        datecancellationprinted => undef,
835
        datereceived => undef,
847
        datereceived            => undef,
848
        budget_id               => $spent_budget->{budget_id},
849
        sort1                   => $spent_sort1->{authorised_value},
836
    };
850
    };
837
851
838
#Okay we have basically what the user would enter, now we do some maths
852
#Okay we have basically what the user would enter, now we do some maths
Lines 860-866 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
860
#Let's test some budget planning
874
#Let's test some budget planning
861
#Regression tests for bug 18736
875
#Regression tests for bug 18736
862
    #We need an item to test by BRANCHES
876
    #We need an item to test by BRANCHES
863
    my $item_1 = $builder->build({ source => 'Item' });
864
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
877
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
865
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
878
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
866
    my $cell = {
879
    my $cell = {
Lines 868-890 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
868
        cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here
881
        cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here
869
        budget_id => $spent_order->{budget_id},
882
        budget_id => $spent_order->{budget_id},
870
        budget_period_id => $spent_fund->budget_period_id,
883
        budget_period_id => $spent_fund->budget_period_id,
884
        sort1_authcat => $spent_order->{sort1_authcat},
885
        sort2_authcat => $spent_order->{sort1_authcat},
886
    };
887
    my $test_values = {
888
        'MONTHS' => {
889
            authvalue => $spent_order->{entrydate},
890
            expected_rounded => 9.85,
891
            expected_exact   => 9.8542,
892
        },
893
        'BRANCHES' => {
894
            authvalue => $item_1->{homebranch},
895
            expected_rounded => 9.85,
896
            expected_exact   => 9.8542,
897
        },
898
        'ITEMTYPES' => {
899
            authvalue => $biblioitem_1->{itemtype},
900
            expected_rounded => 78.80,
901
            expected_exact   => 78.8336,
902
        },
903
        'ELSE' => {
904
            authvalue => $spent_sort1->{authorised_value},
905
            expected_rounded => 78.8,
906
            expected_exact   => 78.8336,
907
        },
871
    };
908
    };
872
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
873
    my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
874
    is ( $actual, '9.854200', "We expect this to be an exact order cost"); #really we should expect cost*quantity but we don't
875
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
876
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
877
    is ( $actual, '9.8500', "We expect this to be a rounded order cost"); #really we should expect cost*quantity but we don't
878
    $cell->{authcat} = 'BRANCHES';
879
    $cell->{authvalue} = $item_1->{homebranch};
880
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
881
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
882
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
883
    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
884
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
885
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
886
    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
887
909
910
    for my $authcat ( keys %$test_values ) {
911
        my $test_val         = $test_values->{$authcat};
912
        my $authvalue        = $test_val->{authvalue};
913
        my $expected_rounded = $test_val->{expected_rounded};
914
        my $expected_exact   = $test_val->{expected_exact};
915
        $cell->{authcat} = $authcat;
916
        $cell->{authvalue} = $authvalue;
917
        t::lib::Mocks::mock_preference('OrderPriceRounding','');
918
        my ( $actual ) = GetBudgetsPlanCell( $cell, undef, $spent_budget); #we are only testing the actual for now
919
        is ( $actual+0, $expected_exact, "We expect this to be an exact order cost ($authcat)"); #really we should expect cost*quantity but we don't
920
        t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
921
        ( $actual ) = GetBudgetsPlanCell( $cell, undef, $spent_budget); #we are only testing the actual for now
922
        is ( $actual+0, $expected_rounded, "We expect this to be a rounded order cost ($authcat)"); #really we should expect cost*quantity but we don't
923
    }
888
924
889
#Okay, now we can receive the order, giving the price as the user would
925
#Okay, now we can receive the order, giving the price as the user would
890
926
891
- 

Return to bug 18736