Revision d066fc37
Von Bernd Bleßmann vor mehr als 9 Jahren hinzugefügt
SL/DB/Helper/FlattenToForm.pm | ||
---|---|---|
7 | 7 |
|
8 | 8 |
use List::MoreUtils qw(any); |
9 | 9 |
|
10 |
use SL::CVar; |
|
11 |
|
|
12 | 10 |
sub flatten_to_form { |
13 | 11 |
my ($self, $form, %params) = @_; |
14 | 12 |
|
... | ... | |
102 | 100 |
} |
103 | 101 |
|
104 | 102 |
sub _copy_custom_variables { |
105 |
my ($src, $form, $prefix, $postfix) = @_; |
|
103 |
my ($src, $form, $prefix, $postfix, $format_amounts) = @_;
|
|
106 | 104 |
|
107 |
my ($module, $sub_module, $trans_id) = ref($src) eq 'SL::DB::OrderItem' ? ('IC', 'orderitems', $src->id) |
|
108 |
: ref($src) eq 'SL::DB::DeliveryOrderItem' ? ('IC', 'delivery_order_items', $src->id) |
|
109 |
: ref($src) eq 'SL::DB::InvoiceItem' ? ('IC', 'invoice', $src->id) |
|
110 |
: ('CT', undef, _has($src, 'customer_id') ? $src->customer_id : $src->vendor_id); |
|
105 |
my $obj = (any { ref($src) eq $_ } qw(SL::DB::OrderItem SL::DB::DeliveryOrderItem SL::DB::InvoiceItem)) |
|
106 |
? $src |
|
107 |
: $src->customervendor; |
|
111 | 108 |
|
112 |
return unless $trans_id; |
|
109 |
foreach my $cvar (@{ $obj->cvars_by_config }) { |
|
110 |
my $value = ($cvar->config->type =~ m{^(?:bool|customer|vendor|part)$}) |
|
111 |
? $cvar->value |
|
112 |
: $cvar->value_as_text; |
|
113 | 113 |
|
114 |
my $cvars = CVar->get_custom_variables(dbh => $src->db->dbh, |
|
115 |
module => $module, |
|
116 |
sub_module => $sub_module, |
|
117 |
trans_id => $trans_id, |
|
118 |
); |
|
119 |
map { $form->{ $prefix . $_->{name} . $postfix } = $_->{value} } @{ $cvars }; |
|
114 |
$form->{ $prefix . $cvar->config->name . $postfix } = $value; |
|
115 |
} |
|
120 | 116 |
|
121 | 117 |
return $src; |
122 | 118 |
} |
Auch abrufbar als: Unified diff
FlattenToForm: CVars auch bei nicht gespeicherten Objekten kopieren.
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.