Revision ebcd0a69
Von Bernd Bleßmann vor etwa 6 Jahren hinzugefügt
t/db_helper/price_tax_calculator.t | ||
---|---|---|
269 | 269 |
|
270 | 270 |
my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item1, $item2, $item3); |
271 | 271 |
|
272 |
# this is how price_tax_calculator is implemented. It differs from |
|
273 |
# the way sales_order / invoice - forms are calculating: |
|
274 |
# linetotal = sellprice 5.55 * qty 1 * (1 - 0.05) = 5.2725; rounded 5.27 |
|
275 |
# linetotal = sellprice 5.50 * qty 1 * (1 - 0.05) = 5.225 rounded 5.23 |
|
276 |
# linetotal = sellprice 5.00 * qty 1 * (1 - 0.05) = 4.75; rounded 4.75 |
|
277 |
# ... |
|
278 |
|
|
279 | 272 |
# item 1: |
280 | 273 |
# discount = sellprice 5.55 * discount (0.05) = 0.2775; rounded 0.28 |
281 |
# sellprice = sellprice 5.55 - discount 0.28 = 5.27; rounded 5.27 |
|
282 |
# linetotal = sellprice 5.27 * qty 1 = 5.27; rounded 5.27 |
|
274 |
# linetotal = sellprice 5.55 * (1 - discount 0.05) * qty 1 = 5.2725; rounded 5.27 |
|
283 | 275 |
# 19%(5.27) = 1.0013; rounded = 1.00 |
284 | 276 |
# total rounded = 6.27 |
285 | 277 |
|
286 | 278 |
# lastcost 1.93 * qty 1 = 1.93; rounded 1.93 |
287 |
# line marge_total = 3.34 |
|
279 |
# line marge_total = 5.27 - 1.93 = 3.34
|
|
288 | 280 |
# line marge_percent = 63.3776091081594 |
289 | 281 |
|
290 | 282 |
# item 2: |
291 | 283 |
# discount = sellprice 5.50 * discount 0.05 = 0.275; rounded 0.28 |
292 |
# sellprice = sellprice 5.50 - discount 0.28 = 5.22; rounded 5.22 |
|
293 |
# linetotal = sellprice 5.22 * qty 1 = 5.22; rounded 5.22 |
|
294 |
# 19%(5.22) = 0.9918; rounded = 0.99 |
|
295 |
# total rounded = 6.21 |
|
284 |
# linetotal = sellprice 5.50 * (1 - discount 0.05) * qty 1 = 5.225; rounded 5.23 |
|
285 |
# 19%(5.23) = .99370; rounded = 0.99 |
|
286 |
# total rounded = 6.22 |
|
296 | 287 |
|
297 | 288 |
# lastcost 1.93 * qty 1 = 1.93; rounded 1.93 |
298 |
# line marge_total = 5.22 - 1.93 = 3.29
|
|
299 |
# line marge_percent = 3.29/5.22 = 0.630268199233716
|
|
289 |
# line marge_total = 5.23 - 1.93 = 3.30
|
|
290 |
# line marge_percent = 3.30/5.23 = 0.630975143403442
|
|
300 | 291 |
|
301 | 292 |
# item 3: |
302 |
# discount = sellprice 5.00 * discount 0.25 = 0.25; rounded 0.25 |
|
303 |
# sellprice = sellprice 5.00 - discount 0.25 = 4.75; rounded 4.75 |
|
304 |
# linetotal = sellprice 4.75 * qty 1 = 4.75; rounded 4.75 |
|
293 |
# discount = sellprice 5.00 * discount 0.05 = 0.05 = 0.25; rounded 0.25 |
|
294 |
# linetotal = sellprice 5.00 (1 - discount 0.05) * qty 1 = 4.75; rounded 4.75 |
|
305 | 295 |
# 19%(4.75) = 0.9025; rounded = 0.90 |
306 | 296 |
# total rounded = 5.65 |
307 | 297 |
|
308 | 298 |
# lastcost 1.93 * qty 1 = 1.93; rounded 1.93 |
309 |
# line marge_total = 2.82 |
|
310 |
# line marge_percent = 59.3684210526316 |
|
299 |
# line marge_total = 4.75 - 1.93 = 2.82
|
|
300 |
# line marge_percent = 2.82/4.75 = 59.3684210526316
|
|
311 | 301 |
|
312 | 302 |
my $title = 'default invoice, three items, sellprice, rounding, discount'; |
313 | 303 |
my %data = $invoice->calculate_prices_and_taxes; |
... | ... | |
316 | 306 |
is($item1->marge_percent, 63.3776091081594, "${title}: item1 marge_percent"); |
317 | 307 |
is($item1->marge_price_factor, 1, "${title}: item1 marge_price_factor"); |
318 | 308 |
|
319 |
is($item2->marge_total, 3.29, "${title}: item2 marge_total");
|
|
320 |
is($item2->marge_percent, 63.0268199233716, "${title}: item2 marge_percent");
|
|
309 |
is($item2->marge_total, 3.30, "${title}: item2 marge_total");
|
|
310 |
is($item2->marge_percent, 63.0975143403442, "${title}: item2 marge_percent");
|
|
321 | 311 |
is($item2->marge_price_factor, 1, "${title}: item2 marge_price_factor"); |
322 | 312 |
|
323 | 313 |
is($item3->marge_total, 2.82, "${title}: item3 marge_total"); |
324 | 314 |
is($item3->marge_percent, 59.3684210526316, "${title}: item3 marge_percent"); |
325 | 315 |
is($item3->marge_price_factor, 1, "${title}: item3 marge_price_factor"); |
326 | 316 |
|
327 |
is($invoice->netamount, 5.27 + 5.22 + 4.75, "${title}: netamount");
|
|
317 |
is($invoice->netamount, 5.27 + 5.23 + 4.75, "${title}: netamount");
|
|
328 | 318 |
|
329 |
# 6.27 + 6.21 + 5.65 = 18.13
|
|
330 |
# 1.19*(5.27 + 5.22 + 4.75) = 18.1356; rounded 18.14
|
|
331 |
#is($invoice->amount, 6.27 + 6.21 + 5.65, "${title}: amount");
|
|
332 |
is($invoice->amount, 18.14, "${title}: amount");
|
|
319 |
# 6.27 + 6.22 + 5.65 = 18.14
|
|
320 |
# 1.19*(5.27 + 5.23 + 4.75) = 18.1475; rounded 18.15
|
|
321 |
#is($invoice->amount, 6.27 + 6.22 + 5.65, "${title}: amount");
|
|
322 |
is($invoice->amount, 18.15, "${title}: amount");
|
|
333 | 323 |
|
334 |
is($invoice->marge_total, 3.34 + 3.29 + 2.82, "${title}: marge_total");
|
|
335 |
is($invoice->marge_percent, 62.007874015748, "${title}: marge_percent");
|
|
324 |
is($invoice->marge_total, 3.34 + 3.30 + 2.82, "${title}: marge_total");
|
|
325 |
is($invoice->marge_percent, 62.0327868852459, "${title}: marge_percent");
|
|
336 | 326 |
|
337 | 327 |
is_deeply(\%data, { |
338 | 328 |
allocated => {}, |
339 | 329 |
amounts => { |
340 | 330 |
$buchungsgruppe->income_accno_id($taxzone) => { |
341 |
amount => 15.24,
|
|
331 |
amount => 15.25,
|
|
342 | 332 |
tax_id => $tax->id, |
343 | 333 |
taxkey => 3, |
344 | 334 |
}, |
... | ... | |
358 | 348 |
tax_amount => 1.0013, |
359 | 349 |
taxkey_id => $taxkeys{$item1->parts_id}->id, |
360 | 350 |
}, |
361 |
{ linetotal => 5.22,
|
|
351 |
{ linetotal => 5.23,
|
|
362 | 352 |
linetotal_cost => 1.93, |
363 |
sellprice => 5.22,
|
|
364 |
tax_amount => 0.9918,
|
|
353 |
sellprice => 5.23,
|
|
354 |
tax_amount => 0.9937,
|
|
365 | 355 |
taxkey_id => $taxkeys{$item2->parts_id}->id, |
366 | 356 |
}, |
367 | 357 |
{ linetotal => 4.75, |
... | ... | |
386 | 376 |
|
387 | 377 |
my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item); |
388 | 378 |
|
389 |
# PTC and ar form calculate linetotal differently: |
|
390 | 379 |
# 6 parts for 0.60 with 3% discount |
391 | 380 |
# |
392 |
# ar form: |
|
393 | 381 |
# linetotal = sellprice 0.60 * qty 6 * discount (1 - 0.03) = 3.492 rounded 3.49 |
394 | 382 |
# total = 3.49 + 0.66 = 4.15 |
395 | 383 |
# |
396 |
# PTC: |
|
397 |
# discount = sellprice 0.60 * discount (0.03) = 0.018; rounded 0.02 |
|
398 |
# sellprice = sellprice 0.60 - discount 0.02 = 0.58 |
|
399 |
# linetotal = sellprice 0.58 * qty 6 = 3.48 |
|
400 |
# 19%(3.48) = 0.6612; rounded = 0.66 |
|
401 |
# total rounded = 3.48 + 0.66 = 4.14 |
|
402 | 384 |
|
403 | 385 |
my $title = 'default invoice, one item, sellprice, rounding, discount'; |
404 | 386 |
my %data = $invoice->calculate_prices_and_taxes; |
... | ... | |
435 | 417 |
taxkey_id => $taxkeys{$item->parts_id}->id, |
436 | 418 |
}, |
437 | 419 |
], |
420 |
rounding => 0, |
|
438 | 421 |
}, "${title}: calculated data"); |
439 | 422 |
} |
440 | 423 |
|
... | ... | |
449 | 432 |
|
450 | 433 |
my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item); |
451 | 434 |
|
452 |
# PTC and ar form calculate linetotal differently: |
|
453 |
# 6 parts for 0.60 with 3% discount |
|
454 |
# |
|
455 |
# ar form: |
|
456 |
# linetotal = sellprice 0.60 * qty 6 * discount (1 - 0.03) = 3.492 rounded 3.49 |
|
457 |
# total = 3.49 + 0.66 = 4.15 |
|
458 |
# |
|
459 |
# PTC: |
|
460 |
# discount = sellprice 0.60 * discount (0.03) = 0.018; rounded 0.02 |
|
461 |
# sellprice = sellprice 0.60 - discount 0.02 = 0.58 |
|
462 |
# linetotal = sellprice 0.58 * qty 6 = 3.48 |
|
463 |
# 19%(3.48) = 0.6612; rounded = 0.66 |
|
464 |
# total rounded = 3.48 + 0.66 = 4.14 |
|
465 |
|
|
466 |
my $title = 'default invoice, one item, sellprice, rounding, discount'; |
|
435 |
my $title = 'default invoice, one item, 19% tax not included, rounding, discount, huge qty'; |
|
467 | 436 |
my %data = $invoice->calculate_prices_and_taxes; |
468 | 437 |
|
469 | 438 |
is($invoice->netamount, 9700, "${title}: netamount"); |
... | ... | |
512 | 481 |
|
513 | 482 |
clear_up(); |
514 | 483 |
done_testing(); |
484 |
|
|
485 |
# vim: ft=perl |
|
486 |
# set emacs to perl mode |
|
487 |
# Local Variables: |
|
488 |
# mode: perl |
|
489 |
# End: |
Auch abrufbar als: Unified diff
PTC-Tests angepasst nach PTC-Rundungs-Patch …
"PTC rundet nicht mehr Rabatt vor Mengenmultiplikation"