NEW Can go back to draft on shipment when stock change not on validate

This commit is contained in:
Laurent Destailleur 2023-04-10 15:55:58 +02:00
parent 8ba802ed5d
commit 90bca8b4d7
4 changed files with 59 additions and 27 deletions

View File

@ -9982,7 +9982,7 @@ abstract class CommonObject
$this->db->begin(); $this->db->begin();
$statusfield = 'status'; $statusfield = 'status';
if ($this->element == 'don' || $this->element == 'donation') { if (in_array($this->element, array('don', 'donation', 'shipping'))) {
$statusfield = 'fk_statut'; $statusfield = 'fk_statut';
} }

View File

@ -157,6 +157,14 @@ if (empty($reshook)) {
$upload_dir = $conf->expedition->dir_output.'/sending'; $upload_dir = $conf->expedition->dir_output.'/sending';
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
// Back to draft
if ($action == 'setdraft' && $user->rights->expedition->creer) {
$object->fetch($id);
$result = $object->setDraft($user, 0);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
// Reopen // Reopen
if ($action == 'reopen' && $user->rights->expedition->creer) { if ($action == 'reopen' && $user->rights->expedition->creer) {
$object->fetch($id); $object->fetch($id);
@ -1740,9 +1748,9 @@ if ($action == 'create') {
$text = $langs->trans("ConfirmValidateSending", $numref); $text = $langs->trans("ConfirmValidateSending", $numref);
if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) { if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
$text .= ' '.$langs->trans("StockMovementWillBeRecorded").'.'; $text .= '<br>'.$langs->trans("StockMovementWillBeRecorded").'.';
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { } elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
$text .= ' '.$langs->trans("StockMovementNotYetRecorded").'.'; $text .= '<br>'.$langs->trans("StockMovementNotYetRecorded").'.';
} }
if (isModEnabled('notification')) { if (isModEnabled('notification')) {
@ -1752,7 +1760,7 @@ if ($action == 'create') {
$text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object); $text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object);
} }
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1, 250);
} }
// Confirm cancelation // Confirm cancelation
if ($action == 'cancel') { if ($action == 'cancel') {
@ -2540,15 +2548,22 @@ if ($action == 'create') {
} }
} }
// TODO add alternative status // 0=draft, 1=validated/delivered, 2=closed/delivered
// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order) // If WORKFLOW_BILL_ON_SHIPMENT: 0=draft, 1=validated, 2=billed (no status delivered)
if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer) { if ($object->statut == Expedition::STATUS_VALIDATED && !getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
if ($user->hasRight('expedition', 'creer')) {
print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id, '');
}
}
if ($object->statut == Expedition::STATUS_CLOSED) {
if ($user->hasRight('expedition', 'creer')) {
if (isModEnabled('facture') && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? if (isModEnabled('facture') && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
print dolGetButtonAction('', $langs->trans('ClassifyUnbilled'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, ''); print dolGetButtonAction('', $langs->trans('ClassifyUnbilled'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
} else { } else {
print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, ''); print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
} }
} }
}
// Send // Send
if (empty($user->socid)) { if (empty($user->socid)) {

View File

@ -2318,6 +2318,23 @@ class Expedition extends CommonObject
} }
} }
/**
* Set draft status
*
* @param User $user Object user that modify
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int <0 if KO, >0 if OK
*/
public function setDraft($user, $notrigger = 0)
{
// Protection
if ($this->statut <= self::STATUS_DRAFT) {
return 0;
}
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SHIPMENT_UNVALIDATE');
}
/** /**
* Classify the shipping as validated/opened * Classify the shipping as validated/opened
* *