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

(-)a/C4/Acquisition.pm (-5 / +13 lines)
Lines 3070-3076 sub populate_order_with_prices { Link Here
3070
            $order->{rrp_tax_included} = $order->{rrp};
3070
            $order->{rrp_tax_included} = $order->{rrp};
3071
3071
3072
            # price tax excluded = price tax included / ( 1 + tax rate )
3072
            # price tax excluded = price tax included / ( 1 + tax rate )
3073
            $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
3073
            $order->{unitprice_tax_excluded} =
3074
              defined( $order->{unitprice_tax_included} )
3075
              ? $order->{unitprice_tax_included} /
3076
              ( 1 + $order->{tax_rate_on_ordering} )
3077
              : undef;
3074
            $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
3078
            $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
3075
3079
3076
            # ecost tax included = rrp tax included  ( 1 - discount )
3080
            # ecost tax included = rrp tax included  ( 1 - discount )
Lines 3081-3088 sub populate_order_with_prices { Link Here
3081
3085
3082
            # tax value = quantity * ecost tax excluded * tax rate
3086
            # tax value = quantity * ecost tax excluded * tax rate
3083
            # we should use the unitprice if included
3087
            # we should use the unitprice if included
3084
            my $cost_tax_included = $order->{unitprice_tax_included} || $order->{ecost_tax_included};
3088
            my $cost_tax_included = $order->{unitprice_tax_included} // $order->{ecost_tax_included};
3085
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded};
3089
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} // $order->{ecost_tax_excluded};
3086
            $order->{tax_value_on_ordering} = ( get_rounded_price($cost_tax_included) - get_rounded_price($cost_tax_excluded) ) * $order->{quantity};
3090
            $order->{tax_value_on_ordering} = ( get_rounded_price($cost_tax_included) - get_rounded_price($cost_tax_excluded) ) * $order->{quantity};
3087
3091
3088
        }
3092
        }
Lines 3092-3098 sub populate_order_with_prices { Link Here
3092
            $order->{rrp_tax_excluded} = $order->{rrp};
3096
            $order->{rrp_tax_excluded} = $order->{rrp};
3093
3097
3094
            # price tax included = price tax excluded * ( 1 - tax rate )
3098
            # price tax included = price tax excluded * ( 1 - tax rate )
3095
            $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3099
            $order->{unitprice_tax_included} =
3100
              defined( $order->{unitprice_tax_excluded} )
3101
              ? $order->{unitprice_tax_excluded} *
3102
              ( 1 + $order->{tax_rate_on_ordering} )
3103
              : undef;
3096
            $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3104
            $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
3097
3105
3098
            # ecost tax excluded = rrp tax excluded * ( 1 - discount )
3106
            # ecost tax excluded = rrp tax excluded * ( 1 - discount )
Lines 3103-3109 sub populate_order_with_prices { Link Here
3103
3111
3104
            # tax value = quantity * ecost tax included * tax rate
3112
            # tax value = quantity * ecost tax included * tax rate
3105
            # we should use the unitprice if included
3113
            # we should use the unitprice if included
3106
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} || $order->{ecost_tax_excluded};
3114
            my $cost_tax_excluded = $order->{unitprice_tax_excluded} // $order->{ecost_tax_excluded};
3107
            $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($cost_tax_excluded) * $order->{tax_rate_on_ordering};
3115
            $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($cost_tax_excluded) * $order->{tax_rate_on_ordering};
3108
        }
3116
        }
3109
    }
3117
    }
(-)a/t/Prices.t (-7 / +55 lines)
Lines 67-72 for my $currency_format ( qw( US FR ) ) { Link Here
67
            discount         => 10.0000,
67
            discount         => 10.0000,
68
            datereceived     => $today
68
            datereceived     => $today
69
        };
69
        };
