X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=t%2Fdb_helper%2Fconvert_invoice.t;h=dc21352617c0c82bdc5ae19917ab88b4a95f69c2;hb=refs%2Fheads%2Fswiss;hp=5279d65ebecf03d2a5be14f9c9365bb8f551d987;hpb=a7ca8ba215c2a039e97c27bc3c637712fca837e9;p=kivitendo-erp.git diff --git a/t/db_helper/convert_invoice.t b/t/db_helper/convert_invoice.t index 5279d65eb..dc2135261 100644 --- a/t/db_helper/convert_invoice.t +++ b/t/db_helper/convert_invoice.t @@ -1,4 +1,4 @@ -use Test::More tests => 29; +use Test::More tests => 42; use strict; @@ -27,10 +27,13 @@ use SL::DB::TaxZone; my ($customer, $currency_id, $buchungsgruppe, $employee, $vendor, $taxzone, $buchungsgruppe7, $tax, $tax7, $unit, @parts); +my $VISUAL_TEST = 0; # just a sleep to click around + sub clear_up { - foreach (qw(DeliveryOrderItem DeliveryOrder InvoiceItem Invoice Part Customer Vendor Employee Department PaymentTerm)) { + foreach (qw(DeliveryOrderItem DeliveryOrder InvoiceItem Invoice Part Customer Vendor Department PaymentTerm)) { "SL::DB::Manager::${_}"->delete_all(all => 1); } + SL::DB::Manager::Employee->delete_all(where => [ id => 31915 ]); }; sub reset_state { @@ -38,13 +41,23 @@ sub reset_state { clear_up(); - $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group 19\%"; - $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%', %{ $params{buchungsgruppe} }) || croak "No accounting group 7\%"; - $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone"; - $tax = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} }) || croak "No tax for 19\%"; - $tax7 = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07) || croak "No tax for 7\%"; - $unit = SL::DB::Manager::Unit->find_by(name => 'kg', %{ $params{unit} }) || croak "No unit"; - $currency_id = $::instance_conf->get_currency_id; + if ($::lx_office_conf{system}->{default_manager} eq "swiss") { + $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 8%', %{ $params{buchungsgruppe} }) || croak "No accounting group 8\%"; + $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 2.5%', %{ $params{buchungsgruppe} })|| croak "No accounting group 2.5\%"; + $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Schweiz') || croak "No taxzone"; + $tax = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.08, %{ $params{tax} }) || croak "No tax for 8\%"; + $tax7 = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.025) || croak "No tax for 2.5\%"; + $unit = SL::DB::Manager::Unit->find_by(name => 'kg', %{ $params{unit} }) || croak "No unit"; + $currency_id = $::instance_conf->get_currency_id; + } else { + $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group 19\%"; + $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%', %{ $params{buchungsgruppe} }) || croak "No accounting group 7\%"; + $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone"; + $tax = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} }) || croak "No tax for 19\%"; + $tax7 = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07) || croak "No tax for 7\%"; + $unit = SL::DB::Manager::Unit->find_by(name => 'kg', %{ $params{unit} }) || croak "No unit"; + $currency_id = $::instance_conf->get_currency_id; + } $customer = SL::DB::Customer->new( name => '520484567dfaedc9e60fc', @@ -95,7 +108,7 @@ sub reset_state { 'sellprice' => '242.20000', #'warehouse_id' => 64702, 'weight' => '0.79', - description => "Nussbaum, Gr.5, Unterfilz weinrot, genietet[[Aufschnittbreite: 11,0, Kernform: US]]\"" , + description => "Pflaumenbaum, Gr.5, Unterfilz weinrot, genietet[[Aufschnittbreite: 11,0, Kernform: US]]\"" , buchungsgruppen_id => $buchungsgruppe->id, unit => $unit->name, id => 26321, @@ -139,9 +152,9 @@ reset_state(); my $do1 = new_delivery_order('department_id' => 32149, 'donumber' => 'L20199', 'employee_id' => 31915, - 'intnotes' => 'Achtung: Neue Lieferadresse ab 16.02.2015 in der Carl-von-Ossietzky-Str.32! 13.02.2015/MH + 'intnotes' => 'Achtung: Neue Lieferadresse ab 16.02.2015 in der Otto-Merck-Str. 7a! 13.02.2015/MH - Steinway-Produkte (201...) immer plus 25% dazu rechnen / BK 13.02.2014', + Yamaha-Produkte (201...) immer plus 25% dazu rechnen / BK 13.02.2014', 'ordnumber' => 'A16399', 'payment_id' => 11276, 'salesman_id' => 31915, @@ -155,16 +168,17 @@ my $do1 = new_delivery_order('department_id' => 32149, 'cusordnumber' => 'b84da', 'customer_id' => $customer->id, 'id' => 464003, + 'notes' => '', ); my $do1_item1 = SL::DB::DeliveryOrderItem->new('delivery_order_id' => 464003, 'description' => "Flügel Hammerkopf bestehend aus: Bass/Diskant 26/65 Stück, Gesamtlänge 80/72, Bohrlänge 56/48 - Nussbaum, Gr.5, Unterfilz weinrot, genietet[[Aufschnittbreite: 11,0, Kernform: US]]", + Pflaumenbaum, Gr.5, Unterfilz weinrot, genietet[[Aufschnittbreite: 11,0, Kernform: US]]", 'discount' => '0.25', 'id' => 144736, 'lastcost' => '49.95000', - 'longdescription' => '', + 'longdescription' => "
  1. 27
  2. 28
  3. 29
  4. asdf
  5. asdf
  6. oben

