Revision 828c7d4e
Von Bernd Bleßmann vor etwa 6 Jahren hinzugefügt
t/db/order.t | ||
---|---|---|
1 |
use Test::More; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use lib 't'; |
|
6 |
use utf8; |
|
7 |
|
|
8 |
use Carp; |
|
9 |
use Data::Dumper; |
|
10 |
use Support::TestSetup; |
|
11 |
use Test::Exception; |
|
12 |
|
|
13 |
use SL::DB::Order; |
|
14 |
use SL::DB::Customer; |
|
15 |
use SL::DB::Department; |
|
16 |
use SL::DB::Currency; |
|
17 |
use SL::DB::PaymentTerm; |
|
18 |
use SL::DB::DeliveryTerm; |
|
19 |
use SL::DB::Employee; |
|
20 |
use SL::DB::Part; |
|
21 |
use SL::DB::Unit; |
|
22 |
|
|
23 |
use SL::Dev::ALL qw(:ALL); |
|
24 |
|
|
25 |
my ($customer, $employee, $payment_term, $delivery_term, $unit, @parts, $department); |
|
26 |
|
|
27 |
|
|
28 |
sub clear_up { |
|
29 |
foreach (qw(OrderItem Order Part Customer Department PaymentTerm DeliveryTerm)) { |
|
30 |
"SL::DB::Manager::${_}"->delete_all(all => 1); |
|
31 |
} |
|
32 |
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]); |
|
33 |
}; |
|
34 |
|
|
35 |
sub reset_state { |
|
36 |
my %params = @_; |
|
37 |
|
|
38 |
clear_up(); |
|
39 |
|
|
40 |
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'"; |
|
41 |
$customer = new_customer()->save; |
|
42 |
|
|
43 |
$employee = SL::DB::Employee->new( |
|
44 |
'login' => 'testuser', |
|
45 |
'name' => 'Test User', |
|
46 |
)->save; |
|
47 |
|
|
48 |
$department = SL::DB::Department->new( |
|
49 |
'description' => 'Test Department', |
|
50 |
)->save; |
|
51 |
|
|
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', |
|
56 |
'terms_netto' => 30, |
|
57 |
'terms_skonto' => 14 |
|
58 |
); |
|
59 |
|
|
60 |
$delivery_term = SL::DB::DeliveryTerm->new( |
|
61 |
'description' => 'Test Delivey Term', |
|
62 |
'description_long' => 'Test Delivey Term Test Delivey Term', |
|
63 |
)->save; |
|
64 |
|
|
65 |
# some parts/services |
|
66 |
@parts = (); |
|
67 |
push @parts, new_part( |
|
68 |
partnumber => 'T4254', |
|
69 |
unit => $unit->name, |
|
70 |
)->save; |
|
71 |
push @parts, new_service( |
|
72 |
partnumber => 'Serv1', |
|
73 |
)->save; |
|
74 |
push @parts, new_part( |
|
75 |
partnumber => 'P2445', |
|
76 |
)->save; |
|
77 |
push @parts, new_service( |
|
78 |
partnumber => 'Serv2' |
|
79 |
)->save; |
|
80 |
} |
|
81 |
|
|
82 |
Support::TestSetup::login(); |
|
83 |
|
|
84 |
reset_state(); |
|
85 |
|
|
86 |
|
|
87 |
##### |
|
88 |
my $order1 = SL::Dev::Record::create_sales_order( |
|
89 |
save => 1, |
|
90 |
customer => $customer, |
|
91 |
shippingpoint => "sp", |
|
92 |
transaction_description => "td1", |
|
93 |
payment_terms => $payment_term, |
|
94 |
delivery_term => $delivery_term, |
|
95 |
taxincluded => 0, |
|
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), |
|
98 |
] |
|
99 |
); |
|
100 |
|
|
101 |
my $delivery_term2 = SL::DB::DeliveryTerm->new( |
|
102 |
'description' => 'Test Delivey Term2', |
|
103 |
'description_long' => 'Test Delivey Term2 Test Delivey Term2', |
|
104 |
)->save; |
|
105 |
|
|
106 |
my $order2 = SL::Dev::Record::create_sales_order( |
|
107 |
save => 1, |
|
108 |
customer => $customer, |
|
109 |
shippingpoint => "sp", |
|
110 |
transaction_description => "td2", |
|
111 |
payment_terms => $payment_term, |
|
112 |
delivery_term => $delivery_term2, |
|
113 |
taxincluded => 0, |
|
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), |
|
116 |
] |
|
117 |
); |
|
118 |
|
|
119 |
my $order = SL::DB::Order->new_from_multi([$order1, $order2]); |
|
120 |
|
|
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'; |
|
126 |
|
|
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'; |
|
131 |
|
|
132 |
reset_state(); |
|
133 |
|
|
134 |
##### |
|
135 |
$order1 = SL::Dev::Record::create_sales_order( |
|
136 |
save => 1, |
|
137 |
taxincluded => 0, |
|
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), |
|
140 |
] |
|
141 |
); |
|
142 |
$order2 = SL::Dev::Record::create_sales_order( |
|
143 |
save => 1, |
|
144 |
customer => $customer, |
|
145 |
taxincluded => 0, |
|
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), |
|
148 |
] |
|
149 |
); |
|
150 |
|
|
151 |
my $err_msg; |
|
152 |
eval { $order = SL::DB::Order->new_from_multi([$order1, $order2]); 1 } or do {$err_msg = $@}; |
|
153 |
|
|
154 |
ok $err_msg =~ "^Cannot create order from source records of different customers", 'new from multi: fail on different customers'; |
|
155 |
|
|
156 |
|
|
157 |
#### |
|
158 |
clear_up(); |
|
159 |
|
|
160 |
done_testing; |
|
161 |
|
|
162 |
1; |
|
163 |
|
|
164 |
|
|
165 |
# set emacs to perl mode |
|
166 |
# Local Variables: |
|
167 |
# mode: perl |
|
168 |
# End: |
Auch abrufbar als: Unified diff
SL::DB::Order: Tests für new_from_multi