diff --git a/htdocs/install/mysql/migration/21.0.0-22.0.0.sql b/htdocs/install/mysql/migration/21.0.0-22.0.0.sql index ff2c13dd2db..fdbd7c4e73e 100644 --- a/htdocs/install/mysql/migration/21.0.0-22.0.0.sql +++ b/htdocs/install/mysql/migration/21.0.0-22.0.0.sql @@ -208,10 +208,9 @@ DELETE FROM llx_const WHERE name = 'STOCK_ALLOW_NEGATIVE_TRANSFER' AND value = 1 ALTER TABLE llx_links ADD COLUMN share varchar(128) NULL AFTER objectid; ALTER TABLE llx_links ADD COLUMN share_pass varchar(32) NULL AFTER share; --- Dispatcher for virtual products -ALTER TABLE llx_expeditiondet ADD COLUMN fk_parent integer NULL AFTER fk_product; +ALTER TABLE llx_expeditiondet ADD COLUMN fk_parent integer NULL AFTER fk_product; -- for sublines ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_parent (fk_parent); -ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); -ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_parent FOREIGN KEY (fk_parent) REFERENCES llx_expeditiondet (rowid); +--ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); +--ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_parent FOREIGN KEY (fk_parent) REFERENCES llx_expeditiondet (rowid); -UPDATE llx_expeditiondet as ed LEFT JOIN llx_commandedet ON ed.fk_elementdet = llx_commandedet.rowid SET ed.fk_product = llx_commandedet.fk_product WHERE ed.fk_product IS NULL AND ed.element_type = 'commande'; +UPDATE llx_expeditiondet as ed SET ed.fk_product = (SELECT cd.fk_product FROM llx_commandedet as cd WHERE cd.rowid = ed.fk_elementdet AND ed.element_type = 'commande') AND ed.fk_product IS NULL; diff --git a/htdocs/install/mysql/tables/llx_expeditiondet.key.sql b/htdocs/install/mysql/tables/llx_expeditiondet.key.sql index 20656ea6a7e..0b887794270 100644 --- a/htdocs/install/mysql/tables/llx_expeditiondet.key.sql +++ b/htdocs/install/mysql/tables/llx_expeditiondet.key.sql @@ -22,6 +22,7 @@ ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_expedition (fk_expe ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_elementdet (fk_elementdet); ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_product (fk_product); ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_parent (fk_parent); + ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_expedition FOREIGN KEY (fk_expedition) REFERENCES llx_expedition (rowid); -ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); -ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_parent FOREIGN KEY (fk_parent) REFERENCES llx_expeditiondet (rowid); +--ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); +--ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_parent FOREIGN KEY (fk_parent) REFERENCES llx_expeditiondet (rowid); diff --git a/htdocs/install/mysql/tables/llx_expeditiondet.sql b/htdocs/install/mysql/tables/llx_expeditiondet.sql index e9d0a0ecc22..080d93c9195 100644 --- a/htdocs/install/mysql/tables/llx_expeditiondet.sql +++ b/htdocs/install/mysql/tables/llx_expeditiondet.sql @@ -26,7 +26,7 @@ create table llx_expeditiondet fk_element integer, -- ID of main source object fk_elementdet integer, -- ID of line of source object (proposal, sale order) element_type varchar(50) DEFAULT 'commande' NOT NULL, -- Type of source object ('commande', ...) - fk_product integer, -- ID of product. If empy, you can retreive it using fk_element/element_type link + fk_product integer, -- ID of product. If empy, you can retreive it using fk_element/element_type link. fk_parent integer, -- ID of parent line qty real, -- Quantity fk_unit integer, -- ID of unit code