do: neue Nummerkreise für supplier und rma Lieferscheine
authorSven Schöling <s.schoeling@googlemail.com>
Fri, 1 Oct 2021 17:45:08 +0000 (19:45 +0200)
committerJan Büren <jan@kivitendo.de>
Mon, 14 Feb 2022 13:58:19 +0000 (14:58 +0100)
SL/DB/DeliveryOrder/TypeData.pm
SL/DB/Helper/TransNumberGenerator.pm
SL/DB/Manager/DeliveryOrder.pm
SL/DB/MetaSetup/Default.pm
SL/TransNumber.pm
sql/Pg-upgrade2/deliveryorder_transnumbers.sql [new file with mode: 0644]

index 079e494..5f35973 100644 (file)
@@ -43,6 +43,7 @@ my %type_data = (
       is_customer    => 1,
       nr_key         => "donumber",
       transfer       => 'out',
+      transnumber    => 'sdonumber',
     },
     part_classification_query => [ "used_for_sale" => 1 ],
     right => "sales_delivery_order_edit",
@@ -70,6 +71,7 @@ my %type_data = (
       is_customer    => 0,
       nr_key         => "donumber",
       transfer       => 'in',
+      transnumber    => 'pdonumber',
     },
     part_classification_query => [ "used_for_purchase" => 1 ],
     right => "purchase_delivery_order_edit",
@@ -97,6 +99,7 @@ my %type_data = (
       is_customer    => 0,
       nr_key         => "donumber",
       transfer       => 'out',
+      transnumber    => 'sudonumber',
     },
     part_classification_query => [ "used_for_purchase" => 1 ],
     right => "purchase_delivery_order_edit",
@@ -124,6 +127,7 @@ my %type_data = (
       is_customer    => 0,
       nr_key         => "donumber",
       transfer       => 'in',
+      transnumber    => 'rdonumber',
     },
     part_classification_query => [ "used_for_sale" => 1 ],
     right => "sales_delivery_order_edit",
