Revision 6270ebd1
Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt
t/background_job/convert_time_recordings.t | ||
---|---|---|
1 |
use Test::More tests => 7; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use lib 't'; |
|
6 |
use utf8; |
|
7 |
|
|
8 |
use Support::TestSetup; |
|
9 |
use Test::Exception; |
|
10 |
use DateTime; |
|
11 |
|
|
12 |
use SL::DB::BackgroundJob; |
|
13 |
|
|
14 |
use_ok 'SL::BackgroundJob::ConvertTimeRecordings'; |
|
15 |
|
|
16 |
use SL::Dev::ALL qw(:ALL); |
|
17 |
|
|
18 |
Support::TestSetup::login(); |
|
19 |
|
|
20 |
sub clear_up { |
|
21 |
foreach (qw(OrderItem Order DeliveryOrder TimeRecording Project Part Customer RecordLink)) { |
|
22 |
"SL::DB::Manager::${_}"->delete_all(all => 1); |
|
23 |
} |
|
24 |
SL::DB::Manager::Employee->delete_all(where => [ '!login' => 'unittests' ]); |
|
25 |
}; |
|
26 |
|
|
27 |
######################################## |
|
28 |
|
|
29 |
$::myconfig{numberformat} = '1000.00'; |
|
30 |
my $old_locale = $::locale; |
|
31 |
# set locale to en so we can match errors |
|
32 |
$::locale = Locale->new('en'); |
|
33 |
|
|
34 |
|
|
35 |
clear_up(); |
|
36 |
|
|
37 |
my $part = new_service(partnumber => 'Serv1', unit => 'Std')->save; |
|
38 |
my $project = create_project(projectnumber => 'p1', description => 'Project 1'); |
|
39 |
my $customer = new_customer()->save; |
|
40 |
|
|
41 |
# sales order with globalproject_id |
|
42 |
my $sales_order = create_sales_order( |
|
43 |
save => 1, |
|
44 |
customer => $customer, |
|
45 |
globalproject => $project, |
|
46 |
taxincluded => 0, |
|
47 |
orderitems => [ create_order_item(part => $part, qty => 3, sellprice => 70), ] |
|
48 |
); |
|
49 |
|
|
50 |
my @time_recordings; |
|
51 |
push @time_recordings, new_time_recording( |
|
52 |
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), |
|
54 |
customer => $customer, |
|
55 |
project => $project, |
|
56 |
part => $part, |
|
57 |
)->save; |
|
58 |
push @time_recordings, new_time_recording( |
|
59 |
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), |
|
61 |
customer => $customer, |
|
62 |
project => $project, |
|
63 |
part => $part, |
|
64 |
)->save; |
|
65 |
|
|
66 |
# two time recordings, one order linked with project_id |
|
67 |
my %data = ( |
|
68 |
link_project => 1, |
|
69 |
project_id => $project->id, |
|
70 |
from_date => '01.04.2021', |
|
71 |
to_date => '30.04.2021', |
|
72 |
); |
|
73 |
my $db_obj = SL::DB::BackgroundJob->new(); |
|
74 |
$db_obj->set_data(%data); |
|
75 |
my $job = SL::BackgroundJob::ConvertTimeRecordings->new; |
|
76 |
my $ret = $job->run($db_obj); |
|
77 |
|
|
78 |
is_deeply($job->{job_errors}, [], 'no errros'); |
|
79 |
like($ret, qr{^Number of delivery orders created: 1}, 'one delivery order created'); |
|
80 |
|
|
81 |
my $linked_dos = $sales_order->linked_records(to => 'DeliveryOrder'); |
|
82 |
is(scalar @$linked_dos, 1, 'one delivery order linked to order'); |
|
83 |
is($linked_dos->[0]->globalproject_id, $sales_order->globalproject_id, 'project ids match'); |
|
84 |
|
|
85 |
my $linked_items = $sales_order->items->[0]->linked_records(to => 'DeliveryOrderItem'); |
|
86 |
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'); |
|
88 |
|
|
89 |
clear_up(); |
|
90 |
|
|
91 |
$::locale = $old_locale; |
|
92 |
|
|
93 |
1; |
|
94 |
|
|
95 |
##### |
|
96 |
# vim: ft=perl |
|
97 |
# set emacs to perl mode |
|
98 |
# Local Variables: |
|
99 |
# mode: perl |
|
100 |
# End: |
Auch abrufbar als: Unified diff
Zeiterfassung: Unit-Test f. Konvertierung