]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Order.pm
Auftrags-Controller: CVars die nicht editierbar und nicht "valid" sind, behandeln …
[mfinanz.git] / SL / Controller / Order.pm
index abb53f274e4d249b4aed226bfc735084154a5df2..469eb40f0d167ecf145197370bdeaf0d7cedc5bc 100644 (file)
@@ -89,7 +89,7 @@ sub action_save {
     return $self->js->render($self);
   }
 
-  flash_later('info', 'The order has been saved');
+  flash_later('info', $::locale->text('The order has been saved'));
   my @redirect_params = (
     action => 'edit',
     type   => $self->type,
@@ -151,17 +151,22 @@ sub action_add_item {
   $new_attr{sellprice}   = $part->sellprice   if ! $item->sellprice;
   $new_attr{discount}    = $cv_discount       if ! $item->discount;
 
+  # add_custom_variables adds cvars to an orderitem with no cvars for saving, but
+  # they cannot be retrieved via custom_variables until the order/orderitem is
+  # saved. Adding empty custom_variables to new orderitem here solves this problem.
+  $new_attr{custom_variables} = [];
+
   $item->assign_attributes(%new_attr);
-  $item->id(join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000)) if !$item->id;
 
   $self->order->add_items($item);
 
   $self->_recalc();
 
-  my $row_as_html = $self->p->render('order/tabs/_row', ITEM => $item);
+  my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+  my $row_as_html = $self->p->render('order/tabs/_row', ITEM => $item, ID => $item_id);
 
   $self->js
-    ->append('#row_table_id tbody', $row_as_html)
+    ->append('#row_table_id', $row_as_html)
     ->val('#add_item_parts_id', '')
     ->val('#add_item_parts_id_name', '')
     ->val('#add_item_description', '')
@@ -169,6 +174,7 @@ sub action_add_item {
     ->val('#add_item_sellprice_as_number', '')
     ->val('#add_item_discount_as_percent', '')
     ->run('row_table_scroll_down')
+    ->run('row_set_keyboard_events_by_id', $item_id)
     ->focus('#add_item_parts_id_name');
 
   $self->_js_redisplay_amounts_and_taxes;
@@ -316,6 +322,11 @@ sub _recalc {
 sub _save {
   my ($self) = @_;
 
+  # autovivify all cvars that are not in the form (cvars_by_config can do it)
+  foreach my $item (@{ $self->order->items }) {
+    $item->cvars_by_config;
+  }
+
   my $errors = [];
   my $db = $self->order->db;