Revision 9c6751b7
Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt
SL/DB/DeliveryOrder.pm | ||
---|---|---|
21 | 21 |
|
22 | 22 |
use SL::Helper::Number qw(_format_total _round_total); |
23 | 23 |
|
24 |
use Rose::DB::Object::Helpers qw(as_tree strip); |
|
24 | 25 |
use List::Util qw(first); |
25 | 26 |
use List::MoreUtils qw(any pairwise); |
26 | 27 |
use Math::Round qw(nhimult); |
... | ... | |
205 | 206 |
); |
206 | 207 |
$record_args{cp_id} = $source->contact_id; |
207 | 208 |
$record_args{cusordnumber} = $source->cv_record_number; |
209 |
$record_args{is_sales} = $source->is_sales; |
|
208 | 210 |
# }}} for vim folds |
209 | 211 |
} |
210 | 212 |
|
SL/DB/DeliveryOrderItem.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
5 |
use Rose::DB::Object::Helpers qw(as_tree strip); |
|
6 |
|
|
5 | 7 |
use SL::DB::MetaSetup::DeliveryOrderItem; |
6 | 8 |
use SL::DB::Manager::DeliveryOrderItem; |
7 | 9 |
use SL::DB::Helper::ActsAsList; |
SL/DB/Order.pm | ||
---|---|---|
21 | 21 |
use SL::DB::Helper::TransNumberGenerator; |
22 | 22 |
use SL::Locale::String qw(t8); |
23 | 23 |
use SL::RecordLinks; |
24 |
use Rose::DB::Object::Helpers qw(as_tree); |
|
24 |
use Rose::DB::Object::Helpers qw(as_tree strip);
|
|
25 | 25 |
|
26 | 26 |
__PACKAGE__->meta->add_relationship( |
27 | 27 |
orderitems => { |
SL/DB/OrderItem.pm | ||
---|---|---|
18 | 18 |
}, |
19 | 19 |
); |
20 | 20 |
use SL::Helper::ShippedQty; |
21 |
use Rose::DB::Object::Helpers qw(as_tree strip); |
|
21 | 22 |
|
22 | 23 |
__PACKAGE__->meta->initialize; |
23 | 24 |
|
SL/DB/Reclamation.pm | ||
---|---|---|
20 | 20 |
use SL::DB::Helper::TransNumberGenerator; |
21 | 21 |
use SL::Locale::String qw(t8); |
22 | 22 |
use SL::RecordLinks; |
23 |
use Rose::DB::Object::Helpers qw(as_tree); |
|
23 |
use Rose::DB::Object::Helpers qw(as_tree strip);
|
|
24 | 24 |
|
25 | 25 |
__PACKAGE__->meta->add_relationship( |
26 | 26 |
|
... | ... | |
258 | 258 |
|
259 | 259 |
1; |
260 | 260 |
})) { |
261 |
return undef; |
|
261 |
return undef, $self->db->error->db_error->db_error;
|
|
262 | 262 |
} |
263 | 263 |
|
264 | 264 |
return $order; |
... | ... | |
296 | 296 |
return undef, $self->db->error->db_error->db_error; |
297 | 297 |
} |
298 | 298 |
|
299 |
return $delivery_order, undef;
|
|
299 |
return $delivery_order; |
|
300 | 300 |
} |
301 | 301 |
|
302 | 302 |
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden |
... | ... | |
485 | 485 |
$record_args{vendor_id} = undef; |
486 | 486 |
$record_args{salesman_id} = undef; |
487 | 487 |
$record_args{payment_id} = undef; |
488 |
$record_args{delivery_term_id} = undef; |
|
488 | 489 |
} |
489 | 490 |
|
490 | 491 |
|
SL/DB/ReclamationItem.pm | ||
---|---|---|
4 | 4 |
use strict; |
5 | 5 |
|
6 | 6 |
use List::MoreUtils qw(any); |
7 |
use Rose::DB::Object::Helpers qw(as_tree strip); |
|
7 | 8 |
|
8 | 9 |
use SL::DB::MetaSetup::ReclamationItem; |
9 | 10 |
use SL::DB::Manager::ReclamationItem; |
... | ... | |
87 | 88 |
|
88 | 89 |
my $item = $class->new(%item_args); |
89 | 90 |
|
90 |
if ( $source->record->is_sales() && ($parent_type =~ m{sales}) ) {
|
|
91 |
if ( $source->record->is_sales() && ($parent_type =~ m{purchase}) ) {
|
|
91 | 92 |
$item->sellprice($source->lastcost); |
92 | 93 |
$item->discount(0); |
93 | 94 |
} |
94 |
if ( !$source->record->is_sales() && ($parent_type =~ m{purchase}) ) {
|
|
95 |
if ( !$source->record->is_sales() && ($parent_type =~ m{sales}) ) {
|
|
95 | 96 |
$item->lastcost($source->sellprice); |
96 | 97 |
} |
97 | 98 |
|
SL/Dev/Record.pm | ||
---|---|---|
11 | 11 |
create_delivery_order_item |
12 | 12 |
create_sales_delivery_order |
13 | 13 |
create_purchase_delivery_order |
14 |
create_sales_reclamation |
|
15 |
create_purchase_reclamation |
|
14 | 16 |
create_project create_department |
15 | 17 |
create_ap_transaction |
16 | 18 |
create_ar_transaction |
... | ... | |
39 | 41 |
sales_order => 'SL::DB::OrderItem', |
40 | 42 |
purchase_order => 'SL::DB::OrderItem', |
41 | 43 |
sales_delivery_order => 'SL::DB::DeliveryOrderItem', |
44 |
purchase_delivery_order => 'SL::DB::DeliveryOrderItem', |
|
45 |
sales_reclamation => 'SL::DB::ReclamationItem', |
|
46 |
purchase_reclamation => 'SL::DB::ReclamationItem', |
|
42 | 47 |
); |
43 | 48 |
|
44 | 49 |
sub create_sales_invoice { |
... | ... | |
223 | 228 |
return $order; |
224 | 229 |
}; |
225 | 230 |
|
231 |
sub create_sales_reclamation { |
|
232 |
my (%params) = @_; |
|
233 |
|
|
234 |
my $record_type = 'sales_reclamation'; |
|
235 |
my $reclamation_items = delete $params{reclamation_items} // _create_two_items($record_type); |
|
236 |
_check_items($reclamation_items, $record_type); |
|
237 |
|
|
238 |
my $save = delete $params{save} // 0; |
|
239 |
|
|
240 |
my $customer = $params{customer} // new_customer(name => 'Test_Customer')->save; |
|
241 |
die "'customer' is not of type SL::DB::Customer" unless ref($customer) eq 'SL::DB::Customer'; |
|
242 |
|
|
243 |
my $reclamation = SL::DB::Reclamation->new( |
|
244 |
customer_id => delete $params{customer_id} // $customer->id, |
|
245 |
taxzone_id => delete $params{taxzone_id} // $customer->taxzone->id, |
|
246 |
currency_id => delete $params{currency_id} // $::instance_conf->get_currency_id, |
|
247 |
taxincluded => delete $params{taxincluded} // 0, |
|
248 |
transdate => delete $params{transdate} // DateTime->today, |
|
249 |
'closed' => undef, |
|
250 |
reclamation_items => $reclamation_items, |
|
251 |
); |
|
252 |
$reclamation->assign_attributes(%params) if %params; |
|
253 |
|
|
254 |
if ( $save ) { |
|
255 |
$reclamation->calculate_prices_and_taxes; # not tested |
|
256 |
$reclamation->save; |
|
257 |
} |
|
258 |
return $reclamation; |
|
259 |
} |
|
260 |
|
|
261 |
sub create_purchase_reclamation { |
|
262 |
my (%params) = @_; |
|
263 |
|
|
264 |
my $record_type = 'sales_reclamation'; |
|
265 |
my $reclamation_items = delete $params{reclamation_items} // _create_two_items($record_type); |
|
266 |
_check_items($reclamation_items, $record_type); |
|
267 |
|
|
268 |
my $save = delete $params{save} // 0; |
|
269 |
|
|
270 |
my $vendor = $params{vendor} // new_vendor(name => 'Test_Vendor')->save; |
|
271 |
die "'vendor' is not of type SL::DB::Vendor" unless ref($vendor) eq 'SL::DB::Vendor'; |
|
272 |
|
|
273 |
my $reclamation = SL::DB::Reclamation->new( |
|
274 |
vendor_id => delete $params{vendor_id} // $vendor->id, |
|
275 |
taxzone_id => delete $params{taxzone_id} // $vendor->taxzone->id, |
|
276 |
currency_id => delete $params{currency_id} // $::instance_conf->get_currency_id, |
|
277 |
taxincluded => delete $params{taxincluded} // 0, |
|
278 |
transdate => delete $params{transdate} // DateTime->today, |
|
279 |
'closed' => undef, |
|
280 |
reclamation_items => $reclamation_items, |
|
281 |
); |
|
282 |
$reclamation->assign_attributes(%params) if %params; |
|
283 |
|
|
284 |
if ( $save ) { |
|
285 |
$reclamation->calculate_prices_and_taxes; # not tested |
|
286 |
$reclamation->save; |
|
287 |
} |
|
288 |
return $reclamation; |
|
289 |
} |
|
290 |
|
|
226 | 291 |
sub _check_items { |
227 | 292 |
my ($items, $record_type) = @_; |
228 | 293 |
|
... | ... | |
249 | 314 |
return _create_item(record_type => 'sales_delivery_order', %params); |
250 | 315 |
} |
251 | 316 |
|
317 |
sub create_reclamation_item { |
|
318 |
my (%params) = @_; |
|
319 |
|
|
320 |
# record_type can be sales or purchase; make sure one is set |
|
321 |
return _create_item(record_type => 'sales_reclamation', %params); |
|
322 |
} |
|
323 |
|
|
252 | 324 |
sub _create_item { |
253 | 325 |
my (%params) = @_; |
254 | 326 |
|
js/kivi.Reclamation.js | ||
---|---|---|
735 | 735 |
$('<input type="hidden" name="use_shipto">').appendTo('#reclamation_form').val('1'); |
736 | 736 |
} |
737 | 737 |
|
738 |
kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/purchase_reclamation'); |
|
738 |
kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/save_and_purchase_reclamation');
|
|
739 | 739 |
}; |
740 | 740 |
|
741 | 741 |
ns.direct_delivery_dialog = function(shipto) { |
t/workflow/delivery_order_reclamation.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 Data::Compare; |
|
11 |
use Support::TestSetup; |
|
12 |
use Test::Exception; |
|
13 |
use List::Util qw(zip); |
|
14 |
|
|
15 |
use SL::DB::DeliveryOrder; |
|
16 |
use SL::DB::Reclamation; |
|
17 |
use SL::DB::ReclamationReason; |
|
18 |
use SL::DB::Customer; |
|
19 |
use SL::DB::Vendor; |
|
20 |
use SL::DB::Department; |
|
21 |
use SL::DB::Currency; |
|
22 |
use SL::DB::PaymentTerm; |
|
23 |
use SL::DB::DeliveryTerm; |
|
24 |
use SL::DB::Employee; |
|
25 |
use SL::DB::Part; |
|
26 |
use SL::DB::Unit; |
|
27 |
|
|
28 |
use Rose::DB::Object::Helpers qw(clone); |
|
29 |
|
|
30 |
use SL::Dev::ALL qw(:ALL); |
|
31 |
|
|
32 |
my ( |
|
33 |
$customer, $vendor, |
|
34 |
$employee, |
|
35 |
$payment_term, |
|
36 |
$delivery_term, |
|
37 |
$unit, |
|
38 |
@parts, |
|
39 |
$department, |
|
40 |
$relamation_reason, |
|
41 |
); |
|
42 |
|
|
43 |
|
|
44 |
sub clear_up { |
|
45 |
foreach (qw( |
|
46 |
DeliveryOrder DeliveryOrderItem |
|
47 |
Reclamation ReclamationItem |
|
48 |
Part |
|
49 |
Customer Vendor |
|
50 |
Department PaymentTerm DeliveryTerm |
|
51 |
)) { |
|
52 |
"SL::DB::Manager::${_}"->delete_all(all => 1); |
|
53 |
} |
|
54 |
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]); |
|
55 |
}; |
|
56 |
|
|
57 |
sub reset_state { |
|
58 |
my %params = @_; |
|
59 |
|
|
60 |
clear_up(); |
|
61 |
|
|
62 |
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'"; |
|
63 |
|
|
64 |
$employee = SL::DB::Employee->new( |
|
65 |
'login' => 'testuser', |
|
66 |
'name' => 'Test User', |
|
67 |
)->save; |
|
68 |
|
|
69 |
$department = SL::DB::Department->new( |
|
70 |
'description' => 'Test Department', |
|
71 |
)->save; |
|
72 |
|
|
73 |
$payment_term = create_payment_terms( |
|
74 |
'description' => '14Tage 2%Skonto, 30Tage netto', |
|
75 |
'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.", |
|
76 |
'percent_skonto' => '0.02', |
|
77 |
'terms_netto' => 30, |
|
78 |
'terms_skonto' => 14 |
|
79 |
); |
|
80 |
|
|
81 |
$delivery_term = SL::DB::DeliveryTerm->new( |
|
82 |
'description' => 'Test Delivey Term', |
|
83 |
'description_long' => 'Test Delivey Term Test Delivey Term', |
|
84 |
)->save; |
|
85 |
|
|
86 |
# some parts/services |
|
87 |
@parts = (); |
|
88 |
push @parts, new_part( |
|
89 |
partnumber => 'Part_1_KG', |
|
90 |
unit => $unit->name, |
|
91 |
)->save; |
|
92 |
push @parts, new_service( |
|
93 |
partnumber => 'Serv_1', |
|
94 |
)->save; |
|
95 |
push @parts, new_part( |
|
96 |
partnumber => 'Part_2', |
|
97 |
)->save; |
|
98 |
push @parts, new_service( |
|
99 |
partnumber => 'Serv_2' |
|
100 |
)->save; |
|
101 |
|
|
102 |
$relamation_reason = SL::DB::ReclamationReason->new( |
|
103 |
name => "test_reason", |
|
104 |
description => "", |
|
105 |
position => 1, |
|
106 |
); |
|
107 |
} |
|
108 |
|
|
109 |
Support::TestSetup::login(); |
|
110 |
|
|
111 |
reset_state(); |
|
112 |
|
|
113 |
##### |
|
114 |
|
|
115 |
my $sales_reclamation = SL::Dev::Record::create_sales_reclamation( |
|
116 |
save => 1, |
|
117 |
employee => $employee, |
|
118 |
shippingpoint => "sp", |
|
119 |
transaction_description => "td1", |
|
120 |
payment => $payment_term, |
|
121 |
delivery_term => $delivery_term, |
|
122 |
taxincluded => 0, |
|
123 |
reclamation_items => [ |
|
124 |
SL::Dev::Record::create_reclamation_item( |
|
125 |
part => $parts[0], qty => 3, sellprice => 70, |
|
126 |
reason => $relamation_reason, |
|
127 |
), |
|
128 |
SL::Dev::Record::create_reclamation_item( |
|
129 |
part => $parts[1], qty => 10, sellprice => 50, |
|
130 |
reason => $relamation_reason, |
|
131 |
), |
|
132 |
], |
|
133 |
)->load; |
|
134 |
|
|
135 |
my $purchase_reclamation = SL::Dev::Record::create_purchase_reclamation( |
|
136 |
save => 1, |
|
137 |
employee => $employee, |
|
138 |
shippingpoint => "sp", |
|
139 |
transaction_description => "td2", |
|
140 |
payment => $payment_term, |
|
141 |
delivery_term => $delivery_term, |
|
142 |
taxincluded => 0, |
|
143 |
reclamation_items => [ |
|
144 |
SL::Dev::Record::create_reclamation_item( |
|
145 |
part => $parts[0], qty => 3, sellprice => 70, |
|
146 |
reason => $relamation_reason, |
|
147 |
), |
|
148 |
SL::Dev::Record::create_reclamation_item( |
|
149 |
part => $parts[1], qty => 10, sellprice => 50, |
|
150 |
reason => $relamation_reason, |
|
151 |
), |
|
152 |
], |
|
153 |
)->load; |
|
154 |
|
|
155 |
|
|
156 |
my $sales_delivery_order = SL::Dev::Record::create_sales_delivery_order( |
|
157 |
save => 1, |
|
158 |
employee => $employee, |
|
159 |
shippingpoint => "sp", |
|
160 |
transaction_description => "td3", |
|
161 |
payment_terms => $payment_term, |
|
162 |
delivery_term => $delivery_term, |
|
163 |
taxincluded => 0, |
|
164 |
is_sales => 1, |
|
165 |
orderitems => [ SL::Dev::Record::create_delivery_order_item(part => $parts[0], qty => 3, sellprice => 70), |
|
166 |
SL::Dev::Record::create_delivery_order_item(part => $parts[1], qty => 10, sellprice => 50), |
|
167 |
] |
|
168 |
)->load; |
|
169 |
|
|
170 |
my $purchase_delivery_order = SL::Dev::Record::create_purchase_delivery_order( |
|
171 |
save => 1, |
|
172 |
employee => $employee, |
|
173 |
shippingpoint => "sp", |
|
174 |
transaction_description => "td4", |
|
175 |
payment_terms => $payment_term, |
|
176 |
delivery_term => $delivery_term, |
|
177 |
taxincluded => 0, |
|
178 |
is_sales => 0, |
|
179 |
orderitems => [ SL::Dev::Record::create_delivery_order_item(part => $parts[0], qty => 3, sellprice => 70), |
|
180 |
SL::Dev::Record::create_delivery_order_item(part => $parts[1], qty => 10, sellprice => 50), |
|
181 |
] |
|
182 |
)->load; |
|
183 |
|
|
184 |
# convert order → reclamation |
|
185 |
my $converted_sales_reclamation = $sales_delivery_order->convert_to_reclamation; |
|
186 |
$converted_sales_reclamation->items_sorted->[0]->reason($relamation_reason); |
|
187 |
$converted_sales_reclamation->items_sorted->[1]->reason($relamation_reason); |
|
188 |
$converted_sales_reclamation->save->load; |
|
189 |
my $converted_purchase_reclamation = $purchase_delivery_order->convert_to_reclamation; |
|
190 |
$converted_purchase_reclamation->items_sorted->[0]->reason($relamation_reason); |
|
191 |
$converted_purchase_reclamation->items_sorted->[1]->reason($relamation_reason); |
|
192 |
$converted_purchase_reclamation->save->load; |
|
193 |
|
|
194 |
# convert reclamation → order |
|
195 |
my $converted_sales_delivery_order = $sales_reclamation->convert_to_delivery_order->save->load; |
|
196 |
my $converted_purchase_delivery_order = $purchase_reclamation->convert_to_delivery_order->save->load; |
|
197 |
|
|
198 |
|
|
199 |
#get items before strip |
|
200 |
my @purchase_reclamation_items = $purchase_reclamation->items_sorted; |
|
201 |
my @sales_reclamation_items = $sales_reclamation->items_sorted; |
|
202 |
my @converted_purchase_reclamation_items = $converted_purchase_reclamation->items_sorted; |
|
203 |
my @converted_sales_reclamation_items = $converted_sales_reclamation->items_sorted; |
|
204 |
my @purchase_delivery_order_items = $purchase_delivery_order->items_sorted; |
|
205 |
my @sales_delivery_order_items = $sales_delivery_order->items_sorted; |
|
206 |
my @converted_purchase_delivery_order_items = $converted_purchase_delivery_order->items_sorted; |
|
207 |
my @converted_sales_delivery_order_items = $converted_sales_delivery_order->items_sorted; |
|
208 |
|
|
209 |
|
|
210 |
### TESTS ##################################################################### |
|
211 |
|
|
212 |
## created sales und purchase reclamation should be nearly the same |
|
213 |
my $sales_reclamation_tmp = clone($sales_reclamation); |
|
214 |
my $purchase_reclamation_tmp = clone($purchase_reclamation); |
|
215 |
# clean different values |
|
216 |
foreach (qw( |
|
217 |
customer_id vendor_id |
|
218 |
id record_number |
|
219 |
salesman_id |
|
220 |
transaction_description |
|
221 |
itime mtime |
|
222 |
)) { |
|
223 |
$sales_reclamation_tmp->$_(undef); |
|
224 |
$purchase_reclamation_tmp->$_(undef); |
|
225 |
} |
|
226 |
foreach my $pair (zip(@purchase_reclamation_items, @sales_reclamation_items)) { |
|
227 |
my ($first, $second) = @{$pair}; |
|
228 |
my $first_tmp = clone($first); |
|
229 |
my $second_tmp = clone($second); |
|
230 |
foreach (qw( |
|
231 |
id reclamation_id |
|
232 |
itime mtime |
|
233 |
)) { |
|
234 |
$first_tmp->$_(undef); |
|
235 |
$second_tmp->$_(undef); |
|
236 |
} |
|
237 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
238 |
} |
|
239 |
is_deeply($purchase_reclamation_tmp->strip->as_tree, $sales_reclamation_tmp->strip->as_tree); |
|
240 |
|
|
241 |
## created sales und purchase delivery_order should be nearly the same |
|
242 |
my $sales_delivery_order_tmp = clone($sales_delivery_order); |
|
243 |
my $purchase_delivery_order_tmp = clone($purchase_delivery_order); |
|
244 |
# clean different values |
|
245 |
foreach (qw( |
|
246 |
customer_id vendor_id |
|
247 |
id is_sales order_type |
|
248 |
donumber salesman_id |
|
249 |
transaction_description |
|
250 |
itime mtime |
|
251 |
)) { |
|
252 |
$sales_delivery_order_tmp->$_(undef); |
|
253 |
$purchase_delivery_order_tmp->$_(undef); |
|
254 |
} |
|
255 |
foreach my $pair (zip(@purchase_delivery_order_items, @sales_delivery_order_items)) { |
|
256 |
my ($first, $second) = @{$pair}; |
|
257 |
my $first_tmp = clone($first); |
|
258 |
my $second_tmp = clone($second); |
|
259 |
foreach (qw( |
|
260 |
id delivery_order_id |
|
261 |
itime mtime |
|
262 |
)) { |
|
263 |
$first_tmp->$_(undef); |
|
264 |
$second_tmp->$_(undef); |
|
265 |
} |
|
266 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
267 |
} |
|
268 |
is_deeply($purchase_delivery_order_tmp->strip->as_tree, $sales_delivery_order_tmp->strip->as_tree); |
|
269 |
|
|
270 |
|
|
271 |
## converted have to be linked to parent |
|
272 |
# sales |
|
273 |
my $linked_sales_delivery_order = $converted_sales_reclamation->linked_records->[0]; |
|
274 |
my $linked_sales_reclamation = $converted_sales_delivery_order->linked_records->[0]; |
|
275 |
is_deeply($linked_sales_delivery_order->strip->as_tree, $sales_delivery_order->strip->as_tree); |
|
276 |
is_deeply($linked_sales_reclamation->strip->as_tree, $sales_reclamation->load->strip->as_tree); |
|
277 |
|
|
278 |
# purchase |
|
279 |
my $linked_purchase_delivery_order = $converted_purchase_reclamation->linked_records->[0]; |
|
280 |
my $linked_purchase_reclamation = $converted_purchase_delivery_order->linked_records->[0]; |
|
281 |
is_deeply($linked_purchase_delivery_order->strip->as_tree, $purchase_delivery_order->strip->as_tree); |
|
282 |
is_deeply($linked_purchase_reclamation->strip->as_tree, $purchase_reclamation->load->strip->as_tree); |
|
283 |
|
|
284 |
|
|
285 |
## converted should be nealy the same |
|
286 |
# sales |
|
287 |
foreach my $pair (zip(@sales_delivery_order_items, @converted_sales_reclamation_items)) { |
|
288 |
my ($first, $second) = @{$pair}; |
|
289 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
290 |
id delivery_order_id reclamation_id itime mtime |
|
291 |
cusordnumber marge_price_factor ordnumber transdate |
|
292 |
description reason_description_ext reason_description_int reason_id |
|
293 |
)]}); |
|
294 |
} |
|
295 |
ok Compare($sales_delivery_order->strip->as_tree, $converted_sales_reclamation->strip->as_tree, {ignore_hash_keys => [qw( |
|
296 |
id employee_id itime mtime reqdate |
|
297 |
is_sales order_type ordnumber oreqnumber |
|
298 |
amount exchangerate netamount |
|
299 |
cp_id contact_id |
|
300 |
cusordnumber cv_record_number |
|
301 |
donumber record_number |
|
302 |
)]}); |
|
303 |
|
|
304 |
foreach my $pair (zip(@sales_reclamation_items, @converted_sales_delivery_order_items)) { |
|
305 |
my ($first, $second) = @{$pair}; |
|
306 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
307 |
id delivery_order_id reclamation_id itime mtime |
|
308 |
cusordnumber marge_price_factor ordnumber transdate |
|
309 |
description reason_description_ext reason_description_int reason_id |
|
310 |
)]}); |
|
311 |
} |
|
312 |
ok Compare($sales_reclamation->strip->as_tree, $converted_sales_delivery_order->strip->as_tree, {ignore_hash_keys => [qw( |
|
313 |
id employee_id itime mtime delivered reqdate |
|
314 |
is_sales order_type ordnumber oreqnumber |
|
315 |
amount exchangerate netamount |
|
316 |
cp_id contact_id |
|
317 |
cusordnumber cv_record_number |
|
318 |
donumber record_number |
|
319 |
)]}); |
|
320 |
|
|
321 |
|
|
322 |
# purchase |
|
323 |
foreach my $pair (zip(@purchase_delivery_order_items, @converted_purchase_reclamation_items)) { |
|
324 |
my ($first, $second) = @{$pair}; |
|
325 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
326 |
id delivery_order_id reclamation_id itime mtime |
|
327 |
cusordnumber marge_price_factor ordnumber transdate |
|
328 |
description reason_description_ext reason_description_int reason_id |
|
329 |
)]}); |
|
330 |
} |
|
331 |
ok Compare($purchase_delivery_order->strip->as_tree, $converted_purchase_reclamation->strip->as_tree, {ignore_hash_keys => [qw( |
|
332 |
id employee_id itime mtime reqdate |
|
333 |
is_sales order_type ordnumber oreqnumber |
|
334 |
amount exchangerate netamount |
|
335 |
cp_id contact_id |
|
336 |
cusordnumber cv_record_number |
|
337 |
donumber record_number |
|
338 |
)]}); |
|
339 |
|
|
340 |
foreach my $pair (zip(@purchase_reclamation_items, @converted_purchase_delivery_order_items)) { |
|
341 |
my ($first, $second) = @{$pair}; |
|
342 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
343 |
id delivery_order_id reclamation_id itime mtime |
|
344 |
cusordnumber marge_price_factor ordnumber transdate |
|
345 |
description reason_description_ext reason_description_int reason_id |
|
346 |
)]}); |
|
347 |
} |
|
348 |
ok Compare($purchase_reclamation->strip->as_tree, $converted_purchase_delivery_order->strip->as_tree, {ignore_hash_keys => [qw( |
|
349 |
id employee_id itime mtime delivered reqdate |
|
350 |
is_sales order_type ordnumber oreqnumber |
|
351 |
amount exchangerate netamount |
|
352 |
cp_id contact_id |
|
353 |
cusordnumber cv_record_number |
|
354 |
donumber record_number |
|
355 |
)]}); |
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
#diag Dumper($purchase_reclamation->strip->as_tree); |
|
360 |
#diag Dumper($linked_purchase_reclamation->strip->as_tree); |
|
361 |
|
|
362 |
|
|
363 |
#### |
|
364 |
clear_up(); |
|
365 |
|
|
366 |
done_testing; |
|
367 |
|
|
368 |
1; |
t/workflow/order_reclamation.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 Data::Compare; |
|
11 |
use Support::TestSetup; |
|
12 |
use Test::Exception; |
|
13 |
use List::Util qw(zip); |
|
14 |
|
|
15 |
use SL::DB::Order; |
|
16 |
use SL::DB::Reclamation; |
|
17 |
use SL::DB::ReclamationReason; |
|
18 |
use SL::DB::Customer; |
|
19 |
use SL::DB::Vendor; |
|
20 |
use SL::DB::Department; |
|
21 |
use SL::DB::Currency; |
|
22 |
use SL::DB::PaymentTerm; |
|
23 |
use SL::DB::DeliveryTerm; |
|
24 |
use SL::DB::Employee; |
|
25 |
use SL::DB::Part; |
|
26 |
use SL::DB::Unit; |
|
27 |
|
|
28 |
use Rose::DB::Object::Helpers qw(clone); |
|
29 |
|
|
30 |
use SL::Dev::ALL qw(:ALL); |
|
31 |
|
|
32 |
my ( |
|
33 |
$customer, $vendor, |
|
34 |
$employee, |
|
35 |
$payment_term, |
|
36 |
$delivery_term, |
|
37 |
$unit, |
|
38 |
@parts, |
|
39 |
$department, |
|
40 |
$relamation_reason, |
|
41 |
); |
|
42 |
|
|
43 |
|
|
44 |
sub clear_up { |
|
45 |
foreach (qw( |
|
46 |
Order OrderItem |
|
47 |
Reclamation ReclamationItem |
|
48 |
Part |
|
49 |
Customer Vendor |
|
50 |
Department PaymentTerm DeliveryTerm |
|
51 |
)) { |
|
52 |
"SL::DB::Manager::${_}"->delete_all(all => 1); |
|
53 |
} |
|
54 |
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]); |
|
55 |
}; |
|
56 |
|
|
57 |
sub reset_state { |
|
58 |
my %params = @_; |
|
59 |
|
|
60 |
clear_up(); |
|
61 |
|
|
62 |
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'"; |
|
63 |
|
|
64 |
$employee = SL::DB::Employee->new( |
|
65 |
'login' => 'testuser', |
|
66 |
'name' => 'Test User', |
|
67 |
)->save; |
|
68 |
|
|
69 |
$department = SL::DB::Department->new( |
|
70 |
'description' => 'Test Department', |
|
71 |
)->save; |
|
72 |
|
|
73 |
$payment_term = create_payment_terms( |
|
74 |
'description' => '14Tage 2%Skonto, 30Tage netto', |
|
75 |
'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.", |
|
76 |
'percent_skonto' => '0.02', |
|
77 |
'terms_netto' => 30, |
|
78 |
'terms_skonto' => 14 |
|
79 |
); |
|
80 |
|
|
81 |
$delivery_term = SL::DB::DeliveryTerm->new( |
|
82 |
'description' => 'Test Delivey Term', |
|
83 |
'description_long' => 'Test Delivey Term Test Delivey Term', |
|
84 |
)->save; |
|
85 |
|
|
86 |
# some parts/services |
|
87 |
@parts = (); |
|
88 |
push @parts, new_part( |
|
89 |
partnumber => 'Part_1_KG', |
|
90 |
unit => $unit->name, |
|
91 |
)->save; |
|
92 |
push @parts, new_service( |
|
93 |
partnumber => 'Serv_1', |
|
94 |
)->save; |
|
95 |
push @parts, new_part( |
|
96 |
partnumber => 'Part_2', |
|
97 |
)->save; |
|
98 |
push @parts, new_service( |
|
99 |
partnumber => 'Serv_2' |
|
100 |
)->save; |
|
101 |
|
|
102 |
$relamation_reason = SL::DB::ReclamationReason->new( |
|
103 |
name => "test_reason", |
|
104 |
description => "", |
|
105 |
position => 1, |
|
106 |
); |
|
107 |
} |
|
108 |
|
|
109 |
Support::TestSetup::login(); |
|
110 |
|
|
111 |
reset_state(); |
|
112 |
|
|
113 |
##### |
|
114 |
|
|
115 |
my $sales_reclamation = SL::Dev::Record::create_sales_reclamation( |
|
116 |
save => 1, |
|
117 |
employee => $employee, |
|
118 |
shippingpoint => "sp", |
|
119 |
transaction_description => "td1", |
|
120 |
payment => $payment_term, |
|
121 |
delivery_term => $delivery_term, |
|
122 |
taxincluded => 0, |
|
123 |
reclamation_items => [ |
|
124 |
SL::Dev::Record::create_reclamation_item( |
|
125 |
part => $parts[0], qty => 3, sellprice => 70, |
|
126 |
reason => $relamation_reason, |
|
127 |
), |
|
128 |
SL::Dev::Record::create_reclamation_item( |
|
129 |
part => $parts[1], qty => 10, sellprice => 50, |
|
130 |
reason => $relamation_reason, |
|
131 |
), |
|
132 |
], |
|
133 |
)->load; |
|
134 |
|
|
135 |
my $purchase_reclamation = SL::Dev::Record::create_purchase_reclamation( |
|
136 |
save => 1, |
|
137 |
employee => $employee, |
|
138 |
shippingpoint => "sp", |
|
139 |
transaction_description => "td2", |
|
140 |
payment => $payment_term, |
|
141 |
delivery_term => $delivery_term, |
|
142 |
taxincluded => 0, |
|
143 |
reclamation_items => [ |
|
144 |
SL::Dev::Record::create_reclamation_item( |
|
145 |
part => $parts[0], qty => 3, sellprice => 70, |
|
146 |
reason => $relamation_reason, |
|
147 |
), |
|
148 |
SL::Dev::Record::create_reclamation_item( |
|
149 |
part => $parts[1], qty => 10, sellprice => 50, |
|
150 |
reason => $relamation_reason, |
|
151 |
), |
|
152 |
], |
|
153 |
)->load; |
|
154 |
|
|
155 |
|
|
156 |
my $sales_order = SL::Dev::Record::create_sales_order( |
|
157 |
save => 1, |
|
158 |
employee => $employee, |
|
159 |
shippingpoint => "sp", |
|
160 |
transaction_description => "td3", |
|
161 |
payment_terms => $payment_term, |
|
162 |
delivery_term => $delivery_term, |
|
163 |
taxincluded => 0, |
|
164 |
orderitems => [ SL::Dev::Record::create_order_item(part => $parts[0], qty => 3, sellprice => 70), |
|
165 |
SL::Dev::Record::create_order_item(part => $parts[1], qty => 10, sellprice => 50), |
|
166 |
] |
|
167 |
)->load; |
|
168 |
|
|
169 |
my $purchase_order = SL::Dev::Record::create_purchase_order( |
|
170 |
save => 1, |
|
171 |
employee => $employee, |
|
172 |
shippingpoint => "sp", |
|
173 |
transaction_description => "td4", |
|
174 |
payment_terms => $payment_term, |
|
175 |
delivery_term => $delivery_term, |
|
176 |
taxincluded => 0, |
|
177 |
orderitems => [ SL::Dev::Record::create_order_item(part => $parts[0], qty => 3, sellprice => 70), |
|
178 |
SL::Dev::Record::create_order_item(part => $parts[1], qty => 10, sellprice => 50), |
|
179 |
] |
|
180 |
)->load; |
|
181 |
|
|
182 |
# convert order → reclamation |
|
183 |
my $converted_sales_reclamation = $sales_order->convert_to_reclamation; |
|
184 |
$converted_sales_reclamation->items_sorted->[0]->reason($relamation_reason); |
|
185 |
$converted_sales_reclamation->items_sorted->[1]->reason($relamation_reason); |
|
186 |
$converted_sales_reclamation->save->load; |
|
187 |
my $converted_purchase_reclamation = $purchase_order->convert_to_reclamation; |
|
188 |
$converted_purchase_reclamation->items_sorted->[0]->reason($relamation_reason); |
|
189 |
$converted_purchase_reclamation->items_sorted->[1]->reason($relamation_reason); |
|
190 |
$converted_purchase_reclamation->save->load; |
|
191 |
|
|
192 |
# convert reclamation → order |
|
193 |
my $converted_sales_order = $sales_reclamation->convert_to_order->save->load; |
|
194 |
my $converted_purchase_order = $purchase_reclamation->convert_to_order->save->load; |
|
195 |
|
|
196 |
|
|
197 |
#get items before strip |
|
198 |
my @purchase_reclamation_items = $purchase_reclamation->items_sorted; |
|
199 |
my @sales_reclamation_items = $sales_reclamation->items_sorted; |
|
200 |
my @converted_purchase_reclamation_items = $converted_purchase_reclamation->items_sorted; |
|
201 |
my @converted_sales_reclamation_items = $converted_sales_reclamation->items_sorted; |
|
202 |
my @purchase_order_items = $purchase_order->items_sorted; |
|
203 |
my @sales_order_items = $sales_order->items_sorted; |
|
204 |
my @converted_purchase_order_items = $converted_purchase_order->items_sorted; |
|
205 |
my @converted_sales_order_items = $converted_sales_order->items_sorted; |
|
206 |
|
|
207 |
|
|
208 |
### TESTS ##################################################################### |
|
209 |
|
|
210 |
## created sales und purchase reclamation should be nearly the same |
|
211 |
my $sales_reclamation_tmp = clone($sales_reclamation); |
|
212 |
my $purchase_reclamation_tmp = clone($purchase_reclamation); |
|
213 |
# clean different values |
|
214 |
foreach (qw( |
|
215 |
customer_id vendor_id |
|
216 |
id record_number |
|
217 |
salesman_id |
|
218 |
transaction_description |
|
219 |
itime mtime |
|
220 |
)) { |
|
221 |
$sales_reclamation_tmp->$_(undef); |
|
222 |
$purchase_reclamation_tmp->$_(undef); |
|
223 |
} |
|
224 |
foreach my $pair (zip(@purchase_reclamation_items, @sales_reclamation_items)) { |
|
225 |
my ($first, $second) = @{$pair}; |
|
226 |
my $first_tmp = clone($first); |
|
227 |
my $second_tmp = clone($second); |
|
228 |
foreach (qw( |
|
229 |
id reclamation_id |
|
230 |
itime mtime |
|
231 |
)) { |
|
232 |
$first_tmp->$_(undef); |
|
233 |
$second_tmp->$_(undef); |
|
234 |
} |
|
235 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
236 |
} |
|
237 |
is_deeply($purchase_reclamation_tmp->strip->as_tree, $sales_reclamation_tmp->strip->as_tree); |
|
238 |
|
|
239 |
## created sales und purchase order should be nearly the same |
|
240 |
my $sales_order_tmp = clone($sales_order); |
|
241 |
my $purchase_order_tmp = clone($purchase_order); |
|
242 |
# clean different values |
|
243 |
foreach (qw( |
|
244 |
customer_id vendor_id |
|
245 |
id |
|
246 |
ordnumber salesman_id |
|
247 |
transaction_description |
|
248 |
itime mtime |
|
249 |
)) { |
|
250 |
$sales_order_tmp->$_(undef); |
|
251 |
$purchase_order_tmp->$_(undef); |
|
252 |
} |
|
253 |
foreach my $pair (zip(@purchase_order_items, @sales_order_items)) { |
|
254 |
my ($first, $second) = @{$pair}; |
|
255 |
my $first_tmp = clone($first); |
|
256 |
my $second_tmp = clone($second); |
|
257 |
foreach (qw( |
|
258 |
id trans_id |
|
259 |
itime mtime |
|
260 |
)) { |
|
261 |
$first_tmp->$_(undef); |
|
262 |
$second_tmp->$_(undef); |
|
263 |
} |
|
264 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
265 |
} |
|
266 |
is_deeply($purchase_order_tmp->strip->as_tree, $sales_order_tmp->strip->as_tree); |
|
267 |
|
|
268 |
|
|
269 |
## converted have to be linked to parent |
|
270 |
# sales |
|
271 |
my $linked_sales_order = $converted_sales_reclamation->linked_records->[0]; |
|
272 |
my $linked_sales_reclamation = $converted_sales_order->linked_records->[0]; |
|
273 |
is_deeply($linked_sales_order->strip->as_tree, $sales_order->strip->as_tree); |
|
274 |
is_deeply($linked_sales_reclamation->strip->as_tree, $sales_reclamation->load->strip->as_tree); |
|
275 |
|
|
276 |
# purchase |
|
277 |
my $linked_purchase_order = $converted_purchase_reclamation->linked_records->[0]; |
|
278 |
my $linked_purchase_reclamation = $converted_purchase_order->linked_records->[0]; |
|
279 |
is_deeply($linked_purchase_order->strip->as_tree, $purchase_order->strip->as_tree); |
|
280 |
is_deeply($linked_purchase_reclamation->strip->as_tree, $purchase_reclamation->load->strip->as_tree); |
|
281 |
|
|
282 |
|
|
283 |
## converted should be nealy the same |
|
284 |
# sales |
|
285 |
foreach my $pair (zip(@sales_order_items, @converted_sales_reclamation_items)) { |
|
286 |
my ($first, $second) = @{$pair}; |
|
287 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
288 |
id trans_id reclamation_id itime mtime |
|
289 |
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate |
|
290 |
reason_description_ext reason_description_int reason_id |
|
291 |
)]}); |
|
292 |
} |
|
293 |
ok Compare($sales_order->strip->as_tree, $converted_sales_reclamation->strip->as_tree, {ignore_hash_keys => [qw( |
|
294 |
id employee_id itime mtime reqdate transdate |
|
295 |
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation |
|
296 |
cp_id contact_id |
|
297 |
cusordnumber cv_record_number |
|
298 |
ordnumber record_number |
|
299 |
)]}); |
|
300 |
|
|
301 |
foreach my $pair (zip(@sales_reclamation_items, @converted_sales_order_items)) { |
|
302 |
my ($first, $second) = @{$pair}; |
|
303 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
304 |
id trans_id reclamation_id itime mtime |
|
305 |
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate |
|
306 |
reason_description_ext reason_description_int reason_id |
|
307 |
)]}); |
|
308 |
} |
|
309 |
ok Compare($sales_reclamation->strip->as_tree, $converted_sales_order->strip->as_tree, {ignore_hash_keys => [qw( |
|
310 |
id employee_id itime mtime reqdate transdate |
|
311 |
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation |
|
312 |
cp_id contact_id |
|
313 |
cusordnumber cv_record_number |
|
314 |
ordnumber record_number |
|
315 |
)]}); |
|
316 |
|
|
317 |
# purchase |
|
318 |
foreach my $pair (zip(@purchase_order_items, @converted_purchase_reclamation_items)) { |
|
319 |
my ($first, $second) = @{$pair}; |
|
320 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
321 |
id trans_id reclamation_id itime mtime |
|
322 |
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate |
|
323 |
reason_description_ext reason_description_int reason_id |
|
324 |
)]}); |
|
325 |
} |
|
326 |
ok Compare($purchase_order->strip->as_tree, $converted_purchase_reclamation->strip->as_tree, {ignore_hash_keys => [qw( |
|
327 |
id employee_id itime mtime reqdate transdate |
|
328 |
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation |
|
329 |
cp_id contact_id |
|
330 |
cusordnumber cv_record_number |
|
331 |
ordnumber record_number |
|
332 |
)]}); |
|
333 |
|
|
334 |
foreach my $pair (zip(@purchase_reclamation_items, @converted_purchase_order_items)) { |
|
335 |
my ($first, $second) = @{$pair}; |
|
336 |
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw( |
|
337 |
id trans_id reclamation_id itime mtime |
|
338 |
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate |
|
339 |
reason_description_ext reason_description_int reason_id |
|
340 |
)]}); |
|
341 |
} |
|
342 |
ok Compare($purchase_reclamation->strip->as_tree, $converted_purchase_order->strip->as_tree, {ignore_hash_keys => [qw( |
|
343 |
id employee_id itime mtime reqdate transdate |
|
344 |
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation |
|
345 |
cp_id contact_id |
|
346 |
cusordnumber cv_record_number |
|
347 |
ordnumber record_number |
|
348 |
)]}); |
|
349 |
|
|
350 |
#### |
|
351 |
clear_up(); |
|
352 |
|
|
353 |
done_testing; |
|
354 |
|
|
355 |
1; |
t/workflow/reclamation_reclamation.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 |
use List::Util qw(zip); |
|
13 |
|
|
14 |
use SL::DB::Reclamation; |
|
15 |
use SL::DB::ReclamationReason; |
|
16 |
use SL::DB::Customer; |
|
17 |
use SL::DB::Vendor; |
|
18 |
use SL::DB::Department; |
|
19 |
use SL::DB::Currency; |
|
20 |
use SL::DB::PaymentTerm; |
|
21 |
use SL::DB::DeliveryTerm; |
|
22 |
use SL::DB::Employee; |
|
23 |
use SL::DB::Part; |
|
24 |
use SL::DB::Unit; |
|
25 |
|
|
26 |
use Rose::DB::Object::Helpers qw(clone); |
|
27 |
|
|
28 |
use SL::Dev::ALL qw(:ALL); |
|
29 |
|
|
30 |
my ( |
|
31 |
$customer, $vendor, |
|
32 |
$employee, |
|
33 |
$payment_term, |
|
34 |
$delivery_term, |
|
35 |
$unit, |
|
36 |
@parts, |
|
37 |
$department, |
|
38 |
$relamation_reason, |
|
39 |
); |
|
40 |
|
|
41 |
|
|
42 |
sub clear_up { |
|
43 |
foreach (qw( |
|
44 |
Reclamation ReclamationItem |
|
45 |
Part |
|
46 |
Customer Vendor |
|
47 |
Department PaymentTerm DeliveryTerm |
|
48 |
)) { |
|
49 |
"SL::DB::Manager::${_}"->delete_all(all => 1); |
|
50 |
} |
|
51 |
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]); |
|
52 |
}; |
|
53 |
|
|
54 |
sub reset_state { |
|
55 |
my %params = @_; |
|
56 |
|
|
57 |
clear_up(); |
|
58 |
|
|
59 |
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'"; |
|
60 |
|
|
61 |
$employee = SL::DB::Employee->new( |
|
62 |
'login' => 'testuser', |
|
63 |
'name' => 'Test User', |
|
64 |
)->save; |
|
65 |
|
|
66 |
$department = SL::DB::Department->new( |
|
67 |
'description' => 'Test Department', |
|
68 |
)->save; |
|
69 |
|
|
70 |
$payment_term = create_payment_terms( |
|
71 |
'description' => '14Tage 2%Skonto, 30Tage netto', |
|
72 |
'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.", |
|
73 |
'percent_skonto' => '0.02', |
|
74 |
'terms_netto' => 30, |
|
75 |
'terms_skonto' => 14 |
|
76 |
); |
|
77 |
|
|
78 |
$delivery_term = SL::DB::DeliveryTerm->new( |
|
79 |
'description' => 'Test Delivey Term', |
|
80 |
'description_long' => 'Test Delivey Term Test Delivey Term', |
|
81 |
)->save; |
|
82 |
|
|
83 |
# some parts/services |
|
84 |
@parts = (); |
|
85 |
push @parts, new_part( |
|
86 |
partnumber => 'Part_1_KG', |
|
87 |
unit => $unit->name, |
|
88 |
)->save; |
|
89 |
push @parts, new_service( |
|
90 |
partnumber => 'Serv_1', |
|
91 |
)->save; |
|
92 |
push @parts, new_part( |
|
93 |
partnumber => 'Part_2', |
|
94 |
)->save; |
|
95 |
push @parts, new_service( |
|
96 |
partnumber => 'Serv_2' |
|
97 |
)->save; |
|
98 |
|
|
99 |
$relamation_reason = SL::DB::ReclamationReason->new( |
|
100 |
name => "test_reason", |
|
101 |
description => "", |
|
102 |
position => 1, |
|
103 |
); |
|
104 |
} |
|
105 |
|
|
106 |
Support::TestSetup::login(); |
|
107 |
|
|
108 |
reset_state(); |
|
109 |
|
|
110 |
##### |
|
111 |
|
|
112 |
my $sales_reclamation = SL::Dev::Record::create_sales_reclamation( |
|
113 |
save => 1, |
|
114 |
employee => $employee, |
|
115 |
shippingpoint => "sp", |
|
116 |
transaction_description => "td1", |
|
117 |
payment => $payment_term, |
|
118 |
delivery_term => $delivery_term, |
|
119 |
taxincluded => 0, |
|
120 |
reclamation_items => [ |
|
121 |
SL::Dev::Record::create_reclamation_item( |
|
122 |
part => $parts[0], qty => 3, sellprice => 70, |
|
123 |
reason => $relamation_reason, |
|
124 |
), |
|
125 |
SL::Dev::Record::create_reclamation_item( |
|
126 |
part => $parts[1], qty => 10, sellprice => 50, |
|
127 |
reason => $relamation_reason, |
|
128 |
), |
|
129 |
], |
|
130 |
)->load; |
|
131 |
|
|
132 |
my $purchase_reclamation = SL::Dev::Record::create_purchase_reclamation( |
|
133 |
save => 1, |
|
134 |
employee => $employee, |
|
135 |
shippingpoint => "sp", |
|
136 |
transaction_description => "td2", |
|
137 |
payment => $payment_term, |
|
138 |
delivery_term => $delivery_term, |
|
139 |
taxincluded => 0, |
|
140 |
reclamation_items => [ |
|
141 |
SL::Dev::Record::create_reclamation_item( |
|
142 |
part => $parts[0], qty => 3, sellprice => 70, |
|
143 |
reason => $relamation_reason, |
|
144 |
), |
|
145 |
SL::Dev::Record::create_reclamation_item( |
|
146 |
part => $parts[1], qty => 10, sellprice => 50, |
|
147 |
reason => $relamation_reason, |
|
148 |
), |
|
149 |
], |
|
150 |
)->load; |
|
151 |
|
|
152 |
# new |
|
153 |
my $new_sales_reclamation = SL::DB::Reclamation->new_from($sales_reclamation, destination_type => 'sales_reclamation')->save->load; |
|
154 |
my $new_purchase_reclamation = SL::DB::Reclamation->new_from($purchase_reclamation, destination_type => 'purchase_reclamation')->save->load; |
|
155 |
|
|
156 |
# convert |
|
157 |
my $converted_purchase_reclamation = SL::DB::Reclamation->new_from($sales_reclamation, destination_type => 'purchase_reclamation'); |
|
158 |
$converted_purchase_reclamation->vendor_id($purchase_reclamation->{vendor_id}); |
|
159 |
$converted_purchase_reclamation->save->load; |
|
160 |
my $converted_sales_reclamation = SL::DB::Reclamation->new_from($purchase_reclamation, destination_type => 'sales_reclamation'); |
|
161 |
$converted_sales_reclamation->customer_id($sales_reclamation->{customer_id}); |
|
162 |
$converted_sales_reclamation->save->load; |
|
163 |
|
|
164 |
#get items before strip |
|
165 |
my @purchase_reclamation_items = $purchase_reclamation->items_sorted; |
|
166 |
my @sales_reclamation_items = $sales_reclamation->items_sorted; |
|
167 |
my @new_purchase_reclamation_items = $new_purchase_reclamation->items_sorted; |
|
168 |
my @new_sales_reclamation_items = $new_sales_reclamation->items_sorted; |
|
169 |
my @converted_purchase_reclamation_items = $converted_purchase_reclamation->items_sorted; |
|
170 |
my @converted_sales_reclamation_items = $converted_sales_reclamation->items_sorted; |
|
171 |
|
|
172 |
|
|
173 |
### TESTS ##################################################################### |
|
174 |
|
|
175 |
## created sales und purchase reclamation should be nearly the same |
|
176 |
my $sales_tmp = clone($sales_reclamation); |
|
177 |
my $purchase_tmp = clone($purchase_reclamation); |
|
178 |
# clean different values |
|
179 |
foreach (qw( |
|
180 |
customer_id vendor_id |
|
181 |
id record_number transaction_description |
|
182 |
itime mtime |
|
183 |
)) { |
|
184 |
$sales_tmp->$_(undef); |
|
185 |
$purchase_tmp->$_(undef); |
|
186 |
} |
|
187 |
|
|
188 |
foreach my $pair (zip(@purchase_reclamation_items, @sales_reclamation_items)) { |
|
189 |
my ($first, $second) = @{$pair}; |
|
190 |
my $first_tmp = clone($first); |
|
191 |
my $second_tmp = clone($second); |
|
192 |
foreach (qw( |
|
193 |
id reclamation_id |
|
194 |
itime mtime |
|
195 |
)) { |
|
196 |
$first_tmp->$_(undef); |
|
197 |
$second_tmp->$_(undef); |
|
198 |
} |
|
199 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
200 |
} |
|
201 |
is_deeply($purchase_tmp->strip->as_tree, $sales_tmp->strip->as_tree); |
|
202 |
|
|
203 |
|
|
204 |
## converted have to be linked to parent |
|
205 |
# new |
|
206 |
my $linked_sales_reclamation_n = $new_sales_reclamation->linked_records->[0]; |
|
207 |
my $linked_purchase_reclamation_n = $new_purchase_reclamation->linked_records->[0]; |
|
208 |
is_deeply($linked_sales_reclamation_n->strip->as_tree, $sales_reclamation->load->strip->as_tree); |
|
209 |
is_deeply($linked_purchase_reclamation_n->strip->as_tree, $purchase_reclamation->load->strip->as_tree); |
|
210 |
|
|
211 |
# converted |
|
212 |
my $linked_sales_reclamation_c = $converted_purchase_reclamation->linked_records->[0]; |
|
213 |
my $linked_purchase_reclamation_c = $converted_sales_reclamation->linked_records->[0]; |
|
214 |
is_deeply($linked_sales_reclamation_c->strip->as_tree, $sales_reclamation->load->strip->as_tree); |
|
215 |
is_deeply($linked_purchase_reclamation_c->strip->as_tree, $purchase_reclamation->load->strip->as_tree); |
|
216 |
|
|
217 |
|
|
218 |
## new reclamations should be nealy the same |
|
219 |
my $new_sales_tmp = clone($new_sales_reclamation); |
|
220 |
my $sales_tmp2 = clone($sales_reclamation); |
|
221 |
my $new_purchase_tmp = clone($new_purchase_reclamation); |
|
222 |
my $purchase_tmp2 = clone($purchase_reclamation); |
|
223 |
# clean different values |
|
224 |
foreach (qw( |
|
225 |
id record_number |
|
226 |
reqdate employee_id transdate |
|
227 |
itime mtime |
|
228 |
)) { |
|
229 |
$new_sales_tmp->$_(undef); |
|
230 |
$sales_tmp2->$_(undef); |
|
231 |
$new_purchase_tmp->$_(undef); |
|
232 |
$purchase_tmp2->$_(undef); |
|
233 |
} |
|
234 |
|
|
235 |
foreach my $pair (zip(@sales_reclamation_items, @new_sales_reclamation_items)) { |
|
236 |
my ($first, $second) = @{$pair}; |
|
237 |
my $first_tmp = clone($first); |
|
238 |
my $second_tmp = clone($second); |
|
239 |
foreach (qw( |
|
240 |
id reclamation_id |
|
241 |
itime mtime |
|
242 |
)) { |
|
243 |
$first_tmp->$_(undef); |
|
244 |
$second_tmp->$_(undef); |
|
245 |
} |
|
246 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
247 |
} |
|
248 |
is_deeply($sales_tmp2->strip->as_tree, $new_sales_tmp->strip->as_tree); |
|
249 |
|
|
250 |
foreach my $pair (zip(@purchase_reclamation_items, @new_purchase_reclamation_items)) { |
|
251 |
my ($first, $second) = @{$pair}; |
|
252 |
my $first_tmp = clone($first); |
|
253 |
my $second_tmp = clone($second); |
|
254 |
foreach (qw( |
|
255 |
id reclamation_id |
|
256 |
itime mtime |
|
257 |
)) { |
|
258 |
$first_tmp->$_(undef); |
|
259 |
$second_tmp->$_(undef); |
|
260 |
} |
|
261 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
262 |
} |
|
263 |
is_deeply($purchase_tmp2->strip->as_tree, $new_purchase_tmp->strip->as_tree); |
|
264 |
|
|
265 |
|
|
266 |
## converted reclamation should be nealy the same |
|
267 |
my $sales_tmp3 = clone($sales_reclamation); |
|
268 |
my $converted_sales_tmp = clone($converted_sales_reclamation); |
|
269 |
my $purchase_tmp3 = clone($purchase_reclamation); |
|
270 |
my $converted_purchase_tmp = clone($converted_purchase_reclamation); |
|
271 |
# clean changing values |
|
272 |
foreach (qw( |
|
273 |
transdate |
|
274 |
customer_id vendor_id |
|
275 |
id record_number |
|
276 |
employee_id reqdate |
|
277 |
itime mtime |
|
278 |
|
|
279 |
delivery_term_id |
|
280 |
payment_id |
|
281 |
)) { |
|
282 |
$sales_tmp3->$_(undef); |
|
283 |
$converted_sales_tmp->$_(undef); |
|
284 |
$purchase_tmp3->$_(undef); |
|
285 |
$converted_purchase_tmp->$_(undef); |
|
286 |
} |
|
287 |
|
|
288 |
# from sales to purchase |
|
289 |
foreach my $pair (zip(@sales_reclamation_items, @converted_purchase_reclamation_items)) { |
|
290 |
my ($first, $second) = @{$pair}; |
|
291 |
my $first_tmp = clone($first); |
|
292 |
my $second_tmp = clone($second); |
|
293 |
foreach (qw( |
|
294 |
id reclamation_id |
|
295 |
sellprice discount |
|
296 |
itime mtime |
|
297 |
)) { |
|
298 |
$first_tmp->$_(undef); |
|
299 |
$second_tmp->$_(undef); |
|
300 |
} |
|
301 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
302 |
} |
|
303 |
is_deeply($sales_tmp3->strip->as_tree, $converted_purchase_tmp->strip->as_tree); |
|
304 |
|
|
305 |
|
|
306 |
# from purchase to sales |
|
307 |
foreach my $pair (zip(@purchase_reclamation_items, @converted_sales_reclamation_items)) { |
|
308 |
my ($first, $second) = @{$pair}; |
|
309 |
my $first_tmp = clone($first); |
|
310 |
my $second_tmp = clone($second); |
|
311 |
foreach (qw( |
|
312 |
id reclamation_id |
|
313 |
lastcost |
|
314 |
itime mtime |
|
315 |
)) { |
|
316 |
$first_tmp->$_(undef); |
|
317 |
$second_tmp->$_(undef); |
|
318 |
} |
|
319 |
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree); |
|
320 |
} |
|
321 |
is_deeply($purchase_tmp3->strip->as_tree, $converted_sales_tmp->strip->as_tree); |
|
322 |
|
|
323 |
#diag Dumper($first->strip->as_tree); |
|
324 |
#diag Dumper($second->strip->as_tree); |
|
325 |
|
|
326 |
#### |
|
327 |
clear_up(); |
|
328 |
|
|
329 |
done_testing; |
|
330 |
|
|
331 |
1; |
|
332 |
|
|
333 |
# set emacs to perl mode |
|
334 |
# Local Variables: |
|
335 |
# mode: perl |
|
336 |
# End: |
Auch abrufbar als: Unified diff
Reclamation: Test for workflow (reclamation, order, delivery_order)