__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' },
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' },
(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
==================
--- /dev/null
+-- @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;