kommt nicht mehr vor

", 'marge_price_factor' => 1, 'mtime' => undef, 'ordnumber' => 'A16399', @@ -208,22 +222,27 @@ Kapseln mit Yamaha Profil, Kerbenabstand 3,6 mm mit eingedrehten Abnickschrauben # test delivery order before any conversion ok($do1->donumber eq "L20199", 'Delivery Order Number created'); +ok($do1->notes eq '', "do RichText notes saved"); ok((not $do1->closed) , 'Delivery Order is not closed'); ok($do1_item1->parts_id eq '26321', 'doi linked with part'); ok($do1_item1->qty == 2, 'qty check doi'); -ok($do1_item2->position == 2, 'doi2 position check'); -ok(2 == scalar@{ SL::DB::Manager::DeliveryOrderItem->get_all(where => [ delivery_order_id => $do1->id ]) }, 'two doi linked'); +ok($do1_item1->longdescription eq "
  1. 27
  2. 28
  3. 29
  4. asdf
  5. asdf
  6. oben

kommt nicht mehr vor

", + "do item1 rich text longdescripition"); +ok ($do1_item2->position == 2, 'doi2 position check'); +ok (2 == scalar@{ SL::DB::Manager::DeliveryOrderItem->get_all(where => [ delivery_order_id => $do1->id ]) }, 'two doi linked'); # convert this do to invoice my $invoice = $do1->convert_to_invoice(); +sleep (300) if $VISUAL_TEST; # we can do a real visual test via gui login # test invoice afterwards ok ($invoice->shipvia eq "DHL, Versand am 06.03.2015, 1 Paket 17,00 kg", "ship via check"); ok ($invoice->shippingpoint eq "Maisenhaus", "shipping point check"); ok ($invoice->ordnumber eq "A16399", "ordnumber check"); ok ($invoice->donumber eq "L20199", "donumber check"); +ok ($invoice->notes eq '', "do RichText notes saved"); ok(($do1->closed) , 'Delivery Order is closed after conversion'); ok (SL::DB::PaymentTerm->new(id => $invoice->{payment_id})->load->description eq "14Tage 2%Skonto, 30Tage netto", 'payment term description check'); @@ -266,7 +285,11 @@ $invoice->load; ok($invoice->currency_id eq '1', 'currency_id'); ok($invoice->cusordnumber eq 'b84da', 'cusordnumber check'); ok(SL::DB::Department->new(id => $invoice->{department_id})->load->description eq "Maisenhaus-Versand", 'department description'); -is($invoice->amount, '1354.17000', 'amount check'); +if ($::lx_office_conf{system}->{default_manager} eq "swiss") { + is($invoice->amount, '1229.00000', 'amount check'); +} else { + is($invoice->amount, '1354.17000', 'amount check'); +} is($invoice->marge_percent, '50.88580', 'marge percent check'); is($invoice->marge_total, '579.06000', 'marge total check'); is($invoice->netamount, '1137.96000', 'netamount check'); @@ -276,6 +299,8 @@ ok(@ {$invoice->items_sorted}[0]->parts_id eq '26321', 'invoiceitem 1 linked wit ok(2 == scalar@{ $invoice->invoiceitems }, 'two invoice items linked with invoice'); is(@ {$invoice->items_sorted}[0]->position, 1, "position 1 order correct"); is(@ {$invoice->items_sorted}[1]->position, 2, "position 2 order correct"); +is(@ {$invoice->items_sorted}[0]->longdescription, "
  1. 27
  2. 28
  3. 29
  4. asdf
  5. asdf
  6. oben

