X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=t%2Fdb_helper%2Fprice_tax_calculator.t;h=a4f6ddcaffe7afa22bae239b0792903658f9d51c;hb=9447acbeb7b1cd0bb4691aa1da8f533ca9099064;hp=5050ecd5ff290467e11a8891649f3805508c588e;hpb=578142061d9297223f05c2a9ac021d3d8e3ca0cb;p=kivitendo-erp.git diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index 5050ecd5f..a4f6ddcaf 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -98,6 +98,15 @@ sub new_invoice { %params, ); } +sub new_order { + my %params = @_; + + return create_sales_order( + transdate => $transdate, + taxzone_id => $taxzone->id, + %params, + ); +} sub new_item { my (%params) = @_; @@ -109,6 +118,16 @@ sub new_item { %params, ); } +sub new_order_item { + my (%params) = @_; + + my $part = delete($params{part}) || $parts[0]; + + return create_order_item( + part => $part, + %params, + ); +} sub test_default_invoice_one_item_19_tax_not_included() { reset_state(); @@ -553,6 +572,85 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_big_qty_ rounding => 0, }, "${title}: calculated data"); } +sub test_default_order_two_items_19_one_optional() { + reset_state(); + + my $item = new_order_item(qty => 2.5); + my $item_optional = new_order_item(qty => 2.5, optional => 1); + + my $order = new_order( + taxincluded => 0, + orderitems => [ $item, $item_optional ], + ); + + my $taxkey = $item->part->get_taxkey(date => $transdate, is_sales => 1, taxzone => $order->taxzone_id); + + # sellprice 2.34 * qty 2.5 = 5.85 + # 19%(5.85) = 1.1115; rounded = 1.11 + # total rounded = 6.96 + + # lastcost 1.93 * qty 2.5 = 4.825; rounded 4.83 + # line marge_total = 1.02 + # line marge_percent = 17.4358974358974 + + my $title = 'default order, two item, one item optional, 19% tax not included'; + my %data = $order->calculate_prices_and_taxes; + + is($item->marge_total, 1.02, "${title}: item marge_total"); + is($item->marge_percent, 17.4358974358974, "${title}: item marge_percent"); + is($item->marge_price_factor, 1, "${title}: item marge_price_factor"); + + # optional items have a linetotal and marge, but ... + is($item_optional->marge_total, 1.02, "${title}: item optional marge_total"); + is($item_optional->marge_percent, 17.4358974358974, "${title}: item optional marge_percent"); + is($item_optional->marge_price_factor, 1, "${title}: item optional marge_price_factor"); + + # ... should not be calculated for the record sum + is($order->netamount, 5.85, "${title}: netamount"); + is($order->amount, 6.96, "${title}: amount"); + is($order->marge_total, 1.02, "${title}: marge_total"); + is($order->marge_percent, 17.4358974358974, "${title}: marge_percent"); + is($order->orderitems->[1]->optional, 1, "${title}: second order item has attribute optional"); + # diag explain $order->orderitems->[1]->optional; + # diag explain \%data; + is_deeply(\%data, { + allocated => {}, + amounts => { + $buchungsgruppe->income_accno_id($taxzone) => { + amount => 5.85, + tax_id => $tax->id, + taxkey => 3, + }, + }, + amounts_cogs => {}, + assembly_items => [ + [], + [], + ], + exchangerate => 1, + taxes_by_chart_id => { + $tax->chart_id => 1.11, + }, + taxes_by_tax_id => { + $tax->id => 1.1115, + }, + items => [ + { linetotal => 5.85, + linetotal_cost => 4.83, + sellprice => 2.34, + tax_amount => 1.1115, + taxkey_id => $taxkey->id, + }, + { linetotal => 5.85, + linetotal_cost => 4.83, + sellprice => 2.34, + tax_amount => 1.1115, + taxkey_id => $taxkey->id, + }, + ], + rounding => 0, + }, "${title}: calculated data"); +} Support::TestSetup::login(); @@ -566,6 +664,7 @@ test_default_invoice_three_items_sellprice_rounding_discount(); test_default_invoice_one_item_19_tax_not_included_rounding_discount(); test_default_invoice_one_item_19_tax_not_included_rounding_discount_huge_qty(); test_default_invoice_one_item_19_tax_not_included_rounding_discount_big_qty_low_sellprice(); +test_default_order_two_items_19_one_optional(); clear_up(); done_testing();