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

(-)a/C4/Acquisition.pm (-6 / +16 lines)
Lines 3053-3062 sub populate_order_with_prices { Link Here
3053
    if ($ordering) {
3053
    if ($ordering) {
3054
        $order->{tax_rate_on_ordering} //= $order->{tax_rate};
3054
        $order->{tax_rate_on_ordering} //= $order->{tax_rate};
3055
        if ( $bookseller->listincgst ) {
3055
        if ( $bookseller->listincgst ) {
3056
            # The user entered the rrp tax included
3056
3057
            # The user entered the prices tax included
3058
            $order->{unitprice_tax_included} = $order->{unitprice};
3057
            $order->{rrp_tax_included} = $order->{rrp};
3059
            $order->{rrp_tax_included} = $order->{rrp};
3058
3060
3059
            # rrp tax excluded = rrp tax included / ( 1 + tax rate )
3061
            # price tax excluded = price tax included / ( 1 + tax rate )
3062
            $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
3060
            $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
3063
            $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
3061
3064
3062
            # ecost tax included = rrp tax included  ( 1 - discount )
3065
            # ecost tax included = rrp tax included  ( 1 - discount )
Lines 3066-3079 sub populate_order_with_prices { Link Here
3066
            $order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
3069
            $order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
3067
3070
3068
            # tax value = quantity * ecost tax excluded * tax rate
3071
            # tax value = quantity * ecost tax excluded * tax rate
3069
            $order->{tax_value_on_ordering} = ( get_rounded_price($order->{ecost_tax_included}) - get_rounded_price($order->{ecost_tax_excluded}) ) * $order->{quantity};
3072
            # we should use the unitprice if included
3073
            my $cost_tax_included = $order->{unitprice_tax_included} || $order->{ecost_tax_included};
3074
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded};
3075
            $order->{tax_value_on_ordering} = ( get_rounded_price($cost_tax_included) - get_rounded_price($cost_tax_excluded) ) * $order->{quantity};
3070
3076
3071
        }
3077
        }
3072
        else {
3078
        else {
3073
            # The user entered the rrp tax excluded
3079
            # The user entered the prices tax excluded
3080
            $order->{unitprice_tax_excluded} = $order->{unitprice};
3074
            $order->{rrp_tax_excluded} = $order->{rrp};
3081
            $order->{rrp_tax_excluded} = $order->{rrp};
3075
3082
3076
            # rrp tax included = rrp tax excluded * ( 1 - tax rate )
3083
            # price tax included = price tax excluded * ( 1 - tax rate )
3084
            $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3077
            $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3085
            $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3078
3086
3079
            # ecost tax excluded = rrp tax excluded * ( 1 - discount )
3087
            # ecost tax excluded = rrp tax excluded * ( 1 - discount )
Lines 3083-3089 sub populate_order_with_prices { Link Here
3083
            $order->{ecost_tax_included} = $order->{ecost_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3091
            $order->{ecost_tax_included} = $order->{ecost_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3084
3092
3085
            # tax value = quantity * ecost tax included * tax rate
3093
            # tax value = quantity * ecost tax included * tax rate
3086
            $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($order->{ecost_tax_excluded}) * $order->{tax_rate_on_ordering};
3094
            # we should use the unitprice if included
3095
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded};
3096
            $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($cost_tax_excluded) * $order->{tax_rate_on_ordering};
3087
        }
3097
        }
3088
    }
3098
    }
3089
3099
(-)a/t/db_dependent/Acquisition/populate_order_with_prices.t (-8 / +39 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 34;
5
use Test::More tests => 44;
6
use C4::Acquisition;
6
use C4::Acquisition;
7
use C4::Context;
7
use C4::Context;
8
use Koha::Database;
8
use Koha::Database;
Lines 44-50 my $order_exc_tax = { Link Here
44
    tax_rate  => .1965,
44
    tax_rate  => .1965,
45
    discount  => .42,
45
    discount  => .42,
46
    rrp       => 16.99,
46
    rrp       => 16.99,
47
    unitprice => 9.85,
47
    unitprice => 0.00,
48
    quantity  => 8,
48
    quantity  => 8,
49
};
49
};
50
50
Lines 60-66 is( $order_with_prices->{rrp_tax_excluded}+0 ,16.99 ,"Ordering tax exc Link Here
60
is( $order_with_prices->{rrp_tax_included}+0      ,20.328535  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
60
is( $order_with_prices->{rrp_tax_included}+0      ,20.328535  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
61
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.8542     ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
61
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.8542     ,"Ordering tax excluded, no round: ecost tax excluded is rrp * ( 1 - discount )");
62
is( $order_with_prices->{ecost_tax_included}+0    ,11.7905503 ,"Ordering tax excluded, no round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
62
is( $order_with_prices->{ecost_tax_included}+0    ,11.7905503 ,"Ordering tax excluded, no round: ecost tax included is ecost tax excluded * (1 + tax rate on ordering)");
63
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4908024 ,"Ordering tax excluded, no round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering");
63
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4908024 ,"Ordering tax excluded, no round: tax value on ordering is quantity * ecost_tax_excluded * tax rate on ordering if no unitprice");
64
65
$order_exc_tax->{unitprice} = 9.85;
66
67
$order_with_prices = C4::Acquisition::populate_order_with_prices({
68
    ordering     => 1,
69
    booksellerid => $bookseller_exc_tax->id,
70
    order        => $order_exc_tax,
71
});
72
73
is( $order_with_prices->{unitprice_tax_excluded}+0      ,9.85      ,"Ordering tax excluded, no round: rrp tax excluded is rrp");
74
is( $order_with_prices->{unitprice_tax_included}+0      ,11.785525  ,"Ordering tax excluded, no round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
75
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4842 ,"Ordering tax excluded, no round: tax value on ordering is quantity * unitprice_tax_excluded * tax rate on ordering if unitprice");
64
76
65
#Vendor prices exclude tax, no rounding, receiving
77
#Vendor prices exclude tax, no rounding, receiving
66
$order_with_prices = C4::Acquisition::populate_order_with_prices({
78
$order_with_prices = C4::Acquisition::populate_order_with_prices({
Lines 72-78 $order_with_prices = C4::Acquisition::populate_order_with_prices({ Link Here
72
is( $order_with_prices->{unitprice}+0              ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
84
is( $order_with_prices->{unitprice}+0              ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
73
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
85
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.8542     ,"Receiving tax excluded, no round, rounded ecost tax excluded = rounded unitprice : unitprice tax excluded is ecost tax excluded");
74
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7905503 ,"Receiving tax excluded, no round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
86
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7905503 ,"Receiving tax excluded, no round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
75
is( $order_with_prices->{tax_value_on_ordering}+0  ,15.4908024 ,"Receiving tax excluded, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
87
is( $order_with_prices->{tax_value_on_receiving}+0  ,15.4908024 ,"Receiving tax excluded, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
88
89
90
$order_exc_tax->{unitprice} = 9.85;
91
#populate order with prices updates the passed in order hashref
92
#we need to reset after additional tests and changes
76
93
77
#Vendor prices exclude tax, rounding to nearest cent, ordering
94
#Vendor prices exclude tax, rounding to nearest cent, ordering
78
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
95
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
Lines 82-87 $order_with_prices = C4::Acquisition::populate_order_with_prices({ Link Here
82
    order        => $order_exc_tax,
99
    order        => $order_exc_tax,
83
});
100
});
84
101
102
is( $order_with_prices->{unitprice_tax_excluded}+0      ,9.85      ,"Ordering tax excluded, round: unitprice tax excluded is unitprice");
103
is( $order_with_prices->{unitprice_tax_included}+0      ,11.785525  ,"Ordering tax excluded, round: unitprice tax included is unitprice tax excluded * (1 + tax rate on ordering)");
85
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.99      ,"Ordering tax excluded, round: rrp tax excluded is rrp");
104
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.99      ,"Ordering tax excluded, round: rrp tax excluded is rrp");
86
is( $order_with_prices->{rrp_tax_included}+0      ,20.328535  ,"Ordering tax excluded, round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
105
is( $order_with_prices->{rrp_tax_included}+0      ,20.328535  ,"Ordering tax excluded, round: rrp tax included is rr tax excluded * (1 + tax rate on ordering)");
87
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.8542     ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
106
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.8542     ,"Ordering tax excluded, round: ecost tax excluded is rrp * ( 1 - discount )");
Lines 105-111 my $order_inc_tax = { Link Here
105
    tax_rate  => .1965,
124
    tax_rate  => .1965,
106
    discount  => .42,
125
    discount  => .42,
107
    rrp       => 20.33,
126
    rrp       => 20.33,
108
    unitprice => 11.79,
127
    unitprice => 0.00,
109
    quantity  => 8,
128
    quantity  => 8,
110
};
129
};
111
130
Lines 121-128 is( $order_with_prices->{rrp_tax_included}+0 ,20.33 ,"Ordering t Link Here
121
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.9912244045132 ,"Ordering tax included, no round: rrp tax excluded is rrp tax included / (1 + tax rate on ordering)");
140
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.9912244045132 ,"Ordering tax included, no round: rrp tax excluded is rrp tax included / (1 + tax rate on ordering)");
122
is( $order_with_prices->{ecost_tax_included}+0    ,11.7914          ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
141
is( $order_with_prices->{ecost_tax_included}+0    ,11.7914          ,"Ordering tax included, no round: ecost tax included is rrp tax included * (1 - discount)");
123
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
142
is( $order_with_prices->{ecost_tax_excluded}+0    ,9.85491015461764 ,"Ordering tax included, no round: ecost tax excluded is rrp tax excluded * ( 1 - discount )");
124
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4919187630589 ,"Ordering tax included, no round: tax value on ordering is ( ecost tax included - ecost tax excluded ) * quantity");
143
is( $order_with_prices->{tax_value_on_ordering}+0 ,15.4919187630589 ,"Ordering tax included, no round: tax value on ordering is ( ecost tax included - ecost tax excluded ) * quantity if no unitprice");
144
145
$order_inc_tax->{unitprice} = 11.79;
146
$order_with_prices = C4::Acquisition::populate_order_with_prices({
147
    ordering     => 1,
148
    booksellerid => $bookseller_inc_tax->id,
149
    order        => $order_inc_tax,
150
});
125
151
152
is( $order_with_prices->{unitprice_tax_included}+0 ,11.79             ,"Ordering tax included, no round: unitprice tax included is unitprice");
153
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.85374007521939  ,"Ordering tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
154
is( $order_with_prices->{tax_value_on_ordering}+0  ,15.4900793982449  ,"Ordering tax included, no round: tax value on ordering is ( unitprice tax included - unitprice tax excluded ) * quantity if unitprice");
126
155
127
#Vendor prices include tax, no rounding, receiving
156
#Vendor prices include tax, no rounding, receiving
128
$order_with_prices = C4::Acquisition::populate_order_with_prices({
157
$order_with_prices = C4::Acquisition::populate_order_with_prices({
Lines 134-149 $order_with_prices = C4::Acquisition::populate_order_with_prices({ Link Here
134
is( $order_with_prices->{unitprice}+0              ,11.7914          ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
163
is( $order_with_prices->{unitprice}+0              ,11.7914          ,"Receiving tax included, no round, rounded ecost tax excluded = rounded unitprice : unitprice is ecost tax excluded");
135
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7914          ,"Receiving tax included, no round: unitprice tax included is unitprice");
164
is( $order_with_prices->{unitprice_tax_included}+0 ,11.7914          ,"Receiving tax included, no round: unitprice tax included is unitprice");
136
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.85491015461764 ,"Receiving tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax rate on receiving)");
165
is( $order_with_prices->{unitprice_tax_excluded}+0 ,9.85491015461764 ,"Receiving tax included, no round: unitprice tax excluded is unitprice tax included / (1 + tax rate on receiving)");
137
is( $order_with_prices->{tax_value_on_ordering}+0  ,15.4919187630589 ,"Receiving tax included, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
166
is( $order_with_prices->{tax_value_on_receiving}+0 ,15.4919187630589 ,"Receiving tax included, no round: tax value on receiving is quantity * unitprice_tax_excluded * tax rate on receiving");
138
167
139
#Vendor prices include tax, rounding to nearest cent, ordering
168
#Vendor prices include tax, rounding to nearest cent, ordering
140
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
169
t::lib::Mocks::mock_preference('OrderPriceRounding', 'nearest_cent');
170
$order_inc_tax->{unitprice} = 11.79;
141
$order_with_prices = C4::Acquisition::populate_order_with_prices({
171
$order_with_prices = C4::Acquisition::populate_order_with_prices({
142
    ordering     => 1,
172
    ordering     => 1,
143
    booksellerid => $bookseller_inc_tax->id,
173
    booksellerid => $bookseller_inc_tax->id,
144
    order        => $order_inc_tax,
174
    order        => $order_inc_tax,
145
});
175
});
146
176
177
is( $order_with_prices->{unitprice_tax_included}+0      ,11.79      ,"Ordering tax included, round: unitprice tax included is unitprice");
178
is( $order_with_prices->{unitprice_tax_excluded}+0,9.85374007521939 ,"Ordering tax included, round: unitprice tax excluded is unitprice tax included / (1 + tax_rate_on_ordering ");
147
is( $order_with_prices->{rrp_tax_included}+0      ,20.33            ,"Ordering tax included, round: rrp tax included is rrp");
179
is( $order_with_prices->{rrp_tax_included}+0      ,20.33            ,"Ordering tax included, round: rrp tax included is rrp");
148
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.9912244045132 ,"Ordering tax included, round: rrp tax excluded is rounded rrp tax included * (1 + tax rate on ordering)");
180
is( $order_with_prices->{rrp_tax_excluded}+0      ,16.9912244045132 ,"Ordering tax included, round: rrp tax excluded is rounded rrp tax included * (1 + tax rate on ordering)");
149
is( $order_with_prices->{ecost_tax_included}+0    ,11.7914          ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
181
is( $order_with_prices->{ecost_tax_included}+0    ,11.7914          ,"Ordering tax included, round: ecost tax included is rounded rrp * ( 1 - discount )");
150
- 

Return to bug 23523