Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c8774e89

Von Tamino Steinert vor etwa 2 Jahren hinzugefügt

  • ID c8774e89fea91da739dd83b9b867ad0ab6eb9956
  • Vorgänger 08e12ce7
  • Nachfolger 6fb26f9a

Workflow: delivery_order ↔ reclamation

Unterschiede anzeigen:

SL/DB/Reclamation.pm
216 216
  return $order;
217 217
}
218 218

  
219
sub convert_to_delivery_order {
220
  my ($self, %params) = @_;
221

  
222
  my $delivery_order;
223
  if (!$self->db->with_transaction(sub {
224
    require SL::DB::DeliveryOrder;
225
    $delivery_order = SL::DB::DeliveryOrder->new_from($self, %params);
226
    $delivery_order->save;
227
    $self->link_to_record($delivery_order);
228
    # TODO extend link_to_record for items, otherwise long-term no d.r.y.
229
    foreach my $item (@{ $delivery_order->items }) {
230
      foreach (qw(reclamation_items)) {
231
        if ($item->{"converted_from_${_}_id"}) {
232
          die unless $item->{id};
233
          RecordLinks->create_links('dbh'        => $self->db->dbh,
234
                                    'mode'       => 'ids',
235
                                    'from_table' => $_,
236
                                    'from_ids'   => $item->{"converted_from_${_}_id"},
237
                                    'to_table'   => 'delivery_order_items',
238
                                    'to_id'      => $item->{id},
239
          ) || die;
240
          delete $item->{"converted_from_${_}_id"};
241
        }
242
      }
243
    }
244

  
245
    $self->update_attributes(delivered => 1) unless $::instance_conf->get_shipped_qty_require_stock_out;
246
    1;
247
  })) {
248
    return undef, $self->db->error->db_error->db_error;
249
  }
250

  
251
  return $delivery_order, undef;
252
}
253

  
219 254
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden
220 255
sub new_from {
221 256
  my ($class, $source, %params) = @_;
222 257
  my %allowed_sources = map { $_ => 1 } qw(
223 258
    SL::DB::Reclamation
224 259
    SL::DB::Order
260
    SL::DB::DeliveryOrder
225 261
  );
226 262
  unless( $allowed_sources{ref $source} ) {
227 263
    croak("Unsupported source object type '" . ref($source) . "'");
......
239 275
    #Order
240 276
    { from => 'sales_order',             to => 'sales_reclamation',    abbr => 'sosr', },
241 277
    { from => 'purchase_order',          to => 'purchase_reclamation', abbr => 'popr', },
278
    #Delivery Order
279
    { from => 'sales_delivery_order',    to => 'sales_reclamation',    abbr => 'sdsr', },
280
    { from => 'purchase_delivery_order', to => 'purchase_reclamation', abbr => 'pdpr', },
242 281
  );
243 282
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
244 283
  if (!$from_to) {
......
310 349
    $record_args{contact_id} = $source->cp_id;
311 350
    $record_args{cv_record_number} = $source->cusordnumber;
312 351
    # }}} for vim folds
352
  } elsif ( $is_abbr_any->(qw(sdsr pdpr)) ) { #DeliveryOrder
353
    map { $record_args{$_} = $source->$_ } # {{{ for vim folds
354
    qw(
355
      currency_id
356
      customer_id
357
      delivery_term_id
358
      department_id
359
      globalproject_id
360
      intnotes
361
      language_id
362
      notes
363
      payment_id
364
      salesman_id
365
      shippingpoint
366
      shipvia
367
      tax_point
368
      taxincluded
369
      taxzone_id
370
      transaction_description
371
      vendor_id
372
    );
373
    $record_args{contact_id} = $source->cp_id;
374
    $record_args{cv_record_number} = $source->cusordnumber;
375
    # }}} for vim folds
313 376
  }
314 377

  
315 378
  if ( ($from_to->{from} =~ m{sales}) && ($from_to->{to} =~ m{purchase}) ) {

Auch abrufbar als: Unified diff