Fix #23108: - Set NULL on fk_warehouse if stockmovement is empty.

- Fix deletion on lines without stockmovement -> set the correct rowid of the line.
- Fix stock qty and warnings correct.
This commit is contained in:
Christian Humpel 2023-01-09 00:49:24 +01:00
parent 3e12a8ab21
commit fc0ef489e6

View File

@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2023 Christian Humpel <christian.humpel@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -239,7 +240,7 @@ if (empty($reshook)) {
$moline->batch = GETPOST('batch-'.$line->id.'-'.$i);
$moline->role = 'consumed';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_stock_movement = $idstockmove == 0 ? null : $idstockmove;
$moline->fk_user_creat = $user->id;
$resultmoline = $moline->create($user);
@ -924,10 +925,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Stock
if (isModEnabled('stock')) {
print '<td class="nowraponall right">';
if ($tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
print img_warning($langs->trans('StockTooLow')).' ';
if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $tmpproduct->type != PRODUCT::TYPE_SERVICE) {
if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
print img_warning($langs->trans('StockTooLow')) . ' ';
}
print price2num($tmpproduct->stock_reel, 'MS'); // Available
}
print price2num($tmpproduct->stock_reel, 'MS'); // Available
print '</td>';
}
// Lot
@ -1001,7 +1004,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// 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');