X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fdb_helper%2Fprice_tax_calculator.t;h=22f4165dd00c60e3757d78d67d6a71aaea0afe30;hb=965a8ee142a6cd21c3056eacaa01a01818032c3e;hp=f7aa9ab0ae92b3a611c73a0faaf310a10310a23a;hpb=1d34002dbf0a3ee90237f4373229a45ed890cd7f;p=kivitendo-erp.git diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index f7aa9ab0a..22f4165dd 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -14,22 +14,30 @@ use Test::Exception; use SL::DB::Buchungsgruppe; use SL::DB::Currency; use SL::DB::Customer; +use SL::DB::DeliveryOrder; use SL::DB::Employee; use SL::DB::Invoice; +use SL::DB::Order; use SL::DB::Part; use SL::DB::Unit; use SL::DB::TaxZone; my ($customer, $currency_id, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $taxzone); +sub clear_up { + SL::DB::Manager::Order->delete_all(all => 1); + SL::DB::Manager::DeliveryOrder->delete_all(all => 1); + SL::DB::Manager::Invoice->delete_all(all => 1); + SL::DB::Manager::Part->delete_all(all => 1); + SL::DB::Manager::Customer->delete_all(all => 1); +}; + sub reset_state { my %params = @_; $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax); - SL::DB::Manager::Invoice->delete_all(all => 1); - SL::DB::Manager::Part->delete_all(all => 1); - SL::DB::Manager::Customer->delete_all(all => 1); + clear_up(); $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group"; $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%') || croak "No accounting group for 7\%"; @@ -54,6 +62,7 @@ sub reset_state { description => 'Fourty-two fifty-four', lastcost => 1.93, sellprice => 2.34, + part_type => 'part', buchungsgruppen_id => $buchungsgruppe->id, unit => $unit->name, %{ $params{part1} } @@ -64,10 +73,23 @@ sub reset_state { description => 'Zero EIGHT fifteeN @ 7%', lastcost => 5.473, sellprice => 9.714, + part_type => 'part', buchungsgruppen_id => $buchungsgruppe7->id, unit => $unit->name, %{ $params{part2} } )->save; + + push @parts, SL::DB::Part->new( + partnumber => 'T888', + description => 'Triple 8', + lastcost => 0, + sellprice => 0.6, + part_type => 'part', + buchungsgruppen_id => $buchungsgruppe->id, + unit => $unit->name, + %{ $params{part3} } + )->save; + } sub new_invoice { @@ -158,6 +180,7 @@ sub test_default_invoice_one_item_19_tax_not_included() { taxkey_id => $taxkey->id, }, ], + rounding => 0, }, "${title}: calculated data"); } @@ -245,6 +268,7 @@ sub test_default_invoice_two_items_19_7_tax_not_included() { taxkey_id => $taxkey2->id, }, ], + rounding => 0, }, "${title}: calculated data"); } @@ -363,6 +387,71 @@ sub test_default_invoice_three_items_sellprice_rounding_discount() { taxkey_id => $taxkeys{$item3->parts_id}->id, } ], + rounding => 0, + }, "${title}: calculated data"); +} + +sub test_default_invoice_one_item_19_tax_not_included_rounding_discount() { + reset_state(); + + my $item = new_item(qty => 6, part => $parts[2], discount => 0.03); + my $invoice = new_invoice( + taxincluded => 0, + invoiceitems => [ $item ], + ); + + my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item); + + # PTC and ar form calculate linetotal differently: + # 6 parts for 0.60 with 3% discount + # + # ar form: + # linetotal = sellprice 0.60 * qty 6 * discount (1 - 0.03) = 3.492 rounded 3.49 + # total = 3.49 + 0.66 = 4.15 + # + # PTC: + # discount = sellprice 0.60 * discount (0.03) = 0.018; rounded 0.02 + # sellprice = sellprice 0.60 - discount 0.02 = 0.58 + # linetotal = sellprice 0.58 * qty 6 = 3.48 + # 19%(3.48) = 0.6612; rounded = 0.66 + # total rounded = 3.48 + 0.66 = 4.14 + + my $title = 'default invoice, one item, sellprice, rounding, discount'; + my %data = $invoice->calculate_prices_and_taxes; + + is($invoice->netamount, 3.48, "${title}: netamount"); + + is($invoice->amount, 4.14, "${title}: amount"); + + is($invoice->marge_total, 3.48, "${title}: marge_total"); + is($invoice->marge_percent, 100, "${title}: marge_percent"); + + is_deeply(\%data, { + allocated => {}, + amounts => { + $buchungsgruppe->income_accno_id($taxzone) => { + amount => 3.48, + tax_id => $tax->id, + taxkey => 3, + }, + }, + amounts_cogs => {}, + assembly_items => [ + [], + ], + exchangerate => 1, + taxes => { + $tax->chart_id => 0.66, + }, + items => [ + { linetotal => 3.48, + linetotal_cost => 0, + sellprice => 0.58, + tax_amount => 0.6612, + taxkey_id => $taxkeys{$item->parts_id}->id, + }, + ], + rounding => 0, }, "${title}: calculated data"); } @@ -371,5 +460,7 @@ Support::TestSetup::login(); test_default_invoice_one_item_19_tax_not_included(); test_default_invoice_two_items_19_7_tax_not_included(); test_default_invoice_three_items_sellprice_rounding_discount(); +test_default_invoice_one_item_19_tax_not_included_rounding_discount(); +clear_up(); done_testing();