deliver_order_items_id mit inventory verknüpft
authorJan Büren <jan@kivitendo-premium.de>
Mon, 26 Jan 2015 12:39:41 +0000 (13:39 +0100)
committerJan Büren <jan@kivitendo-premium.de>
Mon, 26 Jan 2015 12:39:41 +0000 (13:39 +0100)
    Falls Lieferscheine Warenbewegungen auslösen, sind jetzt auch die
    einzelnen Position "rückverfolgbar" und nicht nur der Beleg.
    Entsprechende Fremdschlüssel gesetzt

SL/DB/MetaSetup/Inventory.pm
SL/DO.pm
SL/WH.pm
sql/Pg-upgrade2/warehouse_add_delivery_order_items_stock_id.sql [new file with mode: 0644]

index 28ea1d9..fce09e7 100644 (file)
@@ -9,23 +9,23 @@ use base qw(SL::DB::Object);
 __PACKAGE__->meta->table('inventory');
 
 __PACKAGE__->meta->columns(
-  bestbefore    => { type => 'date' },
-  bin_id        => { type => 'integer', not_null => 1 },
-  chargenumber  => { type => 'text', default => '', not_null => 1 },
-  comment       => { type => 'text' },
-  employee_id   => { type => 'integer', not_null => 1 },
-  id            => { type => 'serial', not_null => 1 },
-  itime         => { type => 'timestamp', default => 'now()' },
-  mtime         => { type => 'timestamp' },
-  oe_id         => { type => 'integer' },
-  orderitems_id => { type => 'integer' },
-  parts_id      => { type => 'integer', not_null => 1 },
-  project_id    => { type => 'integer' },
-  qty           => { type => 'numeric', precision => 25, scale => 5 },
-  shippingdate  => { type => 'date' },
-  trans_id      => { type => 'integer', not_null => 1 },
-  trans_type_id => { type => 'integer', not_null => 1 },
-  warehouse_id  => { type => 'integer', not_null => 1 },
+  bestbefore                    => { type => 'date' },
+  bin_id                        => { type => 'integer', not_null => 1 },
+  chargenumber                  => { type => 'text', default => '', not_null => 1 },
+  comment                       => { type => 'text' },
+  delivery_order_items_stock_id => { type => 'integer' },
+  employee_id                   => { type => 'integer', not_null => 1 },
+  id                            => { type => 'serial', not_null => 1 },
+  itime                         => { type => 'timestamp', default => 'now()' },
+  mtime                         => { type => 'timestamp' },
+  oe_id                         => { type => 'integer' },
+  parts_id                      => { type => 'integer', not_null => 1 },
+  project_id                    => { type => 'integer' },
+  qty                           => { type => 'numeric', precision => 25, scale => 5 },
+  shippingdate                  => { type => 'date' },
+  trans_id                      => { type => 'integer', not_null => 1 },
+  trans_type_id                 => { type => 'integer', not_null => 1 },
+  warehouse_id                  => { type => 'integer', not_null => 1 },
 );
 
 __PACKAGE__->meta->primary_key_columns([ 'id' ]);
@@ -38,11 +38,21 @@ __PACKAGE__->meta->foreign_keys(
     key_columns => { bin_id => 'id' },
   },
 
+  delivery_order_items_stock => {
+    class       => 'SL::DB::DeliveryOrderItemsStock',
+    key_columns => { delivery_order_items_stock_id => 'id' },
+  },
+
   employee => {
     class       => 'SL::DB::Employee',
     key_columns => { employee_id => 'id' },
   },
 
+  oe => {
+    class       => 'SL::DB::DeliveryOrder',
+    key_columns => { oe_id => 'id' },
+  },
+
   parts => {
     class       => 'SL::DB::Part',
     key_columns => { parts_id => 'id' },
index 7659ffe..9fdd6b7 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -387,6 +387,8 @@ SQL
                   conv_i($form->{"delivery_order_items_id_$i"}), $sinfo->{qty}, $sinfo->{unit}, conv_i($sinfo->{warehouse_id}),
                   conv_i($sinfo->{bin_id}));
        $h_item_stock_id->finish();
