Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cbb8eb07

Von Sven Schöling vor mehr als 3 Jahren hinzugefügt

  • ID cbb8eb078305a3eeca9c6c192a66176676da54f8
  • Vorgänger 95dd02de
  • Nachfolger 8f413df4

ShippedQty: delivered korrekt setzen

Wenn der Helper ohne fill_up aufgerufen wurde, wurden nicht existierende
Positionen für die delivered Berechnung ignoriert

Unterschiede anzeigen:

SL/Helper/ShippedQty.pm
270 270
  $self->shipped_qty({});
271 271
}
272 272

  
273
# some of the invocations never need to load all orderitems to copute their answers
274
# delivered however needs oi_qty to be set for each orderitem to decide whether
275
# delivered should be set or not.
276
sub ensure_all_orderitems_for_orders {
277
  my ($self) = @_;
278

  
279
  return if $self->fill_up;
280

  
281
  my $oi_query  = sprintf $fill_up_oi_query,   join (', ', ('?')x@{ $self->oe_ids });
282
  my $oi  = selectall_hashref_query($::form, $self->dbh, $oi_query, @{ $self->oe_ids });
283
  for (@$oi) {
284
    $self->{oi_qty}{ $_->{id} } //= $_->{qty};
285
    $self->{oi2oe}{ $_->{id} }  //= $_->{trans_id};
286
  }
287
}
288

  
273 289
sub available_item_identity_fields {
274 290
  map { [ $_ => $item_identity_fields{$_} ] } @known_item_identity_fields;
275 291
}
......
291 307
sub init_matches { [] }
292 308
sub init_delivered {
293 309
  my ($self) = @_;
310

  
311
  $self->ensure_all_orderitems_for_orders;
312

  
294 313
  my $d = { };
295 314
  for (keys %{ $self->oi_qty }) {
296 315
    my $oe_id = $self->oi2oe->{$_};
t/helper/shipped_qty.t
49 49
  new_part( %part_defaults, partnumber => $i, description => "part $i test" )->save;
50 50
};
51 51

  
52
my $part1 = SL::DB::Manager::Part->find_by( partnumber => '1' );
53
my $part2 = SL::DB::Manager::Part->find_by( partnumber => '2' );
54
my $part3 = SL::DB::Manager::Part->find_by( partnumber => '3' );
55
my $part4 = SL::DB::Manager::Part->find_by( partnumber => '4' );
52
my $part1 = SL::DB::Manager::Part->find_by( partnumber => '1' ) or die;
53
my $part2 = SL::DB::Manager::Part->find_by( partnumber => '2' ) or die;
54
my $part3 = SL::DB::Manager::Part->find_by( partnumber => '3' ) or die;
55
my $part4 = SL::DB::Manager::Part->find_by( partnumber => '4' ) or die;
56 56

  
57 57
my @part_ids; # list of all part_ids to run checks against
58 58
push( @part_ids, $_->id ) foreach ( $part1, $part2, $part3, $part4 );
......
305 305

  
306 306
  is $order->items_sorted->[0]->{shipped_qty}, 5, 'unlinked legacy position test 1';
307 307
  is $order->items_sorted->[1]->{shipped_qty}, 3, 'unlinked legacy position test 2';
308

  
309
}
310

  
311
{
312
# edge case:
313
#
314
# suppose an order was delivered, and someone removes one item from the delivery order.
315
# make sure the order is then shown as not delivered.
316
#
317
  my $sales_order = create_sales_order(
318
    save       => 1,
319
    orderitems => [ create_order_item(part => new_part()->save, qty => 5),
320
                    create_order_item(part => new_part()->save, qty => 6),
321
                    create_order_item(part => new_part()->save, qty => 7),
322
                  ]
323
  );
324
  $sales_order->load;
325

  
326
  my $delivery_order = SL::DB::DeliveryOrder->new_from($sales_order);
327
  $delivery_order->save;
328

  
329
  $delivery_order->items(@{ $delivery_order->items_sorted }[0..1]);
330
  $delivery_order->save;
331

  
332
  SL::Helper::ShippedQty
333
    ->new(fill_up => 0, require_stock_out => 0)
334
    ->calculate($sales_order)
335
    ->write_to_objects;
336

  
337
  ok !$sales_order->delivered, 'after deleting a position from a delivery order, the order is undelivered again';
308 338
}
309 339

  
310 340
clear_up();

Auch abrufbar als: Unified diff