From ee269b46083cdcb08f3155a6c1cd4f8a330a4ac0 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Tue, 31 Oct 2023 11:47:38 +0100 Subject: [PATCH] FIX: update product with stock to lot or serial type. (#23002) * git init * Fixing style errors. * Add split of serial defaults * Fix remaining part * Fix on remaining decimal part * Revert "Fix on remaining decimal part" This reverts commit b91f884ddc798777c6539933bf235c81f739bec8. * Revert "Fix remaining part" This reverts commit 35a6631b29a01544a48a4c80f8f7a65455dab0bf. * Revert "Add split of serial defaults" This reverts commit 37009afcbc91a6cef1743e29ee5a201d01fb410c. * Remove split for serial numbers and replace by error message. * Fix stickler CI * Fix missing product id for lot number fetch * Allow update for data consistency, but show warning in stock card and stocks by lot/serial list --------- Co-authored-by: Francis Appels Co-authored-by: stickler-ci --- htdocs/expedition/card.php | 4 ++-- htdocs/langs/en_US/productbatch.lang | 2 ++ htdocs/product/class/product.class.php | 14 ++++++++++++++ htdocs/product/reassortlot.php | 10 +++------- htdocs/product/stock/product.php | 8 ++++++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index b261f51e145..ce552fdd71d 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -63,7 +63,7 @@ if (isModEnabled('project')) { } // Load translation files required by the page -$langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal')); +$langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'productbatch')); if (isModEnabled('incoterm')) { $langs->load('incoterm'); @@ -1625,7 +1625,7 @@ if ($action == 'create') { if ($result > 0) { print $productlotObject->getNomUrl(1); } else { - print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed'; + print $langs->trans("TableLotIncompleteRunRepairWithParamStandardEqualConfirmed"); } if (empty($conf->global->PRODUCT_DISABLE_SELLBY) && !empty($dbatch->sellby)) { print ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day"); diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index c51d94b8acd..a84816c9d3c 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -45,3 +45,5 @@ OutOfOrder=Out of order InWorkingOrder=In working order ToReplace=Replace CantMoveNonExistantSerial=Error. You ask a move on a record for a serial that does not exists anymore. May be you take the same serial on same warehouse several times in same shipment or it was used by another shipment. Remove this shipment and prepare another one. +TableLotIncompleteRunRepairWithParamStandardEqualConfirmed=Lot table incomplete run repair with parameter '...repair.php?standard=confirmed' +IlligalQtyForSerialNumbers= Stock correction required because unique serial number. \ No newline at end of file diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 800a9f00b5b..990cd808c7f 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -39,6 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; /** @@ -1168,6 +1169,19 @@ class Product extends CommonObject if ($ObjBatch->create($user, 1) < 0) { $error++; $this->errors = $ObjBatch->errors; + } else { + // we also add lot record if not exist + $ObjLot = new Productlot($this->db); + if ($ObjLot->fetch(0, $this->id, $valueforundefinedlot) == 0) { + $ObjLot->fk_product = $this->id; + $ObjLot->entity = $this->entity; + $ObjLot->fk_user_creat = $user->id; + $ObjLot->batch = $valueforundefinedlot; + if ($ObjLot->create($user, true) < 0) { + $error++; + $this->errors = $ObjLot->errors; + } + } } } } diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index 63abd714011..649e468cc6d 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -438,7 +438,7 @@ $num = $db->num_rows($resql); $i = 0; -if ($num == 1 && GETPOST('autojumpifoneonly') && ($search_all or $snom or $sref)) { +if ($num == 1 && GETPOST('autojumpifoneonly') && ($search_all || $snom || $sref)) { $objp = $db->fetch_object($resql); header("Location: card.php?id=$objp->rowid"); exit; @@ -830,15 +830,11 @@ while ($i < $imaxinloop) { //if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; if (is_null($objp->stock_physique)) { if (!empty($objp->reel)) { - if ($objp->reel < 0) { print ''; } - print price2num($objp->reel, 'MS'); - if ($objp->reel < 0) { print ''; } + print price2num($objp->reel, 'MS').($objp->stock_physique < 0 ? ' '.img_warning() : ''); } } else { if (!empty($objp->stock_physique)) { - if ($objp->stock_physique < 0) { print ''; } - print price2num($objp->stock_physique, 'MS'); - if ($objp->stock_physique < 0) { print ''; } + print price2num($objp->stock_physique, 'MS').($objp->stock_physique < 0 ? ' '.img_warning() : (($objp->stock_physique > 1 && $objp->tobatch == 2) ? ' '.img_warning($langs->trans('IlligalQtyForSerialNumbers')): '')); } } print ''; diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 64331a024d9..ab0b367ca42 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -1166,7 +1166,11 @@ if (!$variants) { print "\n".''; print ''; print ''; - print $product_lot_static->getNomUrl(1); + if ($product_lot_static->id > 0) { + print $product_lot_static->getNomUrl(1); + } else { + print $product_lot_static->getNomUrl(1, 'nolink'); + } print ''; $colspan = 3; if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { @@ -1177,7 +1181,7 @@ if (!$variants) { $colspan--; print ''.dol_print_date($pdluo->eatby, 'day').''; } - print ''.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').''; + print ''.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : (($pdluo->qty > 1 && $object->status_batch == 2) ? ' '.img_warning($langs->trans('IlligalQtyForSerialNumbers')): '')).''; print ''; print ''; if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {