From d066fc37f559491011c5d9633ba501411cefe8f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 28 Sep 2015 14:53:20 +0200 Subject: [PATCH] FlattenToForm: CVars auch bei nicht gespeicherten Objekten kopieren. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dazu die CVars aus dem Objekt lesen und nicht über SL::CVar. Die Werte sollten dem entsprechen, was SL:CVar->get_custom_variables zurückliefert. --- SL/DB/Helper/FlattenToForm.pm | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/SL/DB/Helper/FlattenToForm.pm b/SL/DB/Helper/FlattenToForm.pm index 9cf2d119f..04101c3f0 100644 --- a/SL/DB/Helper/FlattenToForm.pm +++ b/SL/DB/Helper/FlattenToForm.pm @@ -7,8 +7,6 @@ our @EXPORT = qw(flatten_to_form); use List::MoreUtils qw(any); -use SL::CVar; - sub flatten_to_form { my ($self, $form, %params) = @_; @@ -102,21 +100,19 @@ sub _copy { } sub _copy_custom_variables { - my ($src, $form, $prefix, $postfix) = @_; + my ($src, $form, $prefix, $postfix, $format_amounts) = @_; - my ($module, $sub_module, $trans_id) = ref($src) eq 'SL::DB::OrderItem' ? ('IC', 'orderitems', $src->id) - : ref($src) eq 'SL::DB::DeliveryOrderItem' ? ('IC', 'delivery_order_items', $src->id) - : ref($src) eq 'SL::DB::InvoiceItem' ? ('IC', 'invoice', $src->id) - : ('CT', undef, _has($src, 'customer_id') ? $src->customer_id : $src->vendor_id); + my $obj = (any { ref($src) eq $_ } qw(SL::DB::OrderItem SL::DB::DeliveryOrderItem SL::DB::InvoiceItem)) + ? $src + : $src->customervendor; - return unless $trans_id; + foreach my $cvar (@{ $obj->cvars_by_config }) { + my $value = ($cvar->config->type =~ m{^(?:bool|customer|vendor|part)$}) + ? $cvar->value + : $cvar->value_as_text; - my $cvars = CVar->get_custom_variables(dbh => $src->db->dbh, - module => $module, - sub_module => $sub_module, - trans_id => $trans_id, - ); - map { $form->{ $prefix . $_->{name} . $postfix } = $_->{value} } @{ $cvars }; + $form->{ $prefix . $cvar->config->name . $postfix } = $value; + } return $src; } -- 2.20.1