From: Moritz Bunkus Date: Mon, 17 Feb 2014 12:04:35 +0000 (+0100) Subject: SL::DB::{DeliveryOrder,Invoice}->new_from: custom_variables der Items mit clonen X-Git-Tag: release-3.2.0beta~491^2~15 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=2714604a9184071fcb3986ac19056da50e5c4a4a;p=kivitendo-erp.git SL::DB::{DeliveryOrder,Invoice}->new_from: custom_variables der Items mit clonen Behebt #2365 auf eine etwas angenehmere Weise als 5bd7e74db1f425a8bbc43357e949efcc1d4eb135. --- diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index 2eecf397d..febf5e27e 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -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); diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index c0a936c7b..8c6965fc4 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -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);