+      # write back the id to the form (important if only transfer was clicked (id fk for invoice)
+      $form->{"stock_${in_out}_$i"} = YAML::Dump($stock_info);
       }
       @values = ($form->{"delivery_order_items_id_$i"}, $sinfo->{qty}, $sinfo->{unit}, conv_i($sinfo->{warehouse_id}),
                  conv_i($sinfo->{bin_id}), $sinfo->{chargenumber}, conv_date($sinfo->{bestbefore}),
@@ -403,7 +405,7 @@ SQL
                                 name_prefix  => 'ic_',
                                 name_postfix => "_$i",
                                 dbh          => $dbh);
-    # link order items with doi
+    # link order items with doi, for future extension look at foreach IS.pm
     if ($form->{"converted_from_orderitems_id_$i"}) {
       RecordLinks->create_links('dbh'        => $dbh,
                                 'mode'       => 'ids',
@@ -1197,17 +1199,18 @@ sub transfer_in_out {
 
   foreach my $request (@{ $params{requests} }) {
     push @transfers, {
-      'parts_id'               => $request->{parts_id},
-      "${prefix}_warehouse_id" => $request->{warehouse_id},
-      "${prefix}_bin_id"       => $request->{bin_id},
-      'chargenumber'           => $request->{chargenumber},
-      'bestbefore'             => $request->{bestbefore},
-      'qty'                    => $request->{qty},
-      'unit'                   => $request->{unit},
-      'oe_id'                  => $form->{id},
-      'shippingdate'           => 'current_date',
-      'transfer_type'          => $params{direction} eq 'in' ? 'stock' : 'shipped',
-      'project_id'             => $request->{project_id},
+      'parts_id'                      => $request->{parts_id},
+      "${prefix}_warehouse_id"        => $request->{warehouse_id},
+      "${prefix}_bin_id"              => $request->{bin_id},
+      'chargenumber'                  => $request->{chargenumber},
+      'bestbefore'                    => $request->{bestbefore},
+      'qty'                           => $request->{qty},
+      'unit'                          => $request->{unit},
+      'oe_id'                         => $form->{id},
+      'shippingdate'                  => 'current_date',
+      'transfer_type'                 => $params{direction} eq 'in' ? 'stock' : 'shipped',
+      'project_id'                    => $request->{project_id},
+      'delivery_order_items_stock_id' => $request->{delivery_order_items_stock_id},
     };
   }
 
index 4e0c3fc..e836d65 100644 (file)
--- a/SL/WH.pm
+++ b/SL/WH.pm
@@ -110,7 +110,7 @@ sub transfer {
           trans_id         => $trans_id,
           shippingdate     => !$transfer->{shippingdate} || $transfer->{shippingdate} eq 'current_date'
                               ? $now : $transfer->{shippingdate},
-          map { $_ => $transfer->{$_} } qw( chargenumber bestbefore oe_id orderitems_id comment),
+          map { $_ => $transfer->{$_} } qw( chargenumber bestbefore oe_id delivery_order_items_stock_id comment),
       );
 
       if ($unit) {
diff --git a/sql/Pg-upgrade2/warehouse_add_delivery_order_items_stock_id.sql b/sql/Pg-upgrade2/warehouse_add_delivery_order_items_stock_id.sql
new file mode 100644 (file)
index 0000000..77d9001
--- /dev/null
@@ -0,0 +1,6 @@
+-- @tag: warehouse_add_delivery_order_items_stock_id
+-- @description: Constraints für inventory auf delivery_order (dois und do). Ferner sinnvolle Umbenennung zumindestens von einer Spalte (orderitems -> dois)
+-- @depends: release_3_1_0
+ALTER TABLE inventory RENAME orderitems_id TO delivery_order_items_stock_id;
+ALTER TABLE inventory ADD CONSTRAINT delivery_order_items_stock_id_fkey FOREIGN KEY (delivery_order_items_stock_id) REFERENCES delivery_order_items_stock (id);
+ALTER TABLE inventory ADD CONSTRAINT oe_id_fkey FOREIGN KEY (oe_id) REFERENCES delivery_orders (id);