diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 10d25b2aa09..4857902b8cc 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -140,6 +140,7 @@ if ($action == 'add' && !empty($permissiontoadd)) { header("Location: ".$urltogo); exit; } else { + $error++; // Creation KO if (!empty($object->errors)) { setEventMessages(null, $object->errors, 'errors'); @@ -255,6 +256,7 @@ if ($action == 'update' && !empty($permissiontoadd)) { if ($result > 0) { $action = 'view'; } else { + $error++; // Creation KO setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; @@ -284,6 +286,7 @@ if ($action == "update_extras" && !empty($permissiontoadd)) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); $action = 'view'; } else { + $error++; setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit_extras'; } @@ -301,9 +304,11 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete)) { if ($result > 0) { // Delete OK setEventMessages("RecordDeleted", null, 'mesgs'); + header("Location: ".$backurlforlist); exit; } else { + $error++; if (!empty($object->errors)) { setEventMessages(null, $object->errors, 'errors'); } else { @@ -347,6 +352,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { + $error++; setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; @@ -383,6 +389,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) { } } } else { + $error++; setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; @@ -414,6 +421,7 @@ if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) { } } } else { + $error++; setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; @@ -425,6 +433,7 @@ if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) { if ($result >= 0) { // Nothing else done } else { + $error++; setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; @@ -456,6 +465,7 @@ if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) { } } } else { + $error++; setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; @@ -481,6 +491,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object exit; } else { + $error++; setEventMessages($objectutil->error, $objectutil->errors, 'errors'); $action = ''; } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 812353591ed..aed5bc9515f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8730,7 +8730,11 @@ abstract class CommonObject $res = $this->db->query($sql); if ($res === false) { $error++; - $this->errors[] = $this->db->lasterror(); + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $this->errors[] = "ErrorRefAlreadyExists"; + } else { + $this->errors[] = $this->db->lasterror(); + } } } diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 19875f55148..2fa24d467ca 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -264,3 +264,5 @@ ProductBatchDoesNotExist=Product with batch/serial does not exist ProductBarcodeDoesNotExist=Product with barcode does not exist WarehouseId=Warehouse ID WarehouseRef=Warehouse Ref +SaveQtyFirst=Save the real inventoried quantities first, before asking creation of the stock movement. +InventoryStartedShort=Started \ No newline at end of file diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index 91edba380cd..1f036e1fa3c 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -109,6 +109,7 @@ if ($reshook < 0) { } if (empty($reshook)) { + $savaction = $action; $error = 0; $backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php'; @@ -152,6 +153,12 @@ if (empty($reshook)) { $autocopy = 'MAIN_MAIL_AUTOCOPY_INVENTORY_TO'; $trackid = 'stockinv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + + if (!$error && $savaction == 'confirm_validate' && $action == '' && $object->id > 0) { + // Switch to the tab inventory + header("Location: ".DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id); + exit; + } } diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 57abc333a58..3e83d62ecf2 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -59,10 +59,10 @@ class Inventory extends CommonObject */ public $picto = 'inventory'; - const STATUS_DRAFT = 0; - const STATUS_VALIDATED = 1; - const STATUS_RECORDED = 2; - const STATUS_CANCELED = 9; + const STATUS_DRAFT = 0; // Draft + const STATUS_VALIDATED = 1; // Inventory is in process + const STATUS_RECORDED = 2; // Inventory is finisged. Stock movement has been recorded. + const STATUS_CANCELED = 9; // Canceled /** * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') @@ -368,7 +368,7 @@ class Inventory extends CommonObject } /** - * Set to Recorded + * Set to inventory to status "Closed". It means all stock movements were recorded. * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers @@ -616,11 +616,11 @@ class Inventory extends CommonObject $labelStatus = array(); $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft'); - $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('Started').')'; + $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')'; $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled'); $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed'); $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft'); - $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Started'); + $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort'); $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled'); $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed'); diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 9a4d61209ba..ce657f1c9d6 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -310,20 +310,22 @@ $help_url = ''; llxHeader('', $langs->trans('Inventory'), $help_url); -// Disable button Generate movement if data were not saved +// Disable button Generate movement if data were modified and not saved print ''; @@ -639,12 +640,14 @@ if ($object->id > 0) { //Call method to undo changes in real qty print ''; @@ -667,7 +670,7 @@ if ($object->id > 0) { print ''; } print '