70
70
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
71
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
71
            {
72
            {
72
                order        => $order_0_0,
73
                order        => $order_0_0,
Lines 151-164 for my $currency_format ( qw( US FR ) ) { Link Here
151
    };
152
    };
152
153
153
    subtest 'Configuration 1: 1 1' => sub {
154
    subtest 'Configuration 1: 1 1' => sub {
154
        plan tests => 8;
155
        plan tests => 9;
155
156
156
        my $biblionumber_1_1 = 43;
157
        my $biblionumber_1_1 = 43;
157
        my $order_1_1        = {
158
        my $order_1_1        = {
158
            biblionumber     => $biblionumber_1_1,
159
            biblionumber     => $biblionumber_1_1,
159
            quantity         => 2,
160
            quantity         => 2,
160
            listprice        => 82.000000,
161
            listprice        => 82.000000,
161
            unitprice        => 73.800000,
162
            quantityreceived => 2,
162
            quantityreceived => 2,
163
            basketno         => $basketno_1_1,
163
            basketno         => $basketno_1_1,
164
            invoiceid        => $invoiceid_1_1,
164
            invoiceid        => $invoiceid_1_1,
Lines 218-223 for my $currency_format ( qw( US FR ) ) { Link Here
218
            }
218
            }
219
        );
219
        );
220
220
221
        $order_1_1->{unitprice} = 73.800000;
222
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
223
            {
224
                order        => $order_1_1,
225
                booksellerid => 4,
226
                ordering     => 1,
227
            }
228
        );
229
        compare(
230
            {
231
                got      => $order_1_1->{tax_value_on_ordering},
232
                expected => 7.03,
233
                conf     => '1 1',
234
                field    => 'tax_value'
235
            }
236
        );
237
221
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
238
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
222
            {
239
            {
223
                order        => $order_1_1,
240
                order        => $order_1_1,
Lines 253-266 for my $currency_format ( qw( US FR ) ) { Link Here
253
    };
270
    };
254
271
255
    subtest 'Configuration 1: 1 0' => sub {
272
    subtest 'Configuration 1: 1 0' => sub {
256
        plan tests => 8;
273
        plan tests => 9;
257
274
258
        my $biblionumber_1_0 = 44;
275
        my $biblionumber_1_0 = 44;
259
        my $order_1_0        = {
276
        my $order_1_0        = {
260
            biblionumber     => $biblionumber_1_0,
277
            biblionumber     => $biblionumber_1_0,
261
            quantity         => 2,
278
            quantity         => 2,
262
            listprice        => 82.000000,
279
            listprice        => 82.000000,
263
            unitprice        => 70.290000,
264
            quantityreceived => 2,
280
            quantityreceived => 2,
265
            basketno         => $basketno_1_1,
281
            basketno         => $basketno_1_1,
266
            invoiceid        => $invoiceid_1_1,
282
            invoiceid        => $invoiceid_1_1,
Lines 320-325 for my $currency_format ( qw( US FR ) ) { Link Here
320
            }
336
            }
321
        );
337
        );
322
338
339
        $order_1_0->{unitprice} = 70.290000;
340
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
341
            {
342
                order        => $order_1_0,
343
                booksellerid => 4,
344
                ordering     => 1,
345
            }
346
        );
347
        compare(
348
            {
349
                got      => $order_1_0->{tax_value_on_ordering},
350
                expected => 6.69,
351
                conf     => '1 0 unitprice',
352
                field    => 'tax_value'
353
            }
354
        );
355
323
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
356
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
324
            {
357
            {
325
                order        => $order_1_0,
358
                order        => $order_1_0,
Lines 355-368 for my $currency_format ( qw( US FR ) ) { Link Here
355
    };
388
    };
356
389
357
    subtest 'Configuration 1: 0 1' => sub {
390
    subtest 'Configuration 1: 0 1' => sub {
358
        plan tests => 8;
391
        plan tests => 9;
359
392
360
        my $biblionumber_0_1 = 45;
393
        my $biblionumber_0_1 = 45;
361
        my $order_0_1        = {
394
        my $order_0_1        = {
362
            biblionumber     => $biblionumber_0_1,
395
            biblionumber     => $biblionumber_0_1,
363
            quantity         => 2,
396
            quantity         => 2,
364
            listprice        => 82.000000,
397
            listprice        => 82.000000,
365
            unitprice        => 77.490000,
366
            quantityreceived => 2,
398
            quantityreceived => 2,
367
            basketno         => $basketno_1_1,
399
            basketno         => $basketno_1_1,
368
            invoiceid        => $invoiceid_1_1,
400
            invoiceid        => $invoiceid_1_1,
Lines 422-427 for my $currency_format ( qw( US FR ) ) { Link Here
422
            }
454
            }
423
        );
455
        );
424
456
457
        $order_0_1->{unitprice} = 77.490000;
458
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
459
            {
460
                order        => $order_0_1,
461
                booksellerid => 4,
462
                ordering     => 1,
463
            }
464
        );
465
        compare(
466
            {
467
                got      => $order_0_1->{tax_value_on_ordering},
468
                expected => 7.38,
469
                conf     => '0 1 unitprice',
470
                field    => 'tax_value'
471
            }
472
        );
473
425
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
474
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
426
            {
475
            {
427
                order        => $order_0_1,
476
                order        => $order_0_1,
428
- 

Return to bug 23523