kommt nicht mehr vor

", + "invoice item1 rich text longdescripition"); is(@ {$invoice->items_sorted}[0]->part->partnumber, 'v-519160549', "partnumber 1 correct"); is(@ {$invoice->items_sorted}[1]->part->partnumber, 'v-120160086', "partnumber 2 correct"); is(@ {$invoice->items_sorted}[0]->qty, '2.00000', "pos 1 qty"); @@ -285,6 +310,53 @@ is(@ {$invoice->items_sorted}[1]->discount, 0.25, "pos 2 discount"); # more ideas: check onhand, lastcost (parsed lastcost) + + +# check linked records AND linked items + +# we expect something like this in record links: +# delivery_order_items | 144736 | invoice | 9 | 2015-09-02 16:29:32.362562 | 5 +# delivery_order_items | 144737 | invoice | 10 | 2015-09-02 16:29:32.362562 | 6 +# delivery_orders | 464003 | ar | 5 | 2015-09-02 16:29:32.362562 | 7 +# wir erwarten: +# verkn�pfter beleg$VAR1 = { +# 'from_id' => 464003, +# 'from_table' => 'delivery_orders', +# 'to_id' => 11, +# 'to_table' => 'ar' +# }; +# verkn�pfte positionen$VAR1 = { +# 'from_id' => 144737, +# 'from_table' => 'delivery_order_items', +# 'to_id' => 22, +# 'to_table' => 'invoice' +# }; +# $VAR2 = { +# 'from_id' => 144736, +# 'from_table' => 'delivery_order_items', +# 'to_id' => 21, +# 'to_table' => 'invoice' +# }; + + + +my @links_record = RecordLinks->get_links('from_table' => 'delivery_orders', + 'to_table' => 'ar', + 'from_id' => 464003); +is($links_record[0]->{from_id}, '464003', "record from id check"); +is($links_record[0]->{from_table}, 'delivery_orders', "record from table check"); +is($links_record[0]->{to_table}, 'ar', "record to table check"); + +foreach (qw(144736 144737)) { + my @links_record_item1 = RecordLinks->get_links('from_table' => 'delivery_order_items', + 'to_table' => 'invoice', + 'from_id' => $_); + is($links_record_item1[0]->{from_id}, $_, "record from id check $_"); + is($links_record_item1[0]->{from_table}, 'delivery_order_items', "record from table check $_"); + is($links_record_item1[0]->{to_table}, 'invoice', "record to table check $_"); +} + + clear_up(); 1;