From: Moritz Bunkus Date: Fri, 3 Jun 2011 08:18:54 +0000 (+0200) Subject: Verhindern, dass Artikelnummern mehrfach vergeben werden X-Git-Tag: release-2.6.3~25^2~3 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=df0d4d3fb8a275b7f96a260d403966c873123666;p=kivitendo-erp.git Verhindern, dass Artikelnummern mehrfach vergeben werden Fix für Bug 1667. --- diff --git a/SL/IC.pm b/SL/IC.pm index cf7c99c36..bbf475310 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -40,6 +40,7 @@ use YAML; use SL::CVar; use SL::DBUtils; +use SL::TransNumber; use strict; @@ -311,6 +312,11 @@ sub save { my $priceupdate = ', priceupdate = current_date'; if ($form->{id}) { + my $trans_number = SL::TransNumber->new(type => $form->{item}, dbh => $dbh, number => $form->{partnumber}, id => $form->{id}); + if (!$trans_number->is_unique) { + $::lxdebug->leave_sub; + return 3; + } # get old price $query = qq|SELECT sellprice, weight FROM parts WHERE id = ?|; @@ -346,23 +352,19 @@ sub save { $priceupdate = '' if (all { $previous_values->{$_} == $form->{$_} } qw(sellprice lastcost listprice)); } else { - my ($count) = selectrow_query($form, $dbh, qq|SELECT COUNT(*) FROM parts WHERE partnumber = ?|, $form->{partnumber}); - if ($count) { - $main::lxdebug->leave_sub(); + my $trans_number = SL::TransNumber->new(type => $form->{item}, dbh => $dbh, number => $form->{partnumber}, save => 1); + + if ($form->{partnumber} && !$trans_number->is_unique) { + $::lxdebug->leave_sub; return 3; } + $form->{partnumber} = $trans_number->create_unique; + ($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|); - do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber, unit) VALUES (?, '', '')|, $form->{id}); + do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber, unit) VALUES (?, ?, '')|, $form->{id}, $form->{partnumber}); $form->{orphaned} = 1; - if ($form->{partnumber} eq "" && $form->{"item"} eq "service") { - $form->{partnumber} = $form->update_defaults($myconfig, "servicenumber"); - } - if ($form->{partnumber} eq "" && $form->{"item"} ne "service") { - $form->{partnumber} = $form->update_defaults($myconfig, "articlenumber"); - } - } my $partsgroup_id = 0; diff --git a/SL/TransNumber.pm b/SL/TransNumber.pm index c9d7be6d1..47cdcd096 100644 --- a/SL/TransNumber.pm +++ b/SL/TransNumber.pm @@ -13,7 +13,7 @@ use Rose::Object::MakeMethods::Generic scalar => [ qw(type id number save dbh dbh_provided business_id) ], ); -my @SUPPORTED_TYPES = qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation); +my @SUPPORTED_TYPES = qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly); sub new { my $class = shift; @@ -58,12 +58,18 @@ sub _get_filters { $filters{where} = 'NOT COALESCE(quotation, FALSE)'; $filters{where} .= $type =~ /^sales/ ? ' AND (customer_id IS NOT NULL)' : ' AND (vendor_id IS NOT NULL)'; - } else { + } elsif ($type =~ /_quotation$/) { $filters{trans_number} = "quonumber"; $filters{numberfield} = $type eq 'sales_quotation' ? "sqnumber" : "rfqnumber"; $filters{table} = "oe"; $filters{where} = 'COALESCE(quotation, FALSE)'; $filters{where} .= $type =~ /^sales/ ? ' AND (customer_id IS NOT NULL)' : ' AND (vendor_id IS NOT NULL)'; + + } elsif ($type =~ /part|service|assembly/) { + $filters{trans_number} = "partnumber"; + $filters{numberfield} = $type eq 'service' ? 'servicenumber' : 'articlenumber'; + $filters{table} = "parts"; + $filters{where} = 'COALESCE(inventory_accno_id, 0) ' . ($type eq 'service' ? '=' : '<>') . ' 0'; } return %filters; @@ -86,7 +92,7 @@ sub is_unique { push @values, conv_i($self->id); } - my $where_str = @where ? join(' AND ', map { "($_)" } @where) : ''; + my $where_str = @where ? ' AND ' . join(' AND ', map { "($_)" } @where) : ''; my $query = <