X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fdb_helper%2Fprice_tax_calculator.t;h=98462641d3a6055fe681a60af90f785a34da4141;hb=acba025a9a6fe28250a1006814e25a45460a9941;hp=b374f5eba3c6647d873b110abd87155dc942a8f0;hpb=a6fc1f811ae96b82a5c83aa8d663a16ea8751637;p=kivitendo-erp.git diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index b374f5eba..98462641d 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -7,27 +7,37 @@ use utf8; use Carp; use Data::Dumper; +use List::MoreUtils qw(uniq); use Support::TestSetup; 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\%"; @@ -42,6 +52,7 @@ sub reset_state { $customer = SL::DB::Customer->new( name => 'Test Customer', currency_id => $currency_id, + taxzone_id => $taxzone->id, %{ $params{customer} } )->save; @@ -108,6 +119,8 @@ sub test_default_invoice_one_item_19_tax_not_included() { invoiceitems => [ $item ], ); + my $taxkey = $item->part->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id); + # sellprice 2.34 * qty 2.5 = 5.85 # 19%(5.85) = 1.1115; rounded = 1.11 # total rounded = 6.96 @@ -129,22 +142,30 @@ sub test_default_invoice_one_item_19_tax_not_included() { is($invoice->marge_percent, 17.4358974358974, "${title}: marge_percent"); is_deeply(\%data, { - allocated => {}, - amounts => { - $buchungsgruppe->income_accno_id_0 => { - amount => 5.85, - tax_id => $tax->id, - taxkey => 3, + allocated => {}, + amounts => { + $buchungsgruppe->income_accno_id($taxzone) => { + amount => 5.85, + tax_id => $tax->id, + taxkey => 3, }, }, - amounts_cogs => {}, - assembly_items => [ + amounts_cogs => {}, + assembly_items => [ [], ], - exchangerate => 1, - taxes => { - $tax->chart_id => 1.11, + exchangerate => 1, + taxes => { + $tax->chart_id => 1.11, }, + items => [ + { linetotal => 5.85, + linetotal_cost => 4.83, + sellprice => 2.34, + tax_amount => 1.1115, + taxkey_id => $taxkey->id, + }, + ], }, "${title}: calculated data"); } @@ -158,6 +179,9 @@ sub test_default_invoice_two_items_19_7_tax_not_included() { invoiceitems => [ $item1, $item2 ], ); + my $taxkey1 = $item1->part->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id); + my $taxkey2 = $item2->part->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id); + # item 1: # sellprice 2.34 * qty 2.5 = 5.85 # 19%(5.85) = 1.1115; rounded = 1.11 @@ -193,28 +217,42 @@ sub test_default_invoice_two_items_19_7_tax_not_included() { is($invoice->marge_percent, 34.8943460879497, "${title}: marge_percent"); is_deeply(\%data, { - allocated => {}, - amounts => { - $buchungsgruppe->income_accno_id_0 => { - amount => 5.85, - tax_id => $tax->id, - taxkey => 3, + allocated => {}, + amounts => { + $buchungsgruppe->income_accno_id($taxzone) => { + amount => 5.85, + tax_id => $tax->id, + taxkey => 3, }, - $buchungsgruppe7->income_accno_id_0 => { - amount => 11.66, - tax_id => $tax7->id, - taxkey => 2, + $buchungsgruppe7->income_accno_id($taxzone) => { + amount => 11.66, + tax_id => $tax7->id, + taxkey => 2, }, }, - amounts_cogs => {}, - assembly_items => [ + amounts_cogs => {}, + assembly_items => [ [], [], ], - exchangerate => 1, - taxes => { - $tax->chart_id => 1.11, - $tax7->chart_id => 0.82, + exchangerate => 1, + taxes => { + $tax->chart_id => 1.11, + $tax7->chart_id => 0.82, }, + items => [ + { linetotal => 5.85, + linetotal_cost => 4.83, + sellprice => 2.34, + tax_amount => 1.1115, + taxkey_id => $taxkey1->id, + }, + { linetotal => 11.66, + linetotal_cost => 6.57, + sellprice => 9.714, + tax_amount => 0.8162, + taxkey_id => $taxkey2->id, + }, + ], }, "${title}: calculated data"); } @@ -229,6 +267,8 @@ sub test_default_invoice_three_items_sellprice_rounding_discount() { invoiceitems => [ $item1, $item2, $item3 ], ); + my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item1, $item2, $item3); + # this is how price_tax_calculator is implemented. It differs from # the way sales_order / invoice - forms are calculating: # linetotal = sellprice 5.55 * qty 1 * (1 - 0.05) = 5.2725; rounded 5.27 @@ -295,22 +335,42 @@ sub test_default_invoice_three_items_sellprice_rounding_discount() { is($invoice->marge_percent, 62.007874015748, "${title}: marge_percent"); is_deeply(\%data, { - allocated => {}, - amounts => { - $buchungsgruppe->income_accno_id_0 => { - amount => 15.24, - tax_id => $tax->id, - taxkey => 3, + allocated => {}, + amounts => { + $buchungsgruppe->income_accno_id($taxzone) => { + amount => 15.24, + tax_id => $tax->id, + taxkey => 3, }, }, - amounts_cogs => {}, - assembly_items => [ + amounts_cogs => {}, + assembly_items => [ [], [], [], ], - exchangerate => 1, - taxes => { - $tax->chart_id => 2.9, + exchangerate => 1, + taxes => { + $tax->chart_id => 2.9, }, + items => [ + { linetotal => 5.27, + linetotal_cost => 1.93, + sellprice => 5.27, + tax_amount => 1.0013, + taxkey_id => $taxkeys{$item1->parts_id}->id, + }, + { linetotal => 5.22, + linetotal_cost => 1.93, + sellprice => 5.22, + tax_amount => 0.9918, + taxkey_id => $taxkeys{$item2->parts_id}->id, + }, + { linetotal => 4.75, + linetotal_cost => 1.93, + sellprice => 4.75, + tax_amount => 0.9025, + taxkey_id => $taxkeys{$item3->parts_id}->id, + } + ], }, "${title}: calculated data"); } @@ -320,4 +380,5 @@ 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(); +clear_up(); done_testing();