Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b2d19248

Von Bernd Bleßmann vor etwa 3 Jahren hinzugefügt

  • ID b2d1924891db6a6387cb8665d737c76d4bd6bb6e
  • Vorgänger 6c3afa9b
  • Nachfolger a4624332

convert_invoice.t: Konvertierung aus Auftrag inkl. verlinkter Positionen

Unterschiede anzeigen:

t/db_helper/convert_invoice.t
1
use Test::More tests => 41;
1
use Test::More tests => 73;
2 2

  
3 3
use strict;
4 4

  
......
30 30
my $VISUAL_TEST = 0;  # just a sleep to click around
31 31

  
32 32
sub clear_up {
33
  foreach (qw(DeliveryOrderItem DeliveryOrder InvoiceItem Invoice Part Customer Department PaymentTerm)) {
33
  foreach (qw(DeliveryOrderItem DeliveryOrder OrderItem Order InvoiceItem Invoice Part Customer Department PaymentTerm)) {
34 34
    "SL::DB::Manager::${_}"->delete_all(all => 1);
35 35
  }
36 36
  SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
......
235 235
  is($links_record_item1[0]->{to_table}   , 'invoice'              , "record to table check $_");
236 236
}
237 237

  
238
##############
239
# test conversion from order to invoice
240
##############
241

  
242
reset_state();
243

  
244
# we create A16399 with two items
245
my $o1 = create_sales_order(
246
  save            => 1,
247
  'department_id' => $department->id,
248
  'transdate'     => $transdate,
249
  'employee_id'   => $employee->id,
250
  'intnotes'      => 'some intnotes',
251
  'ordnumber'     => 'A16399',
252
  'payment_id'    => $payment_do->id,
253
  'salesman_id'   => $employee->id,
254
  'shippingpoint' => 'sendtome',
255
  'shipvia'       => 'DHL, Versand am 06.03.2015, 1 Paket  17,00 kg',
256
  'cusordnumber'  => 'b84da',
257
  'customer_id'   => $customer->id,
258
  'notes'         => '<ul><li><strong>fett</strong></li><li><strong>und</strong></li><li><strong>mit</strong></li><li><strong>bullets</strong></li><li>&nbsp;</li></ul>',
259
  orderitems => [
260
                  create_order_item(
261
                    part               => $parts[0],
262
                    discount           => '0.25',
263
                    lastcost           => '49.95000',
264
                    longdescription    => "<ol><li>27</li><li>28</li><li>29</li><li><sub>asdf</sub></li><li><sub>asdf</sub></li><li><sup>oben</sup></li></ol><p><s>kommt nicht mehr vor</s></p>",
265
                    marge_price_factor => 1,
266
                    qty                => '2.00000',
267
                    sellprice          => '242.20000',
268
                    unit               => $unit->name,
269
                  ),
270
                  create_order_item(
271
                    part            => $parts[1],
272
                    discount        => '0.25',
273
                    lastcost        => '153.00000',
274
                    qty             => '3.00000',
275
                    sellprice       => '344.30000',
276
                    transdate       => '06.03.2015',
277
                    unit            => $unit->name,
278
                  )
279
                ]
280
);
281

  
282

  
283
# TESTS
284

  
285
my $o1_item1 = $o1->orderitems->[0];
286
my $o1_item2 = $o1->orderitems->[1];
287

  
288
# convert this order to invoice
289
$invoice = $o1->convert_to_invoice(transdate => $transdate);
290
$invoice->load;
291

  
292
# test invoice afterwards
293
ok ($invoice->shipvia eq "DHL, Versand am 06.03.2015, 1 Paket  17,00 kg", "convert form order: ship via check");
294
ok ($invoice->shippingpoint eq "sendtome", "convert form order: shipping point check");
295
ok ($invoice->ordnumber eq "A16399", "convert form order: ordnumber check");
296
ok ($invoice->notes eq '<ul><li><strong>fett</strong></li><li><strong>und</strong></li><li><strong>mit</strong></li><li><strong>bullets</strong></li><li>&nbsp;</li></ul>', "convert form order: do RichText notes saved");
297
ok(($o1->closed) , 'convert form order: Order is closed after conversion');
298
is($invoice->payment_terms->description, "14Tage 2%Skonto, 30Tage netto", 'convert form order: payment term description check');
299

  
300
is($invoice->cusordnumber,            'b84da',           'convert form order: cusordnumber check');
301
is($invoice->department->description, "Test Department", 'convert form order: department description ok');
302
is($invoice->amount,                  '1354.20000',      'convert form order: amount check');
303
is($invoice->marge_percent,           '50.88666',        'convert form order: marge percent check');
304
is($invoice->marge_total,             '579.08000',       'convert form order: marge total check');
305
is($invoice->netamount,               '1137.98000',      'convert form order: netamount check');
306

  
307
# some item checks
308
is($invoice->items_sorted->[0]->parts_id,         $parts[0]->id , 'convert form order: invoiceitem 1 linked with part');
309
is(scalar @{ $invoice->invoiceitems },            2,              'convert form order: two invoice items linked with invoice');
310
is($invoice->items_sorted->[0]->position,         1,              "convert form order: position 1 order correct");
311
is($invoice->items_sorted->[1]->position,         2,              "convert form order: position 2 order correct");
312
is($invoice->items_sorted->[0]->part->partnumber, 'v-519160549' , "convert form order: partnumber 1 correct");
313
is($invoice->items_sorted->[1]->part->partnumber, 'v-120160086' , "convert form order: partnumber 2 correct");
314
is($invoice->items_sorted->[0]->qty,              '2.00000',      "convert form order: pos 1 qty");
315
is($invoice->items_sorted->[1]->qty,              '3.00000',      "convert form order: pos 2 qty");
316
is($invoice->items_sorted->[0]->discount,         0.25,           "convert form order: pos 1 discount");
317
is($invoice->items_sorted->[1]->discount,         0.25,           "convert form order: pos 2 discount");
318
is($invoice->items_sorted->[0]->longdescription , "<ol><li>27</li><li>28</li><li>29</li><li><sub>asdf</sub></li><li><sub>asdf</sub></li><li><sup>oben</sup></li></ol><p><s>kommt nicht mehr vor</s></p>",
319
     "convert form order: invoice item1 rich text longdescripition");
320

  
321
# check linked records AND linked items
322
@links_record = RecordLinks->get_links('from_table' => 'oe',
323
                                       'to_table'   => 'ar',
324
                                       'from_id'    => $o1->id,
325
);
326

  
327
is($links_record[0]->{from_id},    $o1->id, "convert form order: record from id check");
328
is($links_record[0]->{from_table}, 'oe',    "convert form order: record from table check");
329
is($links_record[0]->{to_table},   'ar',    "convert form order: record to table check");
330

  
331
my $i = 0;
332
foreach ( $o1_item1->id, $o1_item2->id ) {
333
  $i++;
334
  my @links_record_item = RecordLinks->get_links('from_table' => 'orderitems',
335
                                                  'to_table'   => 'invoice',
336
                                                  'from_id'    => $_,
337
                                                 );
338

  
339
  is($links_record_item[0]->{from_id},    $_ ,          "convert form order: record from id check item $i");
340
  is($links_record_item[0]->{from_table}, 'orderitems', "convert form order: record from table check item $i");
341
  is($links_record_item[0]->{to_table},   'invoice',    "convert form order: record to table check item $i");
342
}
343

  
238 344
clear_up();
239 345

  
240 346
1;

Auch abrufbar als: Unified diff