From: G. Richardson Date: Thu, 28 Jul 2016 16:14:15 +0000 (+0200) Subject: Ware/Erzeugnis/Dienstleistung per parts.part_type unterscheiden X-Git-Tag: release-3.5.4~1914 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=71041661bf4a8e0ad75a20d9252dc501b3611657;p=kivitendo-erp.git Ware/Erzeugnis/Dienstleistung per parts.part_type unterscheiden Neuen ENUM-Typ eingeführt, der auf die Werte "part", "service" und "assembly" beschränkt ist. Da man enums nicht innerhalb von Transaktionen hinzufügen kann, was der Default für den kivitendo Upgrade Mechanismus ist, wird hier auch schon das Sortiment vorbereitet. Siehe auch doc/UPGRADE --- diff --git a/SL/DB/MetaSetup/Part.pm b/SL/DB/MetaSetup/Part.pm index f3c33a606..7e9eedcfa 100644 --- a/SL/DB/MetaSetup/Part.pm +++ b/SL/DB/MetaSetup/Part.pm @@ -9,7 +9,6 @@ use parent qw(SL::DB::Object); __PACKAGE__->meta->table('parts'); __PACKAGE__->meta->columns( - assembly => { type => 'boolean', default => 'false' }, bin_id => { type => 'integer' }, bom => { type => 'boolean', default => 'false' }, buchungsgruppen_id => { type => 'integer' }, @@ -34,6 +33,7 @@ __PACKAGE__->meta->columns( notes => { type => 'text' }, obsolete => { type => 'boolean', default => 'false' }, onhand => { type => 'numeric', default => '0', precision => 25, scale => 5 }, + part_type => { type => 'enum', check_in => [ 'part', 'service', 'assembly', 'assortment' ], db_type => 'part_type_enum', not_null => 1 }, partnumber => { type => 'text', not_null => 1 }, partsgroup_id => { type => 'integer' }, payment_id => { type => 'integer' }, diff --git a/doc/UPGRADE b/doc/UPGRADE index 3cb8989b4..2b7b3b7d7 100644 --- a/doc/UPGRADE +++ b/doc/UPGRADE @@ -23,6 +23,10 @@ Upgrade auf v3.4.x Unstable (letter.tex) angepasst worden. Statt letter.customer muss der Adressat jetzt aus letter.custoemr_vendor erzeugt werden. +* In der Tabelle parts wurde die Boolean-Spalte "assembly" entfernt. Zur + Erkennung von Waren/Dienstleistungen/Erzeugnissen gibt es nun in parts eine + neue Spalte part_type vom ENUM-Typ, der auf die Werte 'part', 'service', + 'assembly' und 'assortment' beschränkt ist. Upgrade auf v3.4.1 ================== diff --git a/sql/Pg-upgrade2/part_type_enum.sql b/sql/Pg-upgrade2/part_type_enum.sql new file mode 100644 index 000000000..e92300f8c --- /dev/null +++ b/sql/Pg-upgrade2/part_type_enum.sql @@ -0,0 +1,32 @@ +-- @tag: part_type_enum +-- @description: enums +-- @depends: release_3_4_1 + +CREATE TYPE part_type_enum AS ENUM ('part', 'service', 'assembly', 'assortment'); +ALTER TABLE parts ADD COLUMN part_type part_type_enum; + +UPDATE parts SET part_type = 'assembly' WHERE assembly IS TRUE; +UPDATE parts SET part_type = 'service' WHERE inventory_accno_id IS NULL and part_type IS NULL; +UPDATE parts SET part_type = 'part' WHERE assembly IS FALSE AND inventory_accno_id IS NOT NULL AND part_type IS NULL; + +-- don't set a default for now to help with finding bugs where no part_type is passed +ALTER TABLE parts ALTER COLUMN part_type SET NOT NULL; + +CREATE OR REPLACE FUNCTION update_purchase_price() RETURNS trigger AS ' +BEGIN + if tg_op = ''DELETE'' THEN + UPDATE parts SET lastcost = COALESCE((select sum ((a.qty * (p.lastcost / COALESCE(pf.factor, + 1)))) as summe from assembly a left join parts p on (p.id = a.parts_id) + LEFT JOIN price_factors pf on (p.price_factor_id = pf.id) where a.id = parts.id),0) + WHERE part_type = ''assembly'' and id = old.id; + return old; -- old ist eine referenz auf die geloeschte reihe + ELSE + UPDATE parts SET lastcost = COALESCE((select sum ((a.qty * (p.lastcost / COALESCE(pf.factor, + 1)))) as summe from assembly a left join parts p on (p.id = a.parts_id) + LEFT JOIN price_factors pf on (p.price_factor_id = pf.id) + WHERE a.id = parts.id),0) where part_type = ''assembly'' and id = new.id; + return new; -- entsprechend new, wird wahrscheinlich benoetigt, um den korrekten Eintrag + -- zu filtern bzw. dann zu aktualisieren + END IF; +END; +' LANGUAGE plpgsql;