Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c888c8a7

Von Sven Schöling vor mehr als 1 Jahr hinzugefügt

  • ID c888c8a7c4cf9cad2d63fc7adbc3e1f859e2efe3
  • Vorgänger a31c242b
  • Nachfolger c4fb78fe

RecordLink: converted_from_* Felder in allen convert_to und new_from korrekt setzen.

Das hier benutzt jetzt das neue Reclamation Format. Statt

converted_from_oe_id

wird jetzt

converted_from_record_id
converted_from_record_type_ref = SL::DB::Order

benutzt.

Unterschiede anzeigen:

SL/DB/DeliveryOrder.pm
249 249
  my $items = delete($params{items}) || $source->items_sorted;
250 250
  my @items = ( $delivery_order->is_type(SUPPLIER_DELIVERY_ORDER_TYPE) && ref($source) ne 'SL::DB::Reclamation' ) ?
251 251
                ()
252
              : map { SL::DB::DeliveryOrderItem->new_from($_) } @{ $items };
252
              : map { SL::DB::DeliveryOrderItem->new_from($_, %params) } @{ $items };
253 253

  
254 254
  @items = grep { $params{item_filter}->($_) } @items if $params{item_filter};
255 255
  @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty};
......
257 257

  
258 258
  $delivery_order->items(\@items);
259 259

  
260
  unless ($params{no_linked_records}) {
261
    $delivery_order->{ RECORD_ID() } = $source->id;
262
    $delivery_order->{ RECORD_TYPE_REF() } = ref $source;
263
  }
264

  
260 265
  return $delivery_order;
261 266
}
262 267

  
......
405 410
  if (!$self->db->with_transaction(sub {
406 411
    require SL::DB::Invoice;
407 412
    $invoice = SL::DB::Invoice->new_from($self, %params)->post || die;
408
    $self->link_to_record($invoice);
409
    # TODO extend link_to_record for items, otherwise long-term no d.r.y.
410
    foreach my $item (@{ $invoice->items }) {
411
      foreach (qw(delivery_order_items)) {    # expand if needed (orderitems)
412
        if ($item->{"converted_from_${_}_id"}) {
413
          die unless $item->{id};
414
          RecordLinks->create_links('mode'       => 'ids',
415
                                    'from_table' => $_,
416
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
417
                                    'to_table'   => 'invoice',
418
                                    'to_id'      => $item->{id},
419
          ) || die;
420
          delete $item->{"converted_from_${_}_id"};
421
        }
422
      }
423
    }
424 413
    $self->update_attributes(closed => 1);
425 414
    1;
426 415
  })) {
SL/DB/DeliveryOrderItem.pm
10 10
use SL::DB::Manager::DeliveryOrderItem;
11 11
use SL::DB::Helper::ActsAsList;
12 12
use SL::DB::Helper::LinkedRecords;
13
use SL::DB::Helper::RecordLink qw(RECORD_ITEM_ID RECORD_ITEM_TYPE_REF);
13 14
use SL::DB::Helper::RecordItem;
14 15
use SL::DB::Helper::CustomVariables (
15 16
  sub_module  => 'delivery_order_items',
......
107 108

  
108 109
  my $item = $class->new(%item_args);
109 110

  
110
  my $source_table = '';
111
  if( ref($source) eq 'SL::DB::OrderItem' ) {
112
    $source_table = 'orderitems';
113
  } elsif ( ref($source) eq 'SL::DB::ReclamationItem' ) {
114
    $source_table = 'reclamation_items';
111
  unless ($params{no_linked_records}) {
112
    $item->{ RECORD_ITEM_ID() } = $source->id;
113
    $item->{ RECORD_ITEM_TYPE_REF() } = ref $source;
115 114
  }
116
  $item->{"converted_from_". $source_table ."_id"} = $_->{id};
117 115

  
118 116
  return $item;
119 117
}
SL/DB/Invoice.pm
272 272
                               donumber         => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber  : $source_item->can('donumber') ? $source_item->donumber : '',
273 273
                             );
274 274

  
275
    $current_invoice_item->{"converted_from_orderitems_id"}           = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
276
    $current_invoice_item->{"converted_from_delivery_order_items_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::DeliveryOrder';
275
    $current_invoice_item->{RECORD_ITEM_ID()}           = $_->{id};
276
    $current_invoice_item->{RECORD_ITEM_TYPE_REF()}     = ref $source_item;
277 277
    $current_invoice_item;
278 278
  } @{ $items };
279 279

  
280
  $invoice->{RECORD_ID()}           = $source->id;
281
  $invoice->{RECORD_TYPE_REF()}     = ref $source;
282

  
280 283
  @items = grep { $params{item_filter}->($_) } @items if $params{item_filter};
281 284
  @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty};
282 285
  @items = grep { $_->qty >=0 } @items if $params{skip_items_negative_qty};
