Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c2075a3c

Von Sven Schöling vor etwa 3 Jahren hinzugefügt

  • ID c2075a3cea6b4cd86cda2228c6fd777169b2890b
  • Vorgänger cac8aa9f
  • Nachfolger 9e894885

DeliveryOrder: stock roundtrip

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
911 911
    do_unit    => $unit,
912 912
    delivered  => $self->order->delivered,
913 913
    row        => $row,
914
    itme_id    => $item_id,
914
    item_id    => $item_id,
915 915
  );
916 916
}
917 917

  
......
1272 1272
  # You need a custom shipto object to call cvars_by_config to get the cvars.
1273 1273
  $self->order->custom_shipto(SL::DB::Shipto->new(module => 'OE', custom_variables => [])) if !$self->order->custom_shipto;
1274 1274

  
1275
  $self->prepare_stock_info($_) for $self->order->items;
1276

  
1275 1277
  return $self->order;
1276 1278
}
1277 1279

  
......
1321 1323
    push @items, $item;
1322 1324
    $pos++;
1323 1325
  }
1326

  
1327
  $self->prepare_stock_info($_) for $order->items, @items;
1328

  
1324 1329
  $order->add_items(grep {!$_->id} @items);
1325 1330

  
1326 1331
  return $order;
......
1343 1348
  # saved. Adding empty custom_variables to new orderitem here solves this problem.
1344 1349
  $item ||= SL::DB::DeliveryOrderItem->new(custom_variables => []);
1345 1350

  
1351
  # handle stock info
1352
  if (my $stock_info = delete $attr->{stock_info}) {
1353
    my %existing = map { $_->id => $_ } $item->delivery_order_stock_entries;
1354
    my @save;
1355

  
1356
    for my $line (@{ DO->unpack_stock_information(packed => $stock_info) }) {
1357
      # lookup existing or make new
1358
      my $obj = delete $existing{$line->{delivery_order_items_stock_id}}
1359
             // SL::DB::DeliveryOrderItemsStock->new;
1360

  
1361
      # assign attributes
1362
      $obj->$_($line->{$_}) for qw(bin_id warehouse_id chargenumber qty unit);
1363
      $obj->bestbefore_as_date($line->{bestfbefore})
1364
        if $line->{bestbefore} && $::instance_conf->get_show_bestbefore;
1365
      push @save, $obj;
1366
    }
1367

  
1368
    $item->delivery_order_stock_entries(@save);
1369
  }
1370

  
1346 1371
  $item->assign_attributes(%$attr);
1347 1372

  
1348 1373
  if ($is_new) {
......
1428 1453
  return $item;
1429 1454
}
1430 1455

  
1456
sub prepare_stock_info {
1457
  my ($self, $item) = @_;
1458

  
1459
  $item->{stock_info} = SL::YAML::Dump([
1460
    map +{
1461
      delivery_order_items_stock_id => $_->id,
1462
      qty                           => $_->qty,
1463
      warehouse_id                  => $_->warehouse_id,
1464
      bin_id                        => $_->bin_id,
1465
      chargenumber                  => $_->chargenumber,
1466
      unit                          => $_->unit,
1467
    }, $item->delivery_order_stock_entries
1468
  ]);
1469
}
1470

  
1431 1471
sub setup_order_from_cv {
1432 1472
  my ($order) = @_;
1433 1473

  

Auch abrufbar als: Unified diff