]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/CsvImport/Part.pm
BUG-Fix: Funktion "Erzeugnis fertigen" sucht Bestandteile im falschen Lager.
[mfinanz.git] / SL / Controller / CsvImport / Part.pm
index 34bdd73655e637d61b19d5ebb2c4059a4dfa2f0d..98ee01d74fdbd2db3d27b3f0d037695912905255 100644 (file)
@@ -27,6 +27,24 @@ use Rose::Object::MakeMethods::Generic
                                  translation_columns all_pricegroups) ],
 );
 
+sub set_profile_defaults {
+  my ($self) = @_;
+
+  my $bugru = SL::DB::Manager::Buchungsgruppe->find_by(description => { like => 'Standard%19%' });
+
+  $self->controller->profile->_set_defaults(
+                       sellprice_places          => 2,
+                       sellprice_adjustment      => 0,
+                       sellprice_adjustment_type => 'percent',
+                       article_number_policy     => 'update_prices',
+                       shoparticle_if_missing    => '0',
+                       parts_type                => 'part',
+                       default_buchungsgruppe    => ($bugru ? $bugru->id : undef),
+                       apply_buchungsgruppe      => 'all',
+                      );
+};
+
+
 sub init_class {
   my ($self) = @_;
   $self->class('SL::DB::Part');
@@ -196,7 +214,7 @@ sub check_buchungsgruppe {
 
   return 1 if $object->buchungsgruppen_id;
 
-  push @{ $entry->{errors} }, $::locale->text('Error: Buchungsgruppe missing or invalid');
+  push @{ $entry->{errors} }, $::locale->text('Error: booking group missing or invalid');
   return 0;
 }
 
@@ -258,7 +276,7 @@ sub check_type {
   my ($self, $entry) = @_;
 
   my $bg = $self->bg_by->{id}->{ $entry->{object}->buchungsgruppen_id };
-  $bg  ||= SL::DB::Buchungsgruppe->new(inventory_accno_id => 1, income_accno_id_0 => 1, expense_accno_id_0 => 1);
+  $bg  ||= SL::DB::Buchungsgruppe->new(inventory_accno_id => 1); # does this case ever occur?
 
   my $type = $self->settings->{parts_type};
   if ($type eq 'mixed') {
@@ -270,17 +288,21 @@ sub check_type {
 
   $entry->{object}->assembly($type eq 'assembly');
 
-  $entry->{object}->income_accno_id( $bg->income_accno_id_0 );
+  # when saving income_accno_id or expense_accno_id use ids from the selected
+  # $bg according to the default tax_zone (the one with the highest sort
+  # order).  Alternatively one could use the ids from defaults, but they might
+  # not all be set.
+
+  $entry->{object}->income_accno_id( $bg->income_accno_id( SL::DB::Manager::TaxZone->get_default->id ) );
 
   if ($type eq 'part' || $type eq 'service') {
-    $entry->{object}->expense_accno_id( $bg->expense_accno_id_0 );
+    $entry->{object}->expense_accno_id( $bg->expense_accno_id( SL::DB::Manager::TaxZone->get_default->id ) );
   }
 
   if ($type eq 'part') {
     $entry->{object}->inventory_accno_id( $bg->inventory_accno_id );
   }
 
-
   if (none { $_ eq $type } qw(part service assembly)) {
     push @{ $entry->{errors} }, $::locale->text('Error: Invalid part type');
     return 0;
@@ -423,10 +445,11 @@ sub handle_makemodel {
     return;
   }
 
-  my %old_makemodels_by_make = map { $_->make => $_ } $entry->{part}->makemodels;
+  my %old_makemodels_by_mm = map { $_->make . $; . $_->model => $_ } $entry->{part}->makemodels;
+  my @new_makemodels;
 
   foreach my $makemodel ($object->makemodels()) {
-    my $makemodel_orig = $old_makemodels_by_make{$makemodel->make};
+    my $makemodel_orig = $old_makemodels_by_mm{$makemodel->make,$makemodel->model};
     $found_any = 1;
 
     if ($makemodel_orig) {
@@ -434,11 +457,15 @@ sub handle_makemodel {
       $makemodel_orig->lastcost($makemodel->lastcost);
 
     } else {
-      $entry->{part}->add_makemodels($makemodel);
+      push @new_makemodels, $makemodel;
     }
   }
 
-  $entry->{part}->makemodel($object->makemodel);
+  $entry->{part}->makemodels([ $entry->{part}->makemodels, @new_makemodels ]) if @new_makemodels;
+
+  # reindex makemodels
+  my $i = 0;
+  $_->sortorder(++$i) for @{ $entry->{part}->makemodels };
 
   $self->save_with_cascade(1) if $found_any;
 }
@@ -479,8 +506,8 @@ sub setup_displayable_columns {
   $self->add_cvar_columns_to_displayable_columns;
 
   $self->add_displayable_columns({ name => 'bin',                description => $::locale->text('Bin')                                                  },
-                                 { name => 'buchungsgruppen_id', description => $::locale->text('Buchungsgruppe (database ID)')                         },
-                                 { name => 'buchungsgruppe',     description => $::locale->text('Buchungsgruppe (name)')                                },
+                                 { name => 'buchungsgruppen_id', description => $::locale->text('Booking group (database ID)')                          },
+                                 { name => 'buchungsgruppe',     description => $::locale->text('Booking group (name)')                                 },
                                  { name => 'description',        description => $::locale->text('Description')                                          },
                                  { name => 'drawing',            description => $::locale->text('Drawing')                                              },
                                  { name => 'ean',                description => $::locale->text('EAN')                                                  },
@@ -507,7 +534,7 @@ sub setup_displayable_columns {
                                  { name => 'price_factor',       description => $::locale->text('Price factor (name)')                                  },
                                  { name => 'rop',                description => $::locale->text('ROP')                                                  },
                                  { name => 'sellprice',          description => $::locale->text('Sellprice')                                            },
-                                 { name => 'shop',               description => $::locale->text('Shopartikel')                                          },
+                                 { name => 'shop',               description => $::locale->text('Shop article')                                         },
                                  { name => 'type',               description => $::locale->text('Article type')  . ' [3]'                             },
                                  { name => 'unit',               description => $::locale->text('Unit (if missing or empty default unit will be used)') },
                                  { name => 've',                 description => $::locale->text('Verrechnungseinheit')                                  },