Revision a43aa9ac
Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt
t/background_job/convert_time_recordings.t | ||
---|---|---|
1 |
use Test::More tests => 34;
|
|
1 |
use Test::More tests => 40;
|
|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
... | ... | |
313 | 313 |
clear_up(); |
314 | 314 |
|
315 | 315 |
|
316 |
######################################## |
|
317 |
# check rounding |
|
318 |
######################################## |
|
319 |
$part = new_service(partnumber => 'Serv1', unit => 'Std')->save; |
|
320 |
$customer = new_customer()->save; |
|
321 |
|
|
322 |
$sales_order = create_sales_order( |
|
323 |
save => 1, |
|
324 |
customer => $customer, |
|
325 |
taxincluded => 0, |
|
326 |
orderitems => [ create_order_item(part => $part, qty => 3, sellprice => 70), ] |
|
327 |
); |
|
328 |
|
|
329 |
@time_recordings = (); |
|
330 |
push @time_recordings, new_time_recording( |
|
331 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 0), |
|
332 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 6), |
|
333 |
customer => $customer, |
|
334 |
order => $sales_order, |
|
335 |
part => $part, |
|
336 |
)->save; |
|
337 |
|
|
338 |
%data = ( |
|
339 |
from_date => '01.01.2021', |
|
340 |
to_date => '30.04.2021', |
|
341 |
link_order => 1, |
|
342 |
rounding => 1, |
|
343 |
); |
|
344 |
$db_obj = SL::DB::BackgroundJob->new(); |
|
345 |
$db_obj->set_data(%data); |
|
346 |
$job = SL::BackgroundJob::ConvertTimeRecordings->new; |
|
347 |
$ret = $job->run($db_obj); |
|
348 |
|
|
349 |
$linked_dos = $sales_order->linked_records(to => 'DeliveryOrder'); |
|
350 |
$linked_items = $sales_order->items->[0]->linked_records(to => 'DeliveryOrderItem'); |
|
351 |
is($linked_items->[0]->qty*1, 0.25, 'rounding to quarter hour: qty in delivery order'); |
|
352 |
is($linked_items->[0]->base_qty*1, 0.25, 'rounding to quarter hour: base_qty in delivery order'); |
|
353 |
|
|
354 |
# reload order and orderitems to get changes to deliverd and ship |
|
355 |
Rose::DB::Object::Helpers::forget_related($sales_order, 'orderitems'); |
|
356 |
$sales_order->load; |
|
357 |
|
|
358 |
is($sales_order->items->[0]->ship*1, 0.25, 'rounding to quarter hour: ship in related order'); |
|
359 |
|
|
360 |
clear_up(); |
|
361 |
|
|
362 |
|
|
363 |
######################################## |
|
364 |
# check rounding |
|
365 |
######################################## |
|
366 |
$part = new_service(partnumber => 'Serv1', unit => 'Std')->save; |
|
367 |
$customer = new_customer()->save; |
|
368 |
|
|
369 |
$sales_order = create_sales_order( |
|
370 |
save => 1, |
|
371 |
customer => $customer, |
|
372 |
taxincluded => 0, |
|
373 |
orderitems => [ create_order_item(part => $part, qty => 3, sellprice => 70), ] |
|
374 |
); |
|
375 |
|
|
376 |
@time_recordings = (); |
|
377 |
push @time_recordings, new_time_recording( |
|
378 |
start_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 0), |
|
379 |
end_time => DateTime->new(year => 2021, month => 4, day => 19, hour => 10, minute => 6), |
|
380 |
customer => $customer, |
|
381 |
order => $sales_order, |
|
382 |
part => $part, |
|
383 |
)->save; |
|
384 |
|
|
385 |
%data = ( |
|
386 |
from_date => '01.01.2021', |
|
387 |
to_date => '30.04.2021', |
|
388 |
link_order => 1, |
|
389 |
rounding => 0, |
|
390 |
); |
|
391 |
$db_obj = SL::DB::BackgroundJob->new(); |
|
392 |
$db_obj->set_data(%data); |
|
393 |
$job = SL::BackgroundJob::ConvertTimeRecordings->new; |
|
394 |
$ret = $job->run($db_obj); |
|
395 |
|
|
396 |
$linked_dos = $sales_order->linked_records(to => 'DeliveryOrder'); |
|
397 |
$linked_items = $sales_order->items->[0]->linked_records(to => 'DeliveryOrderItem'); |
|
398 |
is($linked_items->[0]->qty*1, 0.1, 'no rounding: qty in delivery order'); |
|
399 |
is($linked_items->[0]->base_qty*1, 0.1, 'no rounding: base_qty in delivery order'); |
|
400 |
|
|
401 |
# reload order and orderitems to get changes to deliverd and ship |
|
402 |
Rose::DB::Object::Helpers::forget_related($sales_order, 'orderitems'); |
|
403 |
$sales_order->load; |
|
404 |
|
|
405 |
is($sales_order->items->[0]->ship*1, 0.1, 'no rounding: ship in related order'); |
|
406 |
|
|
407 |
clear_up(); |
|
408 |
|
|
409 |
|
|
316 | 410 |
######################################## |
317 | 411 |
# are wrong params detected? |
318 | 412 |
######################################## |
Auch abrufbar als: Unified diff
Zeiterfassung: Unit-Test: Runden/Nicht runden testen