10 use Support::TestSetup;
15 use SL::DB::Department;
17 use SL::DB::PaymentTerm;
18 use SL::DB::DeliveryTerm;
23 use SL::Dev::ALL qw(:ALL);
25 my ($customer, $employee, $payment_term, $delivery_term, $unit, @parts, $department);
29 foreach (qw(OrderItem Order Part Customer Department PaymentTerm DeliveryTerm)) {
30 "SL::DB::Manager::${_}"->delete_all(all => 1);
32 SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
40 $unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'";
41 $customer = new_customer()->save;
43 $employee = SL::DB::Employee->new(
44 'login' => 'testuser',
45 'name' => 'Test User',
48 $department = SL::DB::Department->new(
49 'description' => 'Test Department',
52 $payment_term = create_payment_terms(
53 'description' => '14Tage 2%Skonto, 30Tage netto',
54 'description_long' => "Innerhalb von 14 Tagen abzüglich 2 % Skonto, innerhalb von 30 Tagen rein netto.|Bei einer Zahlung bis zum <%skonto_date%> gewähren wir 2 % Skonto (EUR <%skonto_amount%>) entspricht EUR <%total_wo_skonto%>.Bei einer Zahlung bis zum <%netto_date%> ist der fällige Betrag in Höhe von <%total%> <%currency%> zu überweisen.",
55 'percent_skonto' => '0.02',
60 $delivery_term = SL::DB::DeliveryTerm->new(
61 'description' => 'Test Delivey Term',
62 'description_long' => 'Test Delivey Term Test Delivey Term',
67 push @parts, new_part(
68 partnumber => 'T4254',
71 push @parts, new_service(
72 partnumber => 'Serv1',
74 push @parts, new_part(
75 partnumber => 'P2445',
77 push @parts, new_service(
82 Support::TestSetup::login();
88 my $order1 = SL::Dev::Record::create_sales_order(
90 customer => $customer,
91 shippingpoint => "sp",
92 transaction_description => "td1",
93 payment_terms => $payment_term,
94 delivery_term => $delivery_term,
96 orderitems => [ SL::Dev::Record::create_order_item(part => $parts[0], qty => 3, sellprice => 70),
97 SL::Dev::Record::create_order_item(part => $parts[1], qty => 10, sellprice => 50),
101 my $delivery_term2 = SL::DB::DeliveryTerm->new(
102 'description' => 'Test Delivey Term2',
103 'description_long' => 'Test Delivey Term2 Test Delivey Term2',
106 my $order2 = SL::Dev::Record::create_sales_order(
108 customer => $customer,
109 shippingpoint => "sp",
110 transaction_description => "td2",
111 payment_terms => $payment_term,
112 delivery_term => $delivery_term2,
114 orderitems => [ SL::Dev::Record::create_order_item(part => $parts[2], qty => 1, sellprice => 60),
115 SL::Dev::Record::create_order_item(part => $parts[3], qty => 20, sellprice => 40),
119 my $order = SL::DB::Order->new_from_multi([$order1, $order2]);
121 ok $order->items->[0]->part->id == $parts[0]->id
122 && $order->items->[1]->part->id == $parts[1]->id
123 && $order->items->[2]->part->id == $parts[2]->id
124 && $order->items->[3]->part->id == $parts[3]->id,
125 'new from multi: positions added ok';
127 ok $order->shippingpoint eq "sp", 'new from multi: keep same info';
128 ok !$order->transaction_description, 'new from multi: undefine differnt info';
129 ok $order->payment_id == $payment_term->id, 'new from multi: keep same info';
130 ok !$order->delivery_term, 'new from multi: undefine differnt info';
135 $order1 = SL::Dev::Record::create_sales_order(
138 orderitems => [ SL::Dev::Record::create_order_item(part => $parts[0], qty => 3, sellprice => 70),
139 SL::Dev::Record::create_order_item(part => $parts[1], qty => 10, sellprice => 50),
142 $order2 = SL::Dev::Record::create_sales_order(
144 customer => $customer,
146 orderitems => [ SL::Dev::Record::create_order_item(part => $parts[2], qty => 1, sellprice => 60),
147 SL::Dev::Record::create_order_item(part => $parts[3], qty => 20, sellprice => 40),
152 eval { $order = SL::DB::Order->new_from_multi([$order1, $order2]); 1 } or do {$err_msg = $@};
154 ok $err_msg =~ "^Cannot create order from source records of different customers", 'new from multi: fail on different customers';
165 # set emacs to perl mode