Zeilenkennung und maximaler Differenzbetrag lassen sich an der Oberfläche eingeben.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 22 Apr 2013 13:31:06 +0000 (15:31 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 25 Nov 2013 13:03:10 +0000 (14:03 +0100)
SL/Controller/CsvImport.pm
SL/Controller/CsvImport/Order.pm
SL/DB/CsvImportProfile.pm
templates/webpages/csv_import/_form_orders.html

index a9df5ad..f21cd2a 100644 (file)
@@ -387,8 +387,7 @@ sub profile_from_form {
   }
 
   if ($self->type eq 'orders') {
-    $::form->{settings}->{order_column} = 'Order';
-    $::form->{settings}->{item_column}  = 'OrderItem';
+    $::form->{settings}->{max_amount_diff} = $::form->parse_amount(\%::myconfig, $::form->{settings}->{max_amount_diff});
   }
 
   delete $::form->{profile}->{id};
index d1a1e46..bcf098d 100644 (file)
@@ -37,7 +37,7 @@ sub init_class {
 sub init_settings {
   my ($self) = @_;
 
-  return { map { ( $_ => $self->controller->profile->get($_) ) } qw(order_column item_column) };
+  return { map { ( $_ => $self->controller->profile->get($_) ) } qw(order_column item_column max_amount_diff) };
 }
 
 
@@ -46,14 +46,25 @@ sub init_profile {
 
   my $profile = $self->SUPER::init_profile;
 
+  # SUPER::init_profile sets row_ident to the class name
+  # overwrite it with the user specified settings
   foreach my $p (@{ $profile }) {
-    my $prof = $p->{profile};
     if ($p->{row_ident} eq 'Order') {
+      $p->{row_ident} = $self->settings->{'order_column'};
+    }
+    if ($p->{row_ident} eq 'OrderItem') {
+      $p->{row_ident} = $self->settings->{'item_column'};
+    }
+  }
+
+  foreach my $p (@{ $profile }) {
+    my $prof = $p->{profile};
+    if ($p->{row_ident} eq $self->settings->{'order_column'}) {
       # no need to handle
       delete @{$prof}{qw(delivery_customer_id delivery_vendor_id proforma quotation amount netamount)};
-      # handable, but not handled by now
     }
-    if ($p->{row_ident} eq 'OrderItem') {
+    if ($p->{row_ident} eq $self->settings->{'item_column'}) {
+      # no need to handle
       delete @{$prof}{qw(trans_id)};
     }
   }
@@ -67,7 +78,7 @@ sub setup_displayable_columns {
 
   $self->SUPER::setup_displayable_columns;
 
-  $self->add_displayable_columns('Order',
+  $self->add_displayable_columns($self->settings->{'order_column'},
                                  { name => 'datatype',         description => $::locale->text('Zeilenkennung')                  },
                                  { name => 'closed',           description => $::locale->text('Closed')                         },
                                  { name => 'curr',             description => $::locale->text('Currency')                       },
@@ -111,7 +122,7 @@ sub setup_displayable_columns {
                                  { name => 'shipto_id',        description => $::locale->text('Ship to (database ID)')          },
                                 );
 
-  $self->add_displayable_columns('OrderItem',
+  $self->add_displayable_columns($self->settings->{'item_column'},
                                  { name => 'datatype',        description => $::locale->text('Zeilenkennung')              },
                                  { name => 'cusordnumber',    description => $::locale->text('Customer Order Number')      },
                                  { name => 'description',     description => $::locale->text('Description')                },
@@ -353,7 +364,6 @@ sub check_objects {
 
   # If amounts are given, show calculated amounts as info and given amounts (verify_xxx).
   # And throw an error if the differences are too big.
-  my $max_diff = 0.02;
   my @to_verify = ( { column      => 'amount',
                       raw_column  => 'verify_amount',
                       info_header => 'Calc. Amount',
@@ -381,7 +391,7 @@ sub check_objects {
       if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'}) {
         next if !$entry->{raw_data}->{ $tv->{raw_column} };
         my $parsed_value = $::form->parse_amount(\%::myconfig, $entry->{raw_data}->{ $tv->{raw_column} });
-        if (abs($entry->{object}->${ \$tv->{column} } - $parsed_value) > $max_diff) {
+        if (abs($entry->{object}->${ \$tv->{column} } - $parsed_value) > $self->settings->{'max_amount_diff'}) {
           push @{ $entry->{errors} }, $::locale->text($tv->{err_msg});
         }
       }
index 21dd484..5a79809 100644 (file)
@@ -54,6 +54,11 @@ sub set_defaults {
                          default_buchungsgruppe    => ($bugru ? $bugru->id : undef),
                          apply_buchungsgruppe      => 'all',
                         );
+  } elsif ($self->type eq 'orders') {
+    $self->_set_defaults(order_column    => 'Order',
+                         item_column     => 'OrderItem',
+                         max_amount_diff => 0.02,
+                        );
   } else {
     $self->_set_defaults(table => 'customer');
   }
index 221f229..728c669 100644 (file)
@@ -3,7 +3,14 @@
 <tr>
  <th align="right">[%- LxERP.t8('Order/Item columns') %]:</th>
  <td colspan="10">
-  [% L.input_tag('settings.order_column', SELF.profile.get('order_column'), size => "5") %]
-  [% L.input_tag('settings.item_column',  SELF.profile.get('item_column'),  size => "5") %]
+  [% L.input_tag('settings.order_column', SELF.profile.get('order_column'), size => "10") %]
+  [% L.input_tag('settings.item_column',  SELF.profile.get('item_column'),  size => "10") %]
+ </td>
+</tr>
+
+<tr>
+ <th align="right">[%- LxERP.t8('Maximal amount difference') %]:</th>
+ <td colspan="10">
+  [% L.input_tag('settings.max_amount_diff', LxERP.format_amount(SELF.profile.get('max_amount_diff')), size => "5") %]
  </td>
 </tr>