Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 640e3288

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

  • ID 640e3288c054e5928f5020b583ac1f194230f96e
  • Vorgänger 9dd69536
  • Nachfolger d9676896

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

  
329 296
    $self->update_attributes(delivered => 1) unless $::instance_conf->get_shipped_qty_require_stock_out;
330 297
    1;
......
543 510
    if ( $is_abbr_any->(qw(poso rqsq rqso pqisq pqiso)) ) {
544 511
      $current_oe_item->lastcost($source_item->sellprice);
545 512
    }
546
    $current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
547
    $current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation';
513
    $current_oe_item->{ RECORD_ITEM_ID() } = $_->{id};
514
    $current_oe_item->{ RECORD_ITEM_TYPE_REF() } = ref($source_item);
548 515
    $current_oe_item;
549 516
  } @{ $items };
550 517

  
......
554 521

  
555 522
  $order->items(\@items);
556 523

  
524
  $order->{ RECORD_ID() } = $source->{id};
525
  $order->{ RECORD_TYPE_REF() } = ref($source);
526

  
557 527
  return $order;
558 528
}
559 529

  
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