Revision 99bc77bc
Von Kivitendo Admin vor mehr als 8 Jahren hinzugefügt
t/db_helper/price_tax_calculator.t | ||
---|---|---|
76 | 76 |
unit => $unit->name, |
77 | 77 |
%{ $params{part2} } |
78 | 78 |
)->save; |
79 |
|
|
80 |
push @parts, SL::DB::Part->new( |
|
81 |
partnumber => 'T888', |
|
82 |
description => 'Triple 8', |
|
83 |
lastcost => 0, |
|
84 |
sellprice => 0.6, |
|
85 |
buchungsgruppen_id => $buchungsgruppe->id, |
|
86 |
unit => $unit->name, |
|
87 |
%{ $params{part3} } |
|
88 |
)->save; |
|
89 |
|
|
79 | 90 |
} |
80 | 91 |
|
81 | 92 |
sub new_invoice { |
... | ... | |
374 | 385 |
}, "${title}: calculated data"); |
375 | 386 |
} |
376 | 387 |
|
388 |
sub test_default_invoice_one_item_19_tax_not_included_rounding_discount() { |
|
389 |
reset_state(); |
|
390 |
|
|
391 |
my $item = new_item(qty => 6, part => $parts[2], discount => 0.03); |
|
392 |
my $invoice = new_invoice( |
|
393 |
taxincluded => 0, |
|
394 |
invoiceitems => [ $item ], |
|
395 |
); |
|
396 |
|
|
397 |
my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item); |
|
398 |
|
|
399 |
# PTC and ar form calculate linetotal differently: |
|
400 |
# 6 parts for 0.60 with 3% discount |
|
401 |
# |
|
402 |
# ar form: |
|
403 |
# linetotal = sellprice 0.60 * qty 6 * discount (1 - 0.03) = 3.492 rounded 3.49 |
|
404 |
# total = 3.49 + 0.66 = 4.15 |
|
405 |
# |
|
406 |
# PTC: |
|
407 |
# discount = sellprice 0.60 * discount (0.03) = 0.018; rounded 0.02 |
|
408 |
# sellprice = sellprice 0.60 - discount 0.02 = 0.58 |
|
409 |
# linetotal = sellprice 0.58 * qty 6 = 3.48 |
|
410 |
# 19%(3.48) = 0.6612; rounded = 0.66 |
|
411 |
# total rounded = 3.48 + 0.66 = 4.14 |
|
412 |
|
|
413 |
my $title = 'default invoice, one item, sellprice, rounding, discount'; |
|
414 |
my %data = $invoice->calculate_prices_and_taxes; |
|
415 |
|
|
416 |
is($invoice->netamount, 3.48, "${title}: netamount"); |
|
417 |
|
|
418 |
is($invoice->amount, 4.14, "${title}: amount"); |
|
419 |
|
|
420 |
is($invoice->marge_total, 3.48, "${title}: marge_total"); |
|
421 |
is($invoice->marge_percent, 100, "${title}: marge_percent"); |
|
422 |
|
|
423 |
is_deeply(\%data, { |
|
424 |
allocated => {}, |
|
425 |
amounts => { |
|
426 |
$buchungsgruppe->income_accno_id($taxzone) => { |
|
427 |
amount => 3.48, |
|
428 |
tax_id => $tax->id, |
|
429 |
taxkey => 3, |
|
430 |
}, |
|
431 |
}, |
|
432 |
amounts_cogs => {}, |
|
433 |
assembly_items => [ |
|
434 |
[], |
|
435 |
], |
|
436 |
exchangerate => 1, |
|
437 |
taxes => { |
|
438 |
$tax->chart_id => 0.66, |
|
439 |
}, |
|
440 |
items => [ |
|
441 |
{ linetotal => 3.48, |
|
442 |
linetotal_cost => 0, |
|
443 |
sellprice => 0.58, |
|
444 |
tax_amount => 0.6612, |
|
445 |
taxkey_id => $taxkeys{$item->parts_id}->id, |
|
446 |
}, |
|
447 |
], |
|
448 |
}, "${title}: calculated data"); |
|
449 |
} |
|
450 |
|
|
377 | 451 |
Support::TestSetup::login(); |
378 | 452 |
|
379 | 453 |
test_default_invoice_one_item_19_tax_not_included(); |
380 | 454 |
test_default_invoice_two_items_19_7_tax_not_included(); |
381 | 455 |
test_default_invoice_three_items_sellprice_rounding_discount(); |
456 |
test_default_invoice_one_item_19_tax_not_included_rounding_discount(); |
|
382 | 457 |
|
383 | 458 |
clear_up(); |
384 | 459 |
done_testing(); |
Auch abrufbar als: Unified diff
Neuer Minimaltestfall für Rabattrundung im PTC
Beim PTC wird vor der Multiplizierung mit der Menge der gerundete Rabatt vom
Verkaufspreis abgezogen, statt erst die Zeilensumme zu berechnen und
dann den Rabatt zu ziehen.
6 Artikel zu 0.6€ mit 3% Rabatt
0.6 * 6 * ( 1 - 0.03 ) != ( 0.6 - round(0.6*0.03) ) * 6
In diesem Test wird anhand der PTC-Regel getestet. Es wird also nicht
angemahnt, daß das Ergebnis von der Berechnung in den Belegmasken abweicht.
Siehe auch Ticket 82.