From f24b365c19384f9c7a4a19b55a2a0df692ab3747 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 21 Jun 2017 16:29:03 +0200 Subject: [PATCH] PriceSource Controller: parts_id/orderitems_id translation --- SL/Controller/PriceSource.pm | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/SL/Controller/PriceSource.pm b/SL/Controller/PriceSource.pm index aea9f4645..41ad793ae 100644 --- a/SL/Controller/PriceSource.pm +++ b/SL/Controller/PriceSource.pm @@ -87,25 +87,44 @@ sub _make_record_item { $class = 'SL::DB::' . $class; + my %translated_methods = ( + 'SL::DB::OrderItem' => { + id => 'parts_id', + orderitems_id => 'id', + }, + 'SL::DB::DeliveryOrderItem' => { + id => 'parts_id', + delivery_order_items_id => 'id', + }, + 'SL::DB::InvoiceItem' => { + id => 'parts_id', + invoice_id => 'id', + }, + ); + eval "require $class"; my $obj = $::form->{"orderitems_id_$row"} ? $class->meta->convention_manager->auto_manager_class_name->find_by(id => $::form->{"orderitems_id_$row"}) : $class->new; - for my $method (apply { s/_$row$// } grep { /_$row$/ } keys %$::form) { + for my $key (grep { /_$row$/ } keys %$::form) { + my $method = $key; + $method =~ s/_$row$//; + $method = $translated_methods{$class}{$method} // $method; + my $value = $::form->{$key}; if ($obj->meta->column($method)) { if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) { - $obj->${\"$method\_as_date"}($::form->{"$method\_$row"}); + $obj->${\"$method\_as_date"}($value); } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) { - $obj->${\"$method\_as_number"}($::form->{"$method\_$row"}); + $obj->${\"$method\_as_number"}($value); } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::Boolean$/) { - $obj->$method(!!$::form->{$method}); + $obj->$method(!!$value); } else { - $obj->$method($::form->{"$method\_$row"}); + $obj->$method($value); } } else { - $obj->{__additional_form_attributes}{$method} = $::form->{"$method\_$row"}; + $obj->{__additional_form_attributes}{$method} = $value; } } -- 2.20.1