Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision af81f05f

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID af81f05f3519e304f29a28b7fe34cce3689c073f
  • Vorgänger 42c64631
  • Nachfolger 68f05425

Zeiterfassung: Konvertierung: geliefert/gelieferte Mengen in Auftrag anpassen

Unterschiede anzeigen:

SL/BackgroundJob/ConvertTimeRecordings.pm
211 211
          }
212 212
        }
213 213

  
214
        # update delivered and item's ship for related order
214 215
        my $helper = SL::Helper::ShippedQty->new->calculate($related_order)->write_to_objects;
215
        $related_order->update_attributes(delivered => $related_order->{delivered});
216
        $related_order->delivered($related_order->{delivered});
217
        $_->ship($_->{shipped_qty}) for @{$related_order->items};
218
        $related_order->save(cascade => 1);
216 219

  
217 220
        1;
218 221
      })) {
......
287 290
    return;
288 291
  }
289 292

  
290
  my $orders = SL::DB::Manager::Order->get_all(where => [customer_id      => $tr->customer_id,
291
                                                         or               => [quotation => undef, quotation => 0],
292
                                                         globalproject_id => $project_id, ]);
293
  my $orders = SL::DB::Manager::Order->get_all(where        => [customer_id      => $tr->customer_id,
294
                                                                or               => [quotation => undef, quotation => 0],
295
                                                                globalproject_id => $project_id, ],
296
                                               with_objects => ['orderitems']);
293 297
  my @matching_orders;
294 298
  foreach my $order (@$orders) {
295 299
    if (any { $_->parts_id == $part_id } @{ $order->items_sorted }) {
SL/DB/DeliveryOrder.pm
20 20
use SL::Helper::Number qw(_format_total _round_total);
21 21

  
22 22
use List::Util qw(first);
23
use List::MoreUtils qw(any);
23
use List::MoreUtils qw(any pairwise);
24 24
use Math::Round qw(nhimult);
25 25

  
26 26
__PACKAGE__->meta->add_relationship(orderitems => { type         => 'one to many',
......
264 264
  if ($params{related_order}) {
265 265
    # collect suitable items in related order
266 266
    my @items_to_use;
267
    my @new_attributes;
267 268
    foreach my $item (@items) {
268 269
      my $item_to_use = first {$item->parts_id == $_->parts_id} @{ $params{related_order}->items_sorted };
269 270

  
270 271
      die "no suitable item found in related order" if !$item_to_use;
271 272

  
272 273
      my %new_attributes;
273
      $new_attributes{$_} = $item->$_ for qw(qty unit_obj longdescription);
274
      $item_to_use->assign_attributes(%new_attributes);
275
      push @items_to_use, $item_to_use;
274
      $new_attributes{$_} = $item->$_ for qw(qty base_qty unit_obj longdescription);
275
      push @items_to_use,   $item_to_use;
276
      push @new_attributes, \%new_attributes;
276 277
    }
277
    $delivery_order = SL::DB::DeliveryOrder->new_from($params{related_order}, items => \@items_to_use, %params);
278

  
279
    $delivery_order = $class->new_from($params{related_order}, items => \@items_to_use, %params);
280
    pairwise { $a->assign_attributes( %$b) } @{$delivery_order->items}, @new_attributes;
278 281

  
279 282
  } else {
280 283
    my %args = (
t/background_job/convert_time_recordings.t
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;

Auch abrufbar als: Unified diff