1 |
|
use Test::More tests => 7;
|
|
1 |
use Test::More tests => 18;
|
2 |
2 |
|
3 |
3 |
use strict;
|
4 |
4 |
|
... | ... | |
8 |
8 |
use Support::TestSetup;
|
9 |
9 |
use Test::Exception;
|
10 |
10 |
use DateTime;
|
|
11 |
use Rose::DB::Object::Helpers qw(forget_related);
|
11 |
12 |
|
12 |
13 |
use SL::DB::BackgroundJob;
|
13 |
14 |
|
... | ... | |
34 |
35 |
|
35 |
36 |
clear_up();
|
36 |
37 |
|
|
38 |
########################################
|
|
39 |
# two time recordings, one order linked with project_id
|
|
40 |
########################################
|
37 |
41 |
my $part = new_service(partnumber => 'Serv1', unit => 'Std')->save;
|
38 |
42 |
my $project = create_project(projectnumber => 'p1', description => 'Project 1');
|
39 |
43 |
my $customer = new_customer()->save;
|
... | ... | |
50 |
54 |
my @time_recordings;
|
51 |
55 |
push @time_recordings, new_time_recording(
|
52 |
56 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 5),
|
53 |
|
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 11, minute => 10),
|
|
57 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 11, minute => 5),
|
54 |
58 |
customer => $customer,
|
55 |
59 |
project => $project,
|
56 |
60 |
part => $part,
|
57 |
61 |
)->save;
|
58 |
62 |
push @time_recordings, new_time_recording(
|
59 |
63 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 12, minute => 5),
|
60 |
|
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 14, minute => 10),
|
|
64 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 14, minute => 5),
|
61 |
65 |
customer => $customer,
|
62 |
66 |
project => $project,
|
63 |
67 |
part => $part,
|
64 |
68 |
)->save;
|
65 |
69 |
|
66 |
|
# two time recordings, one order linked with project_id
|
67 |
70 |
my %data = (
|
68 |
71 |
link_project => 1,
|
69 |
72 |
project_id => $project->id,
|
... | ... | |
84 |
87 |
|
85 |
88 |
my $linked_items = $sales_order->items->[0]->linked_records(to => 'DeliveryOrderItem');
|
86 |
89 |
is(scalar @$linked_items, 1, 'one delivery order item linked to order item');
|
87 |
|
is($linked_items->[0]->qty*1, 3.16, 'qty in delivery order');
|
|
90 |
is($linked_items->[0]->qty*1, 3, 'qty in delivery order');
|
|
91 |
is($linked_items->[0]->base_qty*1, 3, 'base_qty in delivery order');
|
|
92 |
|
|
93 |
# reload order and orderitems to get changes to deliverd and ship
|
|
94 |
Rose::DB::Object::Helpers::forget_related($sales_order, 'orderitems');
|
|
95 |
$sales_order->load;
|
|
96 |
|
|
97 |
ok($sales_order->delivered, 'related order is delivered');
|
|
98 |
is($sales_order->items->[0]->ship*1, 3, 'ship in related order');
|
|
99 |
|
|
100 |
clear_up();
|
|
101 |
|
|
102 |
|
|
103 |
########################################
|
|
104 |
# two time recordings, one order linked with project_id
|
|
105 |
# unit in order is 'min', but part is 'Std'
|
|
106 |
########################################
|
|
107 |
$part = new_service(partnumber => 'Serv1', unit => 'Std')->save;
|
|
108 |
$project = create_project(projectnumber => 'p1', description => 'Project 1');
|
|
109 |
$customer = new_customer()->save;
|
|
110 |
|
|
111 |
$sales_order = create_sales_order(
|
|
112 |
save => 1,
|
|
113 |
customer => $customer,
|
|
114 |
globalproject => $project,
|
|
115 |
taxincluded => 0,
|
|
116 |
orderitems => [ create_order_item(part => $part, qty => 180, unit => 'min', sellprice => 70), ]
|
|
117 |
);
|
|
118 |
|
|
119 |
@time_recordings = ();
|
|
120 |
push @time_recordings, new_time_recording(
|
|
121 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 10),
|
|
122 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 11, minute => 10),
|
|
123 |
customer => $customer,
|
|
124 |
project => $project,
|
|
125 |
part => $part,
|
|
126 |
)->save;
|
|
127 |
push @time_recordings, new_time_recording(
|
|
128 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 12, minute => 10),
|
|
129 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 14, minute => 10),
|
|
130 |
customer => $customer,
|
|
131 |
project => $project,
|
|
132 |
part => $part,
|
|
133 |
)->save;
|
|
134 |
|
|
135 |
# two time recordings, one order linked with project_id
|
|
136 |
%data = (
|
|
137 |
link_project => 1,
|
|
138 |
project_id => $project->id,
|
|
139 |
from_date => '01.04.2021',
|
|
140 |
to_date => '30.04.2021',
|
|
141 |
);
|
|
142 |
$db_obj = SL::DB::BackgroundJob->new();
|
|
143 |
$db_obj->set_data(%data);
|
|
144 |
$job = SL::BackgroundJob::ConvertTimeRecordings->new;
|
|
145 |
$ret = $job->run($db_obj);
|
|
146 |
|
|
147 |
$linked_dos = $sales_order->linked_records(to => 'DeliveryOrder');
|
|
148 |
$linked_items = $sales_order->items->[0]->linked_records(to => 'DeliveryOrderItem');
|
|
149 |
is($linked_items->[0]->qty*1, 3, 'different units: qty in delivery order');
|
|
150 |
is($linked_items->[0]->base_qty*1, 3, 'different units: base_qty in delivery order');
|
|
151 |
|
|
152 |
# reload order and orderitems to get changes to deliverd and ship
|
|
153 |
Rose::DB::Object::Helpers::forget_related($sales_order, 'orderitems');
|
|
154 |
$sales_order->load;
|
|
155 |
|
|
156 |
ok($sales_order->delivered, 'different units: related order is delivered');
|
|
157 |
is($sales_order->items->[0]->ship*1, 180, 'different units: ship in related order');
|
|
158 |
|
|
159 |
clear_up();
|
|
160 |
|
|
161 |
|
|
162 |
########################################
|
|
163 |
# two time recordings, one order linked with project_id
|
|
164 |
# unit in order is 'Std', but part is 'min'
|
|
165 |
########################################
|
|
166 |
$part = new_service(partnumber => 'Serv1', unit => 'min')->save;
|
|
167 |
$project = create_project(projectnumber => 'p1', description => 'Project 1');
|
|
168 |
$customer = new_customer()->save;
|
|
169 |
|
|
170 |
$sales_order = create_sales_order(
|
|
171 |
save => 1,
|
|
172 |
customer => $customer,
|
|
173 |
globalproject => $project,
|
|
174 |
taxincluded => 0,
|
|
175 |
orderitems => [ create_order_item(part => $part, qty => 2, unit => 'Std', sellprice => 70), ]
|
|
176 |
);
|
|
177 |
|
|
178 |
@time_recordings = ();
|
|
179 |
push @time_recordings, new_time_recording(
|
|
180 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 10),
|
|
181 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 11, minute => 10),
|
|
182 |
customer => $customer,
|
|
183 |
project => $project,
|
|
184 |
part => $part,
|
|
185 |
)->save;
|
|
186 |
push @time_recordings, new_time_recording(
|
|
187 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 12, minute => 10),
|
|
188 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 13, minute => 10),
|
|
189 |
customer => $customer,
|
|
190 |
project => $project,
|
|
191 |
part => $part,
|
|
192 |
)->save;
|
|
193 |
|
|
194 |
# two time recordings, one order linked with project_id
|
|
195 |
%data = (
|
|
196 |
link_project => 1,
|
|
197 |
project_id => $project->id,
|
|
198 |
from_date => '01.04.2021',
|
|
199 |
to_date => '30.04.2021',
|
|
200 |
);
|
|
201 |
$db_obj = SL::DB::BackgroundJob->new();
|
|
202 |
$db_obj->set_data(%data);
|
|
203 |
$job = SL::BackgroundJob::ConvertTimeRecordings->new;
|
|
204 |
$ret = $job->run($db_obj);
|
|
205 |
|
|
206 |
$linked_dos = $sales_order->linked_records(to => 'DeliveryOrder');
|
|
207 |
$linked_items = $sales_order->items->[0]->linked_records(to => 'DeliveryOrderItem');
|
|
208 |
is($linked_items->[0]->qty*1, 2, 'different units 2: qty in delivery order');
|
|
209 |
is($linked_items->[0]->base_qty*1, 120, 'different units 2: base_qty in delivery order');
|
|
210 |
|
|
211 |
# reload order and orderitems to get changes to deliverd and ship
|
|
212 |
Rose::DB::Object::Helpers::forget_related($sales_order, 'orderitems');
|
|
213 |
$sales_order->load;
|
|
214 |
|
|
215 |
ok($sales_order->delivered, 'different units 2: related order is delivered');
|
|
216 |
is($sales_order->items->[0]->ship*1, 2, 'different units 2: ship in related order');
|
88 |
217 |
|
89 |
218 |
clear_up();
|
90 |
219 |
|
|
220 |
|
|
221 |
########################################
|
|
222 |
|
91 |
223 |
$::locale = $old_locale;
|
92 |
224 |
|
93 |
225 |
1;
|
Zeiterfassung: Konvertierung: geliefert/gelieferte Mengen in Auftrag anpassen