mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-14 08:54:21 +01:00
Merge pull request #20564 from atm-kevin/NEW_Reverse_Movement_Product_Consumption
NEW : Reverse movement product consumption
This commit is contained in:
@@ -69,6 +69,8 @@ ForAQuantityToConsumeOf=For a quantity to disassemble of %s
|
||||
ConfirmValidateMo=Are you sure you want to validate this Manufacturing Order?
|
||||
ConfirmProductionDesc=By clicking on '%s', you will validate the consumption and/or production for the quantities set. This will also update the stock and record stock movements.
|
||||
ProductionForRef=Production of %s
|
||||
CancelProductionForRef=Cancellation of product stock decrementation for product %s
|
||||
TooltipDeleteAndRevertStockMovement=Delete line and revert stock movement
|
||||
AutoCloseMO=Close automatically the Manufacturing Order if quantities to consume and to produce are reached
|
||||
NoStockChangeOnServices=No stock change on services
|
||||
ProductQtyToConsumeByMO=Product quantity still to consume by open MO
|
||||
|
||||
@@ -750,12 +750,79 @@ class Mo extends CommonObject
|
||||
*/
|
||||
public function deleteLine(User $user, $idline, $notrigger = false)
|
||||
{
|
||||
global $langs;
|
||||
$langs->load('stocks');
|
||||
|
||||
if ($this->status < 0) {
|
||||
$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
|
||||
return -2;
|
||||
}
|
||||
|
||||
return $this->deleteLineCommon($user, $idline, $notrigger);
|
||||
$productstatic = new Product($this->db);
|
||||
$fk_movement = GETPOST('fk_movement', 'int');
|
||||
$arrayoflines = $this->fetchLinesLinked('consumed', $idline);
|
||||
|
||||
if (! empty($arrayoflines)) {
|
||||
$this->db->begin();
|
||||
|
||||
$stockmove = new MouvementStock($this->db);
|
||||
$stockmove->setOrigin($this->element, $this->id);
|
||||
|
||||
if (! empty($fk_movement)) {
|
||||
$moline = new MoLine($this->db);
|
||||
$TArrayMoLine = $moline->fetchAll('', '', 1, 0, array('customsql' => 'fk_stock_movement ='.$fk_movement));
|
||||
$moline = array_shift($TArrayMoLine);
|
||||
|
||||
$movement = new MouvementStock($this->db);
|
||||
$movement->fetch($fk_movement);
|
||||
$productstatic->fetch($movement->product_id);
|
||||
$qtytoprocess = $movement->qty;
|
||||
|
||||
// Reverse stock movement
|
||||
$labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
|
||||
$codemovementCancel = $langs->trans("StockIncrease");
|
||||
|
||||
if (($qtytoprocess >= 0)) {
|
||||
$idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel);
|
||||
} else {
|
||||
$idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel);
|
||||
}
|
||||
if ($idstockmove < 0) {
|
||||
$this->error++;
|
||||
$this->db->rollback();
|
||||
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
|
||||
} else {
|
||||
$this->db->commit();
|
||||
}
|
||||
return $moline->delete($user, $notrigger);
|
||||
} else {
|
||||
foreach ($arrayoflines as $key => $arrayofline) {
|
||||
$lineDetails = $arrayoflines[$key];
|
||||
$productstatic->fetch($lineDetails['fk_product']);
|
||||
$qtytoprocess = $lineDetails['qty'];
|
||||
|
||||
// Reverse stock movement
|
||||
$labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
|
||||
$codemovementCancel = $langs->trans("StockIncrease");
|
||||
|
||||
if ($qtytoprocess >= 0) {
|
||||
$idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
|
||||
} else {
|
||||
$idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
|
||||
}
|
||||
if ($idstockmove < 0) {
|
||||
$this->error++;
|
||||
$this->db->rollback();
|
||||
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
|
||||
} else {
|
||||
$this->db->commit();
|
||||
}
|
||||
}
|
||||
return $this->deleteLineCommon($user, $idline, $notrigger);
|
||||
}
|
||||
} else {
|
||||
return $this->deleteLineCommon($user, $idline, $notrigger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ $cancel = GETPOST('cancel', 'aZ09');
|
||||
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
|
||||
$backtopage = GETPOST('backtopage', 'alpha');
|
||||
$lineid = GETPOST('lineid', 'int');
|
||||
$fk_movement = GETPOST('fk_movement', 'int');
|
||||
|
||||
$collapse = GETPOST('collapse', 'aZ09comma');
|
||||
|
||||
@@ -445,7 +446,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
}
|
||||
// Confirmation to delete line
|
||||
if ($action == 'deleteline') {
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid.'&fk_movement='.$fk_movement, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
|
||||
}
|
||||
// Clone confirmation
|
||||
if ($action == 'clone') {
|
||||
@@ -914,7 +915,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
$href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line->id);
|
||||
print '<td class="center">';
|
||||
print '<a class="reposition" href="'.$href.'">';
|
||||
print img_picto('', 'delete');
|
||||
print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
|
||||
print '</a>';
|
||||
print '</td>';
|
||||
}
|
||||
@@ -969,7 +970,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
|
||||
// Action delete line
|
||||
if ($permissiontodelete) {
|
||||
print '<td></td>';
|
||||
$href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line->id).'&fk_movement='.((int) $line2['fk_stock_movement']);
|
||||
print '<td class="center">';
|
||||
print '<a class="reposition" href="'.$href.'">';
|
||||
print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
|
||||
print '</a>';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
print '</tr>';
|
||||
@@ -1220,7 +1226,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
$href .= '&lineid='.$line->id;
|
||||
print '<td class="center">';
|
||||
print '<a class="reposition" href="'.$href.'">';
|
||||
print img_picto('', "delete");
|
||||
print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), "delete");
|
||||
print '</a>';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user