diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index bf9432a6e81..f370863004a 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -408,13 +408,16 @@ DELETE FROM llx_rights_def where module = 'holiday' and perms = 'lire_tous'; CREATE TABLE llx_c_product_nature ( rowid integer AUTO_INCREMENT PRIMARY KEY, - code integer NOT NULL, + code tinyint NOT NULL, label varchar(100), active tinyint DEFAULT 1 NOT NULL ) ENGINE=innodb; ALTER TABLE llx_c_product_nature ADD UNIQUE INDEX uk_c_product_nature(code); -INSERT INTO llx_c_product_nature (code, label, active) VALUES (-1, '', 1); INSERT INTO llx_c_product_nature (code, label, active) VALUES (0, 'RowMaterial', 1); INSERT INTO llx_c_product_nature (code, label, active) VALUES (1, 'Finished', 1); + +ALTER TABLE llx_product MODIFY COLUMN finished tinyint DEFAULT NULL; +ALTER TABLE llx_product ADD CONSTRAINT fk_product_finished FOREIGN KEY (finished) REFERENCES llx_c_product_nature (code); + diff --git a/htdocs/install/mysql/tables/llx_c_product_nature.sql b/htdocs/install/mysql/tables/llx_c_product_nature.sql index b2f9892aa1e..3c467ce7cf8 100644 --- a/htdocs/install/mysql/tables/llx_c_product_nature.sql +++ b/htdocs/install/mysql/tables/llx_c_product_nature.sql @@ -18,7 +18,7 @@ CREATE TABLE llx_c_product_nature ( rowid integer AUTO_INCREMENT PRIMARY KEY, - code varchar(3) NOT NULL, + code tinyint NOT NULL, label varchar(100), active tinyint DEFAULT 1 NOT NULL ) ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_product.key.sql b/htdocs/install/mysql/tables/llx_product.key.sql index c3dd33c88c5..c0526a8f2cc 100644 --- a/htdocs/install/mysql/tables/llx_product.key.sql +++ b/htdocs/install/mysql/tables/llx_product.key.sql @@ -33,6 +33,7 @@ ALTER TABLE llx_product ADD INDEX idx_product_fk_barcode_type (fk_barcode_type); ALTER TABLE llx_product ADD INDEX idx_product_fk_project (fk_project); ALTER TABLE llx_product ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode_type, entity); ALTER TABLE llx_product ADD CONSTRAINT fk_product_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); +ALTER TABLE llx_product ADD CONSTRAINT fk_product_finished FOREIGN KEY (finished) REFERENCES llx_c_product_nature (code); ALTER TABLE llx_product ADD CONSTRAINT fk_product_fk_country FOREIGN KEY (fk_country) REFERENCES llx_c_country (rowid); ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type (rowid); diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index bc583a76ce2..2431c884c62 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -92,7 +92,7 @@ create table llx_product lifo double(24,8), -- To store valuation of stock calculated using lifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table. fk_default_warehouse integer DEFAULT NULL, canvas varchar(32) DEFAULT NULL, - finished tinyint DEFAULT NULL, -- 1=manufactured product, 0=matiere premiere + finished tinyint DEFAULT NULL, -- see dictionnary c_product_nature hidden tinyint DEFAULT 0, -- Not used. Deprecated. import_key varchar(14), -- Import key model_pdf varchar(255), -- model save dodument used diff --git a/htdocs/product/card.php b/htdocs/product/card.php index e3467e871c8..62813ee2a57 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -321,8 +321,19 @@ if (empty($reshook)) $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit $object->volume = GETPOST('volume'); $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit - $object->finished = GETPOST('finished', 'alpha'); - $object->fk_unit = GETPOST('units', 'alpha'); // This is the fk_unit of sale + $finished = GETPOST('finished', 'int'); + if ($finished > 0) { + $object->finished = $finished; + } else { + $object->finished = null; + } + + $units = GETPOST('units', 'int'); + if ($units > 0) { + $object->fk_unit = $units; + } else { + $object->fk_unit = null; + } $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha'); $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha'); @@ -435,10 +446,15 @@ if (empty($reshook)) $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit $object->volume = GETPOST('volume'); $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit - $object->finished = GETPOST('finished', 'alpha'); + + $finished = GETPOST('finished', 'int'); + if ($finished >= 0) { + $object->finished = $finished; + } else { + $object->finished = null; + } $units = GETPOST('units', 'int'); - if ($units > 0) { $object->fk_unit = $units; } else { @@ -1547,8 +1563,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } else { // Nature print '