Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision df0d4d3f

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID df0d4d3fb8a275b7f96a260d403966c873123666
  • Vorgänger 33b0b2ca
  • Nachfolger e08c98d4

Verhindern, dass Artikelnummern mehrfach vergeben werden

Fix für Bug 1667.

Unterschiede anzeigen:

SL/IC.pm
40 40

  
41 41
use SL::CVar;
42 42
use SL::DBUtils;
43
use SL::TransNumber;
43 44

  
44 45
use strict;
45 46

  
......
311 312
  my $priceupdate = ', priceupdate = current_date';
312 313

  
313 314
  if ($form->{id}) {
315
    my $trans_number = SL::TransNumber->new(type => $form->{item}, dbh => $dbh, number => $form->{partnumber}, id => $form->{id});
316
    if (!$trans_number->is_unique) {
317
      $::lxdebug->leave_sub;
318
      return 3;
319
    }
314 320

  
315 321
    # get old price
316 322
    $query = qq|SELECT sellprice, weight FROM parts WHERE id = ?|;
......
346 352
    $priceupdate        = '' if (all { $previous_values->{$_} == $form->{$_} } qw(sellprice lastcost listprice));
347 353

  
348 354
  } else {
349
    my ($count) = selectrow_query($form, $dbh, qq|SELECT COUNT(*) FROM parts WHERE partnumber = ?|, $form->{partnumber});
350
    if ($count) {
351
      $main::lxdebug->leave_sub();
355
    my $trans_number = SL::TransNumber->new(type => $form->{item}, dbh => $dbh, number => $form->{partnumber}, save => 1);
356

  
357
    if ($form->{partnumber} && !$trans_number->is_unique) {
358
      $::lxdebug->leave_sub;
352 359
      return 3;
353 360
    }
354 361

  
362
    $form->{partnumber} = $trans_number->create_unique;
363

  
355 364
    ($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|);
356
    do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber, unit) VALUES (?, '', '')|, $form->{id});
365
    do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber, unit) VALUES (?, ?, '')|, $form->{id}, $form->{partnumber});
357 366

  
358 367
    $form->{orphaned} = 1;
359
    if ($form->{partnumber} eq "" && $form->{"item"} eq "service") {
360
      $form->{partnumber} = $form->update_defaults($myconfig, "servicenumber");
361
    }
362
    if ($form->{partnumber} eq "" && $form->{"item"} ne "service") {
363
      $form->{partnumber} = $form->update_defaults($myconfig, "articlenumber");
364
    }
365

  
366 368
  }
367 369
  my $partsgroup_id = 0;
368 370

  
SL/TransNumber.pm
13 13
 scalar => [ qw(type id number save dbh dbh_provided business_id) ],
14 14
);
15 15

  
16
my @SUPPORTED_TYPES = qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation);
16
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);
17 17

  
18 18
sub new {
19 19
  my $class = shift;
......
58 58
    $filters{where}         = 'NOT COALESCE(quotation, FALSE)';
59 59
    $filters{where}        .= $type =~ /^sales/ ? ' AND (customer_id IS NOT NULL)' : ' AND (vendor_id IS NOT NULL)';
60 60

  
61
  } else {
61
  } elsif ($type =~ /_quotation$/) {
62 62
    $filters{trans_number}  = "quonumber";
63 63
    $filters{numberfield}   = $type eq 'sales_quotation' ? "sqnumber" : "rfqnumber";
64 64
    $filters{table}         = "oe";
65 65
    $filters{where}         = 'COALESCE(quotation, FALSE)';
66 66
    $filters{where}        .= $type =~ /^sales/ ? ' AND (customer_id IS NOT NULL)' : ' AND (vendor_id IS NOT NULL)';
67

  
68
  } elsif ($type =~ /part|service|assembly/) {
69
    $filters{trans_number}  = "partnumber";
70
    $filters{numberfield}   = $type eq 'service' ? 'servicenumber' : 'articlenumber';
71
    $filters{table}         = "parts";
72
    $filters{where}         = 'COALESCE(inventory_accno_id, 0) ' . ($type eq 'service' ? '=' : '<>') . ' 0';
67 73
  }
68 74

  
69 75
  return %filters;
......
86 92
    push @values, conv_i($self->id);
87 93
  }
88 94

  
89
  my $where_str = @where ? join(' AND ', map { "($_)" } @where) : '';
95
  my $where_str = @where ? ' AND ' . join(' AND ', map { "($_)" } @where) : '';
90 96
  my $query     = <<SQL;
91 97
    SELECT $filters{trans_number}
92 98
    FROM $filters{table}

Auch abrufbar als: Unified diff