Revision b3db6825
Von Kivitendo Admin vor mehr als 1 Jahr hinzugefügt
t/model/records.t | ||
---|---|---|
24 | 24 |
my ($sales_quotation1, $sales_order1, $sales_invoice1, $sales_delivery_order1, $sales_reclamation1); |
25 | 25 |
my ($purchase_quotation1, $purchase_order1, $purchase_invoice1, $purchase_delivery_order1, $purchase_reclamation1); |
26 | 26 |
|
27 |
Support::TestSetup::login(); |
|
28 |
$dbh = SL::DB->client->dbh; |
|
29 |
|
|
30 |
note "testing deletions"; |
|
31 |
reset_state(); |
|
32 |
reset_basic_sales_records(); |
|
33 |
reset_basic_purchase_records(); |
|
34 |
|
|
35 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 1 ]), 2, 'number of quotations before delete ok'); |
|
36 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 0 ]), 2, 'number of orders before delete ok'); |
|
37 |
is(SL::DB::Manager::DeliveryOrder->get_all_count(), 2, 'number of delivery orders before delete ok'); |
|
38 |
is(SL::DB::Manager::Reclamation->get_all_count(), 2, 'number of reclamations before delete ok'); |
|
39 |
# is(SL::DB::Manager::Invoice->get_all_count(), 1, 'number of invoices before delete ok'); # no purchase_invoice was created |
|
40 |
|
|
41 |
foreach my $record ( ($sales_quotation1, |
|
42 |
$sales_order1, |
|
43 |
$sales_reclamation1, |
|
44 |
$purchase_quotation1, |
|
45 |
$purchase_order1, |
|
46 |
$purchase_reclamation1 |
|
47 |
) |
|
48 |
) { |
|
49 |
|
|
50 |
my $delete_return = SL::Model::Record->delete($record); |
|
51 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $record->id, addition => 'DELETED'); |
|
52 |
# just test if snumbers contains "_", not whether it actually is correct |
|
53 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
|
54 |
}; |
|
55 |
|
|
56 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 1 ]), 0, 'number of quotations after delete ok'); |
|
57 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 0 ]), 0, 'number of orders after delete ok'); |
|
58 |
# is(SL::DB::Manager::Invoice->get_all_count(), 0, 'number of invoices after delete ok'); |
|
59 |
is(SL::DB::Manager::Reclamation->get_all_count(), 0, 'number of orders after delete ok'); |
|
60 |
|
|
61 |
note "testing workflows"; |
|
62 |
reset_state(); |
|
63 |
reset_basic_sales_records(); |
|
64 |
reset_basic_purchase_records(); |
|
65 |
|
|
66 |
note "testing subversion of order"; |
|
67 |
# make current version a final version, currently this is handled via frontend/controller |
|
68 |
is($sales_order1->ordnumber, "ord-01", "ordnumber before increment_subversion ok"); |
|
69 |
SL::DB::OrderVersion->new(oe_id => $sales_order1->id, version => 1, final_version => 1)->save; |
|
70 |
SL::Model::Record->increment_subversion($sales_order1); |
|
71 |
is($sales_order1->ordnumber, "ord-01-2", "ordnumber after increment_subversion ok"); |
|
72 |
is(SL::DB::Manager::Order->get_all_count(where => [quotation => 0]), 2, 'number of orders after incremented subversion ok'); |
|
73 |
|
|
74 |
|
|
75 |
note "testing new_from_workflow for quotation"; |
|
76 |
foreach my $target_record_type ( qw(sales_order sales_delivery_order) ) { |
|
77 |
# TODO: invoice |
|
78 |
note " testing from quotation -> $target_record_type"; |
|
79 |
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type); |
|
80 |
|
|
81 |
SL::Model::Record->save($new_record); |
|
82 |
$new_record->load; |
|
83 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount'); |
|
84 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, addition => 'SAVED'); |
|
85 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
|
86 |
test_record_links($new_record, "converted $target_record_type"); |
|
87 |
}; |
|
88 |
|
|
89 |
note "testing new_from_workflow for order"; |
|
90 |
foreach my $target_record_type ( qw(sales_delivery_order sales_reclamation) ) { |
|
91 |
# TODO: invoice |
|
92 |
note " testing from quotation -> $target_record_type"; |
|
93 |
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type); |
|
94 |
if ( 'SL::DB::Reclamation' eq ref($new_record) ) { |
|
95 |
$_->reason($reclamation_reason) foreach @{ $new_record->items }; |
|
96 |
}; |
|
97 |
SL::Model::Record->save($new_record); |
|
98 |
$new_record->load; |
|
99 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_type, addition => 'SAVED'); |
|
100 |
|
|
101 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
|
102 |
|
|
103 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount'); |
|
104 |
test_record_links($new_record, "converted $target_record_type"); |
|
105 |
}; |
|
106 |
|
|
107 |
note ('testing multi'); |
|
108 |
reset_state(); |
|
109 |
reset_basic_sales_records(); |
|
110 |
reset_basic_purchase_records(); |
|
111 |
|
|
112 |
note('combining several sales orders to one combined order'); |
|
113 |
my @sales_orders; |
|
114 |
push(@sales_orders, SL::Model::Record->new_from_workflow($sales_quotation1, 'sales_order')->save->load) for 1 .. 3; |
|
115 |
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, 'sales_order', sort_sources_by => 'transdate'); |
|
116 |
SL::Model::Record->save($combined_order); |
|
117 |
cmp_ok($combined_order->netamount, '==', 3*710, "netamount of combined order ok"); |
|
118 |
|
|
119 |
die; |
|
120 |
|
|
121 |
clear_up(); |
|
122 |
done_testing; |
|
123 |
|
|
124 |
sub test_record_links { |
|
125 |
my $record = shift; |
|
126 |
my $text = shift; |
|
127 |
|
|
128 |
is(@{ $record->linked_records }, 1, "1 record link for $text created ok"); # just check if one exists, not if it is actually correct |
|
129 |
my $number_of_item_record_links; |
|
130 |
foreach my $item ( @{ $record->items } ) { |
|
131 |
$number_of_item_record_links += scalar @{ $item->linked_records }; |
|
132 |
}; |
|
133 |
is($number_of_item_record_links, 2, "2 record links for $text items created ok"); # just check if they exist, not if they are actually correct |
|
134 |
} |
|
135 |
|
|
27 | 136 |
sub clear_up { |
28 | 137 |
foreach (qw(InvoiceItem Invoice |
29 | 138 |
DeliveryOrderItem DeliveryOrder |
... | ... | |
38 | 147 |
}; |
39 | 148 |
|
40 | 149 |
sub reset_basic_sales_records { |
41 |
$dbh->do("UPDATE defaults SET sonumber = 'ord-00', sqnumber = 'quo-00', sdonumber = 'do-00'"); |
|
150 |
$dbh->do("UPDATE defaults SET sonumber = 'ord-00', sqnumber = 'quo-00', sdonumber = 'do-00', s_reclamation_record_number = 'srecl-00'");
|
|
42 | 151 |
|
43 | 152 |
$sales_quotation1 = create_sales_quotation( |
44 |
save => 1, |
|
45 |
customer => $customer, |
|
46 |
taxincluded => 0, |
|
153 |
save => 1, |
|
154 |
customer => $customer, |
|
47 | 155 |
orderitems => [ create_order_item(part => $parts[0], qty => 3, sellprice => 70), |
48 | 156 |
create_order_item(part => $parts[1], qty => 10, sellprice => 50), |
49 | 157 |
] |
50 | 158 |
); |
51 | 159 |
|
52 | 160 |
$sales_order1 = create_sales_order( |
53 |
save => 1, |
|
54 |
customer => $customer, |
|
55 |
taxincluded => 0, |
|
161 |
save => 1, |
|
162 |
customer => $customer, |
|
56 | 163 |
orderitems => [ create_order_item(part => $parts[0], qty => 3, sellprice => 70), |
57 | 164 |
create_order_item(part => $parts[1], qty => 10, sellprice => 50), |
58 | 165 |
] |
59 | 166 |
); |
60 | 167 |
|
61 | 168 |
$sales_delivery_order1 = create_sales_delivery_order( |
62 |
save => 1, |
|
63 |
customer => $customer, |
|
64 |
taxincluded => 0, |
|
169 |
save => 1, |
|
170 |
customer => $customer, |
|
65 | 171 |
orderitems => [ create_delivery_order_item(part => $parts[0], qty => 3, sellprice => 70), |
66 | 172 |
create_delivery_order_item(part => $parts[1], qty => 10, sellprice => 50), |
67 | 173 |
] |
68 | 174 |
); |
69 | 175 |
|
70 | 176 |
$sales_reclamation1 = create_sales_reclamation( |
71 |
save => 1, |
|
72 |
# customer => $customer, |
|
73 |
employee => $employee, |
|
74 |
taxincluded => 0, |
|
177 |
save => 1, |
|
178 |
employee => $employee, |
|
75 | 179 |
reclamation_items => [ create_reclamation_item(part => $parts[0], qty => 3, sellprice => 70, reason => $reclamation_reason), |
76 | 180 |
create_reclamation_item(part => $parts[1], qty => 10, sellprice => 50, reason => $reclamation_reason), |
77 | 181 |
] |
... | ... | |
81 | 185 |
# $sales_invoice1 = create_sales_invoice( |
82 | 186 |
# save => 1, |
83 | 187 |
# customer => $customer, |
84 |
# taxincluded => 0, |
|
85 | 188 |
# invoiceitems => [ create_invoice_item(part => $parts[0], qty => 3, sellprice => 70), |
86 | 189 |
# create_invoice_item(part => $parts[1], qty => 10, sellprice => 50), |
87 | 190 |
# ] |
... | ... | |
89 | 192 |
} |
90 | 193 |
|
91 | 194 |
sub reset_basic_purchase_records { |
92 |
$dbh->do("UPDATE defaults SET rfqnumber = 'rfq-00', ponumber = 'po-00', pdonumber = 'pdo-00'"); |
|
195 |
$dbh->do("UPDATE defaults SET rfqnumber = 'rfq-00', ponumber = 'po-00', pdonumber = 'pdo-00', p_reclamation_record_number = 'precl-00'");
|
|
93 | 196 |
|
94 | 197 |
$purchase_quotation1 = create_purchase_quotation ( |
95 | 198 |
save => 1, |
96 | 199 |
vendor => $vendor, |
97 |
taxincluded => 0, |
|
98 | 200 |
orderitems => [ create_order_item(part => $parts[0], qty => 3, sellprice => 70), |
99 | 201 |
create_order_item(part => $parts[1], qty => 10, sellprice => 50), |
100 | 202 |
] |
... | ... | |
103 | 205 |
$purchase_order1 = create_purchase_order ( |
104 | 206 |
save => 1, |
105 | 207 |
vendor => $vendor, |
106 |
taxincluded => 0, |
|
107 | 208 |
orderitems => [ create_order_item(part => $parts[0], qty => 3, sellprice => 70), |
108 | 209 |
create_order_item(part => $parts[1], qty => 10, sellprice => 50), |
109 | 210 |
] |
110 | 211 |
); |
111 | 212 |
|
112 | 213 |
$purchase_delivery_order1 = create_purchase_delivery_order( |
113 |
save => 1, |
|
114 |
vendor => $vendor, |
|
115 |
taxincluded => 0, |
|
214 |
save => 1, |
|
215 |
vendor => $vendor, |
|
116 | 216 |
orderitems => [ create_delivery_order_item(part => $parts[0], qty => 3, sellprice => 70), |
117 | 217 |
create_delivery_order_item(part => $parts[1], qty => 10, sellprice => 50), |
118 | 218 |
] |
... | ... | |
120 | 220 |
|
121 | 221 |
$purchase_reclamation1 = create_purchase_reclamation( |
122 | 222 |
save => 1, |
123 |
# vendor => $vendor, |
|
124 | 223 |
employee => $employee, |
125 |
taxincluded => 0, |
|
126 | 224 |
reclamation_items => [ create_reclamation_item(part => $parts[0], qty => 3, sellprice => 70, reason => $reclamation_reason), |
127 | 225 |
create_reclamation_item(part => $parts[1], qty => 10, sellprice => 50, reason => $reclamation_reason), |
128 | 226 |
] |
... | ... | |
172 | 270 |
|
173 | 271 |
} |
174 | 272 |
|
175 |
Support::TestSetup::login(); |
|
176 |
$dbh = SL::DB->client->dbh; |
|
177 |
|
|
178 |
clear_up(); |
|
179 |
reset_state(); |
|
180 |
reset_basic_sales_records(); |
|
181 |
reset_basic_purchase_records(); |
|
182 |
|
|
183 |
note "testing deletions"; |
|
184 |
|
|
185 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 1 ]), 2, 'number of quotations before delete ok'); |
|
186 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 0 ]), 2, 'number of orders before delete ok'); |
|
187 |
is(SL::DB::Manager::DeliveryOrder->get_all_count(), 2, 'number of delivery orders before delete ok'); |
|
188 |
is(SL::DB::Manager::Reclamation->get_all_count(), 2, 'number of reclamations before delete ok'); |
|
189 |
# is(SL::DB::Manager::Invoice->get_all_count(), 1, 'number of invoices before delete ok'); # no purchase_invoice was created |
|
190 |
|
|
191 |
foreach my $record ( ($sales_quotation1, |
|
192 |
$sales_order1, |
|
193 |
$sales_reclamation1, |
|
194 |
$purchase_quotation1, |
|
195 |
$purchase_order1, |
|
196 |
$purchase_reclamation1 |
|
197 |
) |
|
198 |
) { |
|
199 |
|
|
200 |
my $delete_return = SL::Model::Record->delete($record); |
|
201 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $record->id, addition => 'DELETED'); |
|
202 |
# just test if snumbers contains "_", not whether it actually is correct |
|
203 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
|
204 |
}; |
|
205 |
|
|
206 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 1 ]), 0, 'number of quotations after delete ok'); |
|
207 |
is(SL::DB::Manager::Order->get_all_count(where => [ quotation => 0 ]), 0, 'number of orders after delete ok'); |
|
208 |
# is(SL::DB::Manager::Invoice->get_all_count(), 0, 'number of invoices after delete ok'); |
|
209 |
is(SL::DB::Manager::Reclamation->get_all_count(), 0, 'number of orders after delete ok'); |
|
210 |
|
|
211 |
note "testing workflows"; |
|
212 |
reset_state(); |
|
213 |
reset_basic_sales_records(); |
|
214 |
reset_basic_purchase_records(); |
|
215 |
|
|
216 |
note "testing subversion of order"; |
|
217 |
# make current version a final version, currently this is handled via frontend/controller |
|
218 |
is($sales_order1->ordnumber, "ord-01", "ordnumber before increment_subversion ok"); |
|
219 |
SL::DB::OrderVersion->new(oe_id => $sales_order1->id, version => 1, final_version => 1)->save; |
|
220 |
SL::Model::Record->increment_subversion($sales_order1); |
|
221 |
is($sales_order1->ordnumber, "ord-01-2", "ordnumber after increment_subversion ok"); |
|
222 |
is(SL::DB::Manager::Order->get_all_count(where => [quotation => 0]), 2, 'number of orders after incremented subversion ok'); |
|
223 |
|
|
224 |
|
|
225 |
note "testing new_from_workflow for quotation"; |
|
226 |
foreach my $target_record_type ( qw(sales_order sales_delivery_order) ) { |
|
227 |
# TODO: invoice |
|
228 |
note " testing from quotation -> $target_record_type"; |
|
229 |
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type); |
|
230 |
|
|
231 |
SL::Model::Record->save($new_record); |
|
232 |
$new_record->load; |
|
233 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount'); |
|
234 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, addition => 'SAVED'); |
|
235 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
|
236 |
test_record_links($new_record, "converted $target_record_type"); |
|
237 |
}; |
|
238 |
|
|
239 |
note "testing new_from_workflow for order"; |
|
240 |
foreach my $target_record_type ( qw(sales_delivery_order sales_reclamation) ) { |
|
241 |
# TODO: invoice |
|
242 |
note " testing from quotation -> $target_record_type"; |
|
243 |
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type); |
|
244 |
if ( 'SL::DB::Reclamation' eq ref($new_record) ) { |
|
245 |
$_->reason($reclamation_reason) foreach @{ $new_record->items }; |
|
246 |
}; |
|
247 |
SL::Model::Record->save($new_record); |
|
248 |
$new_record->load; |
|
249 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_type, addition => 'SAVED'); |
|
250 |
|
|
251 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
|
252 |
|
|
253 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount'); |
|
254 |
test_record_links($new_record, "converted $target_record_type"); |
|
255 |
}; |
|
256 |
|
|
257 |
note ('testing multi'); |
|
258 |
clear_up(); |
|
259 |
reset_state(); |
|
260 |
reset_basic_sales_records(); |
|
261 |
reset_basic_purchase_records(); |
|
262 |
|
|
263 |
note('combining several sales orders to one combined order'); |
|
264 |
my @sales_orders; |
|
265 |
push(@sales_orders, SL::Model::Record->new_from_workflow($sales_quotation1, 'sales_order')->save->load) for 1 .. 3; |
|
266 |
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, 'sales_order', sort_sources_by => 'transdate'); |
|
267 |
SL::Model::Record->save($combined_order); |
|
268 |
cmp_ok($combined_order->netamount, '==', 3*710, "netamount of combined order ok"); |
|
269 |
|
|
270 |
|
|
271 |
clear_up(); |
|
272 |
done_testing; |
|
273 |
|
|
274 |
sub test_record_links { |
|
275 |
my $record = shift; |
|
276 |
my $text = shift; |
|
277 |
|
|
278 |
is(@{ $record->linked_records }, 1, "1 record link for $text created ok"); # just check if one exists, not if it is actually correct |
|
279 |
my $number_of_item_record_links; |
|
280 |
foreach my $item ( @{ $record->items } ) { |
|
281 |
$number_of_item_record_links += scalar @{ $item->linked_records }; |
|
282 |
}; |
|
283 |
is($number_of_item_record_links, 2, "2 record links for $text items created ok"); # just check if they exist, not if they are actually correct |
|
284 |
} |
|
285 |
|
|
286 | 273 |
1; |
287 | 274 |
|
288 | 275 |
# set emacs to perl mode |
Auch abrufbar als: Unified diff
t/model/records aufgeräumt und umstrukturiert