Letter: model sortierung benutzen
[kivitendo-erp.git] / SL / Controller / PriceSource.pm
index b7ee8bd..aea9f46 100644 (file)
@@ -5,14 +5,13 @@ use strict;
 use parent qw(SL::Controller::Base);
 
 use List::MoreUtils qw(any uniq apply);
-use SL::ClientJS;
 use SL::Locale::String qw(t8);
 use SL::PriceSource;
 
 use Rose::Object::MakeMethods::Generic
 (
  scalar => [ qw(record_item) ],
- 'scalar --get_set_init' => [ qw(js record) ],
+ 'scalar --get_set_init' => [ qw(record) ],
 );
 
 __PACKAGE__->run_before('check_auth');
@@ -25,6 +24,12 @@ sub action_price_popup {
   my ($self) = @_;
 
   my $record_item = _make_record_item($::form->{row});
+  my $old_unit;
+  if (($old_unit = $record_item->{__additional_form_attributes}{unit_old}) && $old_unit ne $record_item->unit) {
+    # reset unit changes. the way these interact on update breaks stuff
+    $record_item->unit_obj(SL::DB::Manager::Unit->find_by(name => $old_unit));
+    $self->js->val("select[name='unit_$::form->{row}']", $old_unit);
+  }
 
   $self->render_price_dialog($record_item);
 }
@@ -47,7 +52,7 @@ sub render_price_dialog {
 #     $self->js->show('#dialog_flash_error');
 #   }
 
-  $self->js->render($self);
+  $self->js->render;
 }
 
 
@@ -59,10 +64,6 @@ sub check_auth {
   $::auth->assert('edit_prices');
 }
 
-sub init_js {
-  SL::ClientJS->new
-}
-
 sub init_record {
   _make_record();
 }
@@ -93,15 +94,18 @@ sub _make_record_item {
           : $class->new;
 
   for my $method (apply { s/_$row$// } grep { /_$row$/ } keys %$::form) {
-    next unless $obj->meta->column($method);
-    if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
-      $obj->${\"$method\_as_date"}($::form->{"$method\_$row"});
-    } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) {
-      $obj->${\"$method\_as_number"}($::form->{"$method\_$row"});
-    } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::Boolean$/) {
-      $obj->$method(!!$::form->{$method});
+    if ($obj->meta->column($method)) {
+      if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
+        $obj->${\"$method\_as_date"}($::form->{"$method\_$row"});
+      } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) {
+        $obj->${\"$method\_as_number"}($::form->{"$method\_$row"});
+      } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::Boolean$/) {
+        $obj->$method(!!$::form->{$method});
+      } else {
+        $obj->$method($::form->{"$method\_$row"});
+      }
     } else {
-      $obj->$method($::form->{"$method\_$row"});
+      $obj->{__additional_form_attributes}{$method} = $::form->{"$method\_$row"};
     }
   }