Add unique key on table of inventory details

This commit is contained in:
Laurent Destailleur 2020-08-31 20:02:06 +02:00
parent 4110f1df05
commit 887d4e0603
4 changed files with 25 additions and 13 deletions

View File

@ -301,4 +301,8 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
ALTER TABLE llx_actioncomm_reminder ADD COLUMN entity integer NOT NULL DEFAULT 1;
ALTER TABLE llx_actioncomm_reminder ADD COLUMN fk_actioncomm integer NOT NULL;
ALTER TABLE llx_actioncomm_reminder ADD COLUMN fk_email_template integer;
ALTER TABLE llx_actioncomm_reminder DROP INDEX uk_actioncomm_reminder_unique, ADD UNIQUE uk_actioncomm_reminder_unique (fk_user, typeremind, offsetvalue, offsetunit, fk_actioncomm);
ALTER TABLE llx_actioncomm_reminder DROP INDEX uk_actioncomm_reminder_unique, ADD UNIQUE uk_actioncomm_reminder_unique (fk_user, typeremind, offsetvalue, offsetunit, fk_actioncomm);
ALTER TABLE llx_inventorydet ADD UNIQUE uk_inventorydet(fk_inventory, fk_warehouse, fk_product, batch);

View File

@ -20,3 +20,6 @@
ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_tms (tms);
ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_datec (datec);
ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_fk_inventory (fk_inventory);
ALTER TABLE llx_inventorydet ADD UNIQUE uk_inventorydet(fk_inventory, fk_warehouse, fk_product, batch);

View File

@ -19,15 +19,15 @@
CREATE TABLE llx_inventorydet
(
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
datec datetime DEFAULT NULL,
tms timestamp,
fk_inventory integer DEFAULT 0,
fk_warehouse integer DEFAULT 0,
fk_product integer DEFAULT 0,
batch varchar(128) DEFAULT NULL, -- Lot or serial number
qty_stock double DEFAULT NULL, -- The targeted value. can be filled during draft edition
qty_view double DEFAULT NULL, -- must be filled once regulation is done
qty_regulated double DEFAULT NULL -- must be filled once regulation is done
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
datec datetime DEFAULT NULL,
tms timestamp,
fk_inventory integer DEFAULT 0,
fk_warehouse integer DEFAULT 0,
fk_product integer DEFAULT 0,
batch varchar(128) DEFAULT NULL, -- Lot or serial number
qty_stock double DEFAULT NULL, -- The targeted value. can be filled during draft edition
qty_view double DEFAULT NULL, -- must be filled once regulation is done
qty_regulated double DEFAULT NULL -- must be filled once regulation is done
)
ENGINE=innodb;

View File

@ -132,7 +132,8 @@ if (empty($reshook))
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
}
if (! $error) {
if (! $error && ! empty($conf->productbatch->enabled)) {
$tmpproduct = new Product($db);
$result = $tmpproduct->fetch($fk_product);
@ -157,7 +158,11 @@ if (empty($reshook))
$result = $tmp->create($user);
if ($result < 0) {
dol_print_error($db, $tmp->error, $tmp->errors);
if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
setEventMessages($langs->trans("DuplicateRecord"), null, 'errors');
} else {
dol_print_error($db, $tmp->error, $tmp->errors);
}
}
}
}