SL::DB::{DeliveryOrder,Invoice}->new_from: custom_variables der Items mit clonen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 17 Feb 2014 12:04:35 +0000 (13:04 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 24 Feb 2014 13:40:01 +0000 (14:40 +0100)
Behebt #2365 auf eine etwas angenehmere Weise als
5bd7e74db1f425a8bbc43357e949efcc1d4eb135.

SL/DB/DeliveryOrder.pm
SL/DB/Invoice.pm

index 2eecf39..febf5e2 100644 (file)
@@ -4,6 +4,8 @@ use strict;
 
 use Carp;
 
+use Rose::DB::Object::Helpers ();
+
 use SL::DB::MetaSetup::DeliveryOrder;
 use SL::DB::Manager::DeliveryOrder;
 use SL::DB::Helper::FlattenToForm;
@@ -81,6 +83,15 @@ sub date {
   goto &transdate;
 }
 
+sub _clone_orderitem_cvar {
+  my ($cvar) = @_;
+
+  my $cloned = Rose::DB::Object::Helpers::clone_and_reset($_);
+  $cloned->sub_module('delivery_order_items');
+
+  return $cloned;
+}
+
 sub new_from {
   my ($class, $source, %params) = @_;
 
@@ -124,11 +135,15 @@ sub new_from {
   my $delivery_order = $class->new(%args, %params);
 
   my @items = map {
-    my $source_item = $_;
+    my $source_item      = $_;
+    my @custom_variables = map { _clone_orderitem_cvar($_) } @{ $source_item->custom_variables };
+
     SL::DB::DeliveryOrderItem->new(map({ ( $_ => $source_item->$_ ) }
-                                   qw(base_qty cusordnumber description discount lastcost longdescription marge_price_factor ordnumber parts_id price_factor price_factor_id
-                                      project_id qty reqdate sellprice serialnumber transdate unit
-                                   )));
+                                         qw(base_qty cusordnumber description discount lastcost longdescription marge_price_factor ordnumber parts_id price_factor price_factor_id
+                                            project_id qty reqdate sellprice serialnumber transdate unit
+                                         )),
+                                   custom_variables => \@custom_variables);
+
   } @{ $source->items_sorted };
 
   $delivery_order->items(\@items);
index c0a936c..8c6965f 100644 (file)
@@ -8,6 +8,8 @@ use strict;
 use Carp;
 use List::Util qw(first);
 
+use Rose::DB::Object::Helpers ();
+
 use SL::DB::MetaSetup::Invoice;
 use SL::DB::Manager::Invoice;
 use SL::DB::Helper::FlattenToForm;
@@ -111,6 +113,15 @@ sub closed {
   return $self->paid >= $self->amount;
 }
 
+sub _clone_orderitem_delivery_order_item_cvar {
+  my ($cvar) = @_;
+
+  my $cloned = Rose::DB::Object::Helpers::clone_and_reset($_);
+  $cloned->sub_module('invoice');
+
+  return $cloned;
+}
+
 sub new_from {
   my ($class, $source, %params) = @_;
 
@@ -152,12 +163,17 @@ sub new_from {
   my $invoice = $class->new(%args, %params);
 
   my @items = map {
-    my $source_item = $_;
+    my $source_item      = $_;
+    my @custom_variables = map { _clone_orderitem_delivery_order_item_cvar($_) } @{ $source_item->custom_variables };
+
     SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) }
                                  qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id ordnumber transdate cusordnumber unit
                                     base_qty longdescription lastcost price_factor_id), @item_columns),
-                            deliverydate => $source_item->reqdate,
-                            fxsellprice  => $source_item->sellprice,);
+                             deliverydate     => $source_item->reqdate,
+                             fxsellprice      => $source_item->sellprice,
+                             custom_variables => \@custom_variables,
+                           );
+
   } @{ $source->items_sorted };
 
   $invoice->invoiceitems(\@items);