index 5b45853..eb89ea8 100644 (file)
@@ -30,6 +30,8 @@ my %specs = ( ar                      => { number_column => 'invnumber',
               purchase_order          => { number_column => 'ordnumber',      number_range_column => 'ponumber',       scoping => \&oe_scoping,    },
               sales_delivery_order    => { number_column => 'donumber',       number_range_column => 'sdonumber',      scoping => \&do_scoping,    },
               purchase_delivery_order => { number_column => 'donumber',       number_range_column => 'pdonumber',      scoping => \&do_scoping,    },
+              supplier_delivery_order => { number_column => 'donumber',       number_range_column => 'sudonumber',     scoping => \&do_scoping,    },
+              rma_delivery_order      => { number_column => 'donumber',       number_range_column => 'rdonumber',      scoping => \&do_scoping,    },
               customer                => { number_column => 'customernumber', number_range_column => 'customernumber',                             },
               vendor                  => { number_column => 'vendornumber',   number_range_column => 'vendornumber',                               },
               part                    => { number_column => 'partnumber',     number_range_column => 'articlenumber',  scoping => \&parts_scoping, },
index 156ca7b..9f45ca0 100644 (file)
@@ -8,6 +8,8 @@ use SL::DB::Helper::Paginated;
 use SL::DB::Helper::Sorted;
 use SL::DB::Helper::Filtered;
 
+use SL::DB::DeliveryOrder::TypeData qw(validate_type);
+
 sub object_class { 'SL::DB::DeliveryOrder' }
 
 __PACKAGE__->make_manager_methods;
@@ -27,10 +29,7 @@ sub type_filter {
   my $class = shift;
   my $type  = lc(shift || '');
 
-  return ('!customer_id' => undef) if $type eq 'sales_delivery_order';
-  return ('!vendor_id'   => undef) if $type eq 'purchase_delivery_order';
-
-  die "Unknown type $type";
+  return type => validate_type($type);
 }
 
 sub _sort_spec {
index b7fe2b1..ba8cf32 100644 (file)
@@ -148,6 +148,7 @@ __PACKAGE__->meta->columns(
   purchase_delivery_order_show_delete       => { type => 'boolean', default => 'true' },
   purchase_order_show_delete                => { type => 'boolean', default => 'true' },
   quick_search_modules                      => { type => 'array' },
+  rdonumber                                 => { type => 'text' },
   reqdate_interval                          => { type => 'integer', default => '0' },
   reqdate_on                                => { type => 'boolean', default => 'true' },
   require_transaction_description_ps        => { type => 'boolean', default => 'false', not_null => 1 },
@@ -182,6 +183,7 @@ __PACKAGE__->meta->columns(
   stocktaking_cutoff_date                   => { type => 'date' },
   stocktaking_qty_threshold                 => { type => 'numeric', default => '0', precision => 25, scale => 5 },
   stocktaking_warehouse_id                  => { type => 'integer' },
+  sudonumber                                => { type => 'text' },
   taxnumber                                 => { type => 'text' },
   templates                                 => { type => 'text' },
   transfer_default                          => { type => 'boolean', default => 'true' },
index 25646da..8e87d3b 100644 (file)
@@ -9,13 +9,16 @@ use List::MoreUtils qw(any none);
 use SL::DBUtils;
 use SL::PrefixedNumber;
 use SL::DB;
+use SL::DB::DeliveryOrder::TypeData;
 
 use Rose::Object::MakeMethods::Generic
 (
  scalar => [ qw(type id number save dbh dbh_provided business_id) ],
 );
 
-my @SUPPORTED_TYPES = qw(invoice invoice_for_advance_payment final_invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly assortment letter);
+my @SUPPORTED_TYPES = qw(invoice invoice_for_advance_payment final_invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly assortment letter),
+  @{ SL::DB::DeliveryOrder::TypeData::valid_types() },
+);
 
 sub new {
   my $class = shift;
@@ -47,11 +50,12 @@ sub _get_filters {
     $filters{numberfield}   = "${type}number";
     $filters{table}         = $type;
 
-  } elsif ($type =~ /_delivery_order$/) {
-    $filters{trans_number}  = "donumber";
-    $filters{numberfield}   = $type eq 'sales_delivery_order' ? "sdonumber" : "pdonumber";
+  } elsif ($type =~ /_delivery_order$/ && SL::DB::DeliveryOrder::TypeData::is_valid_type($type)) {
+    $filters{trans_number}  = SL::DB::DeliveryOrder::TypeData::get3($type, 'properties', 'nr_key'),
+    $filters{numberfield}   = SL::DB::DeliveryOrder::TypeData::get3($type, 'properties', 'transnumber'),
     $filters{table}         = "delivery_orders";
-    $filters{where}         = $type =~ /^sales/ ? '(customer_id IS NOT NULL)' : '(vendor_id IS NOT NULL)';
+    $filters{where}         = "order_type = ?";
+    $filters{values}        = [ $::form->{type} ];
 
   } elsif ($type =~ /_order$/) {
     $filters{trans_number}  = "ordnumber";
@@ -96,6 +100,7 @@ sub is_unique {
   my @values = ($self->number);
 
   push @where, $filters{where} if $filters{where};
+  push @values, @{ $filters{values} } if $filters{values};
 
   if ($self->id) {
     push @where,  qq|id <> ?|;
@@ -131,7 +136,7 @@ sub create_unique {
 SQL
 
     do_query($form, $self->dbh, "LOCK TABLE " . $filters{table}) || die $self->dbh->errstr;
-    my %numbers_in_use = selectall_as_map($form, $self->dbh, $query, $filters{trans_number}, 'in_use');
+    my %numbers_in_use = selectall_as_map($form, $self->dbh, $query, $filters{trans_number}, 'in_use', @{ $filters{values} // [] });
 
     my $business_number;
     ($business_number) = selectfirst_array_query($form, $self->dbh, qq|SELECT customernumberinit FROM business WHERE id = ? FOR UPDATE|, $self->business_id) if $self->business_id;
diff --git a/sql/Pg-upgrade2/deliveryorder_transnumbers.sql b/sql/Pg-upgrade2/deliveryorder_transnumbers.sql
new file mode 100644 (file)
index 0000000..3e03150
--- /dev/null
@@ -0,0 +1,11 @@
+-- @tag: deliveryorder_transnumbers
+-- @description: Nummernkreise für neue lieferscheintypen
+-- @depends: release_3_5_8
+
+ALTER TABLE defaults ADD COLUMN sudonumber TEXT;
+ALTER TABLE defaults ADD COLUMN rdonumber TEXT;
+
+UPDATE defaults SET
+  sudonumber = '0',
+  rdonumber = '0';
+