Skip to content

Commit

Permalink
FIX #28564
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 1, 2024
1 parent 6e7263a commit b870a84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
44 changes: 33 additions & 11 deletions htdocs/mrp/class/mo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -900,17 +900,21 @@ public function deleteLine(User $user, $idline, $notrigger = false)
}
$productstatic = new Product($this->db);
$fk_movement = GETPOST('fk_movement', 'int');
$arrayoflines = $this->fetchLinesLinked('consumed', $idline);
$arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consummed under the one to delete

Check failure on line 903 in htdocs/mrp/class/mo.class.php

View workflow job for this annotation

GitHub Actions / pre-commit

mo.class.php: consummed ==> consumed

if (!empty($arrayoflines)) {
$this->db->begin();
$result = 0;

$this->db->begin();

if (!empty($arrayoflines)) {
// If there is child lines
$stockmove = new MouvementStock($this->db);
$stockmove->setOrigin($this->element, $this->id);

if (!empty($fk_movement)) {
// The fk_movement was not recorded so we try to guess the product and quantity to restore.
$moline = new MoLine($this->db);
$TArrayMoLine = $moline->fetchAll('', '', 1, 0, array('customsql' => 'fk_stock_movement ='.$fk_movement));
$TArrayMoLine = $moline->fetchAll('', '', 1, 0, array('customsql' => 'fk_stock_movement = '.(int) $fk_movement));
$moline = array_shift($TArrayMoLine);

$movement = new MouvementStock($this->db);
Expand All @@ -929,13 +933,12 @@ public function deleteLine(User $user, $idline, $notrigger = false)
}
if ($idstockmove < 0) {
$this->error++;
$this->db->rollback();
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
} else {
$this->db->commit();
$result = $moline->delete($user, $notrigger);
}
return $moline->delete($user, $notrigger);
} else {
// Loop on each child lines
foreach ($arrayoflines as $key => $arrayofline) {
$lineDetails = $arrayoflines[$key];
$productstatic->fetch($lineDetails['fk_product']);
Expand All @@ -945,24 +948,43 @@ public function deleteLine(User $user, $idline, $notrigger = false)
$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();
$moline = new MoLine($this->db);
$moline->fetch($lineDetails['rowid']);

$resdel = $moline->delete($user, $notrigger);
if ($resdel < 0) {
$this->error++;
setEventMessages($moline->error, $moline->errors, 'errors');
}
}
}
return $this->deleteLineCommon($user, $idline, $notrigger);

if (empty($this->error)) {
$result = $this->deleteLineCommon($user, $idline, $notrigger);
}
}
} else {
return $this->deleteLineCommon($user, $idline, $notrigger);
// No child lines
$result = $this->deleteLineCommon($user, $idline, $notrigger);
}

if (!empty($this->error) || $result <= 0) {
$this->db->rollback();
} else {
$this->db->commit();
}

return $result;
}


Expand Down
4 changes: 2 additions & 2 deletions htdocs/mrp/mo_production.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@

// Action Edit line
if ($object->status == Mo::STATUS_DRAFT) {
$href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line->id);
$href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line2['rowid']);
print '<td class="center">';
print '<a class="reposition" href="' . $href . '">';
print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit');
Expand All @@ -1288,7 +1288,7 @@

// Action delete line
if ($permissiontodelete) {
$href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line->id).'&fk_movement='.((int) $line2['fk_stock_movement']);
$href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line2['rowid']).'&fk_movement='.((int) $line2['fk_stock_movement']);
print '<td class="center">';
print '<a class="reposition" href="'.$href.'">';
print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
Expand Down

0 comments on commit b870a84

Please sign in to comment.