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

(-)a/t/db_dependent/Budgets.t (-2 / +93 lines)
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 => 145;
4
4
5
BEGIN {
5
BEGIN {
6
    use_ok('C4::Budgets')
6
    use_ok('C4::Budgets')
Lines 12-22 use C4::Members qw( AddMember ); Link Here
12
12
13
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Booksellers;
14
use Koha::Acquisition::Orders;
14
use Koha::Acquisition::Orders;
15
use Koha::Number::Price;
15
16
16
use t::lib::TestBuilder;
17
use t::lib::TestBuilder;
17
18
18
use YAML;
19
use YAML;
19
20
21
use t::lib::Mocks;
22
t::lib::Mocks::mock_preference('OrderPriceRounding','');
23
20
my $schema  = Koha::Database->new->schema;
24
my $schema  = Koha::Database->new->schema;
21
$schema->storage->txn_begin;
25
$schema->storage->txn_begin;
22
my $builder = t::lib::TestBuilder->new;
26
my $builder = t::lib::TestBuilder->new;
Lines 470-475 ModReceiveOrder({ Link Here
470
   invoice           => $test_invoice,
474
   invoice           => $test_invoice,
471
   received_items    => [],
475
   received_items    => [],
472
} );
476
} );
477
t::lib::Mocks::mock_preference('OrderPriceRounding','');
473
478
474
is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6");
479
is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6");
475
is ( GetBudgetOrdered( $fund ), '20.000000', "total ordered price is 20");
480
is ( GetBudgetOrdered( $fund ), '20.000000', "total ordered price is 20");
Lines 798-803 is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting cat Link Here
798
803
799
# /Test GetBudgetAuthCats
804
# /Test GetBudgetAuthCats
800
805
806
subtest 'GetBudgetSpent GetBudgetOrdered tests' => sub {
807
808
    plan tests => 8;
809
810
#Let's build an order, we need a couple things though
811
812
    my $spent_biblio = $builder->build({ source => 'Biblio' });
813
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
814
    my $spent_invoice = $builder->build({ source => 'Aqinvoice'});
815
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
816
    my $spent_vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } });
817
    my $spent_orderinfo = {
818
        basketno => $spent_basket->{basketno},
819
        booksellerid => $spent_vendor->{id},
820
        rrp => 16.99,
821
        discount => .42,
822
        ecost => 16.91,
823
        biblionumber => $spent_biblio->{biblionumber},
824
        currency => $spent_currency->{currency},
825
        tax_rate_on_ordering => 0,
826
        tax_value_on_ordering => 0,
827
        tax_rate_on_receiving => 0,
828
        tax_value_on_receiving => 0,
829
        quantity => 8,
830
        quantityreceived => 0,
831
        datecancellationprinted => undef,
832
        datereceived => undef,
833
    };
834
835
#Okay we have basically what the user would enter, now we do some maths
836
837
    $spent_orderinfo = C4::Acquisition::populate_order_with_prices({
838
            order        => $spent_orderinfo,
839
            booksellerid => $spent_orderinfo->{booksellerid},
840
            ordering     => 1,
841
    });
842
843
#And let's place the order
844
845
    my $spent_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
846
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
847
    my $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
848
849
    is($spent_orderinfo->{ecost_tax_excluded}, 9.854200,'We store extra precision in price calculation');
850
    is( Koha::Number::Price->new($spent_orderinfo->{ecost_tax_excluded})->format(), 9.85,'But the price as formatted is two digits');
851
    is($spent_ordered,'78.833600',"We expect the ordered amount to be equal to the estimated price times quantity with full precision");
852
853
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
854
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
855
    is($spent_ordered,'78.80',"We expect the ordered amount to be equal to the estimated price rounded times quantity");
856
857
#Okay, now we can receive the order, giving the price as the user would
858
859
    $spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected
860
861
#Do our maths
862
863
    $spent_orderinfo = C4::Acquisition::populate_order_with_prices({
864
            order        => $spent_orderinfo,
865
            booksellerid => $spent_orderinfo->{booksellerid},
866
            receiving    => 1,
867
    });
868
    my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
869
870
#And receive
871
872
    ModReceiveOrder({
873
            biblionumber => $spent_order->{biblionumber},
874
            order => $received_order,
875
            invoice => $spent_invoice,
876
            quantityreceived => $spent_order->{quantity},
877
            budget_id => $spent_order->{budget_id},
878
            received_items => [],
879
    });
880
881
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
882
    my $spent_spent = GetBudgetSpent( $spent_order->{budget_id} );
883
    is($spent_orderinfo->{unitprice_tax_excluded}, 9.854200,'We store extra precision in price calculation');
884
    is( Koha::Number::Price->new($spent_orderinfo->{unitprice_tax_excluded})->format(), 9.85,'But the price as formatted is two digits');
885
    is($spent_spent,'78.8336',"We expect the spent amount to be equal to the estimated price times quantity with full precision");
886
887
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
888
    $spent_spent = GetBudgetSpent( $spent_order->{budget_id} );
889
    is($spent_spent,'78.8',"We expect the spent amount to be equal to the estimated price rounded times quantity");
890
891
};
892
801
sub _get_dependencies {
893
sub _get_dependencies {
802
    my ($budget_hierarchy) = @_;
894
    my ($budget_hierarchy) = @_;
803
    my $graph;
895
    my $graph;
804
- 

Return to bug 18736