SL/DB/Order.pm
273 273
  if (!$self->db->with_transaction(sub {
274 274
    require SL::DB::Invoice;
275 275
    $invoice = SL::DB::Invoice->new_from($self, %params)->post || die;
276
    $self->link_to_record($invoice);
277
    # TODO extend link_to_record for items, otherwise long-term no d.r.y.
278
    foreach my $item (@{ $invoice->items }) {
279
      foreach (qw(orderitems)) {
280
        if ($item->{"converted_from_${_}_id"}) {
281
          die unless $item->{id};
282
          RecordLinks->create_links('mode'       => 'ids',
283
                                    'from_table' => $_,
284
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
285
                                    'to_table'   => 'invoice',
286
                                    'to_id'      => $item->{id},
287
          ) || die;
288
          delete $item->{"converted_from_${_}_id"};
289
        }
290
      }
291
    }
292 276
    $self->update_attributes(closed => 1);
293 277
    1;
294 278
  })) {
......
306 290
    require SL::DB::DeliveryOrder;
307 291
    $delivery_order = SL::DB::DeliveryOrder->new_from($self, @args);
308 292
    $delivery_order->save;
309
    $self->link_to_record($delivery_order);
310
    # TODO extend link_to_record for items, otherwise long-term no d.r.y.
311
    foreach my $item (@{ $delivery_order->items }) {
312
      foreach (qw(orderitems)) {    # expand if needed (delivery_order_items)
313
        if ($item->{"converted_from_${_}_id"}) {
314
          die unless $item->{id};
315
          RecordLinks->create_links('dbh'        => $self->db->dbh,
316
                                    'mode'       => 'ids',
317
                                    'from_table' => $_,
318
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
319
                                    'to_table'   => 'delivery_order_items',
320
                                    'to_id'      => $item->{id},
321
          ) || die;
322
          delete $item->{"converted_from_${_}_id"};
323
        }
324
      }
325
    }
326 293

  
327 294
    $self->update_attributes(delivered => 1) unless $::instance_conf->get_shipped_qty_require_stock_out;
328 295
    1;
......
518 485
    if ( $is_abbr_any->(qw(poso rqsq rqso)) ) {
519 486
      $current_oe_item->lastcost($source_item->sellprice);
520 487
    }
521
    $current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
522
    $current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation';
488
    $current_oe_item->{ RECORD_ITEM_ID() } = $_->{id};
489
    $current_oe_item->{ RECORD_ITEM_TYPE_REF() } = ref($source_item);
523 490
    $current_oe_item;
524 491
  } @{ $items };
525 492

  
......
529 496

  
530 497
  $order->items(\@items);
531 498

  
499
  $order->{ RECORD_ID() } = $source->{id};
500
  $order->{ RECORD_TYPE_REF() } = ref($source);
501

  
532 502
  return $order;
533 503
}
534 504

  
SL/DB/Reclamation.pm
206 206
    require SL::DB::Order;
207 207
    $order = SL::DB::Order->new_from($self, %params);
208 208
    $order->save;
209
    $self->link_to_record($order);
210
    foreach my $item (@{ $order->items }) {
211
      foreach (qw(reclamation_item)) {
212
        if ($item->{"converted_from_${_}_id"}) {
213
          die unless $item->{id};
214
          RecordLinks->create_links('dbh'        => $self->db->dbh,
215
                                    'mode'       => 'ids',
216
                                    'from_table' => 'reclamation_items',
217
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
218
                                    'to_table'   => 'orderitems',
219
                                    'to_id'      => $item->{id},
220
          ) || die;
221
          delete $item->{"converted_from_${_}_id"};
222
        }
223
      }
224
    }
225 209

  
226 210
    1;
227 211
  })) {
......
239 223
    require SL::DB::DeliveryOrder;
240 224
    $delivery_order = SL::DB::DeliveryOrder->new_from($self, %params);
241 225
    $delivery_order->save;
242
    $self->link_to_record($delivery_order);
243
    # TODO extend link_to_record for items, otherwise long-term no d.r.y.
244
    foreach my $item (@{ $delivery_order->items }) {
245
      foreach (qw(reclamation_items)) {
246
        if ($item->{"converted_from_${_}_id"}) {
247
          die unless $item->{id};
248
          RecordLinks->create_links('dbh'        => $self->db->dbh,
249
                                    'mode'       => 'ids',
250
                                    'from_table' => $_,
251
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
252
                                    'to_table'   => 'delivery_order_items',
253
                                    'to_id'      => $item->{id},
254
          ) || die;
255
          delete $item->{"converted_from_${_}_id"};
256
        }
257
      }
258
    }
259 226

  
260 227
    $self->update_attributes(delivered => 1) unless $::instance_conf->get_shipped_qty_require_stock_out;
261 228
    1;

Auch abrufbar als: Unified diff