From 71ed1ec602691baa9c54f9b53b8a138160ace74a Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 23 May 2022 12:07:37 +0200 Subject: [PATCH 1/2] Product lot document management should not use batch but ref (is lot id) --- htdocs/product/stock/productlot_card.php | 9 ++++++++- htdocs/product/stock/productlot_document.php | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index eb6084e5f22..263d9d2c6c8 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -28,6 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; @@ -90,7 +91,13 @@ if ($id || $ref) { $batch = $tmp[1]; } $object->fetch($id, $productid, $batch); - $object->ref = $object->batch; // For document management ( it use $object->ref) + $object->ref = $object->batch; // Old system for document management ( it uses $object->ref) + $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); + if (empty($filearray)) { + // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product) + $object->fetch($id, $productid, $batch); + } } // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array diff --git a/htdocs/product/stock/productlot_document.php b/htdocs/product/stock/productlot_document.php index 789b03aa6ce..dbe2dd517f4 100644 --- a/htdocs/product/stock/productlot_document.php +++ b/htdocs/product/stock/productlot_document.php @@ -83,10 +83,16 @@ if ($id || $ref) { $batch = $tmp[1]; } $object->fetch($id, $productid, $batch); - $object->ref = $object->batch; // For document management ( it use $object->ref) + $object->ref = $object->batch; // Old system for document management ( it uses $object->ref) if (!empty($conf->productbatch->enabled)) { $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); + if (empty($filearray)) { + // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product) + $object->fetch($id, $productid, $batch); + $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); + } } } From 8574f36e352bea8afacbcbcefc68b875c8a258de Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 23 May 2022 15:25:31 +0200 Subject: [PATCH 2/2] dol_dir_list fast mode --- htdocs/product/stock/productlot_card.php | 2 +- htdocs/product/stock/productlot_document.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 263d9d2c6c8..6e6f8991e83 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -93,7 +93,7 @@ if ($id || $ref) { $object->fetch($id, $productid, $batch); $object->ref = $object->batch; // Old system for document management ( it uses $object->ref) $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); + $filearray = dol_dir_list($upload_dir, "files"); if (empty($filearray)) { // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product) $object->fetch($id, $productid, $batch); diff --git a/htdocs/product/stock/productlot_document.php b/htdocs/product/stock/productlot_document.php index dbe2dd517f4..89ba063e8d7 100644 --- a/htdocs/product/stock/productlot_document.php +++ b/htdocs/product/stock/productlot_document.php @@ -87,7 +87,7 @@ if ($id || $ref) { if (!empty($conf->productbatch->enabled)) { $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart); - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); + $filearray = dol_dir_list($upload_dir, "files"); if (empty($filearray)) { // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product) $object->fetch($id, $productid, $batch);