Skip to content

Commit

Permalink
fix/feat: ProductLot document folder have to be the rowid (#29859)
Browse files Browse the repository at this point in the history
* fix/feat: ProductLot docuement folder have to be ID as batch is not unique

* fix/feat: ProductLot docuement folder have to be ID as batch is not unique

* add translation

* fix travis

* fix travis

* fix CI*

* fix CI

* fix: travis CI

* reset from develop

* reset from develop

* reset from develop

* reset from develop

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
  • Loading branch information
FHenry and eldy authored Nov 13, 2024
1 parent 8c9a1c2 commit ba46e7d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 17 deletions.
52 changes: 51 additions & 1 deletion htdocs/install/upgrade2.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,15 @@
$afterversionarray = explode('.', '18.0.9');
$beforeversionarray = explode('.', '19.0.9');
if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_contractdet_rank();
}
*/

// Scripts for 20.0
$afterversionarray = explode('.', '19.0.9');
$beforeversionarray = explode('.', '20.0.9');
if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_productlot_path();
}
}


Expand Down Expand Up @@ -4380,6 +4386,50 @@ function migrate_reload_menu($db, $langs, $conf)
return 1;
}

/**
* Migrate file from old path to new one for lot path
*
* @return void
*/
function migrate_productlot_path()
{
global $conf, $db, $langs, $user;

print '<tr><td colspan="4">';

print '<b>'.$langs->trans('MigrationProductLotPath')."</b><br>\n";

$sql = "SELECT rowid , entity, batch, fk_product from ".MAIN_DB_PREFIX."product_lot";
$resql = $db->query($sql);
if ($resql) {
$modulepart="product_batch";
while ($obj = $db->fetch_object($resql)) {
$entity = (empty($obj->entity) ? 1 : $obj->entity);
if ($entity > 1) {
$dir = DOL_DATA_ROOT.'/'.$entity.'/'.$conf->productbatch->multidir_output[$entity];
} else {
$dir = $conf->productbatch->multidir_output[$entity];
}

$lot = new Productlot($db);
$res = $lot->fetch($obj->rowid, $obj->fk_product, $obj->batch);

if ($dir && $res > 0) {
$lot->ref = $obj->batch;
$origin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);

$lot->fetch($obj->rowid, $obj->fk_product, $obj->batch);
$destin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);

if (dol_is_dir($origin) && !dol_is_dir($destin)) {
dol_move_dir($origin, $destin, 0);
}
}
}
}
print '</td></tr>';
}

/**
* Migrate file from old path to new one for users
*
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/install.lang
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,4 @@ FunctionTest=Function test
NodoUpgradeAfterDB=No action requested by external modules after upgrade of database
NodoUpgradeAfterFiles=No action requested by external modules after upgrade of files or directories
MigrationContractLineRank=Migrate Contract Line to use Rank (and enable Reorder)
MigrationProductLotPath=Migrate Product Batch files path
12 changes: 6 additions & 6 deletions htdocs/product/stock/productlot_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
$productid = GETPOSTINT('productid');
$ref = GETPOST('ref', 'alpha'); // ref is productid_batch


$modulepart = 'product_batch';


// Initialize a technical objects

$object = new Productlot($db);
$extrafields = new ExtraFields($db);
$hookmanager->initHooks(array('productlotcard', 'globalcard')); // Note that conf->hooks_modules contains array
Expand Down Expand Up @@ -103,13 +108,8 @@
$batch = $tmp[1];
}
$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");
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 a technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
Expand Down Expand Up @@ -602,7 +602,7 @@
// Documents
if ($includedocgeneration) {
$objref = dol_sanitizeFileName($object->ref);
$relativepath = $objref.'/'.$objref.'.pdf';
$relativepath = $object->id.'/'.$objref.'.pdf';
$filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product_batch');
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed = $usercanread; // If you can read, you can build the PDF to read content
Expand Down
6 changes: 0 additions & 6 deletions htdocs/product/stock/productlot_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,10 @@
$batch = $tmp[1];
}
$object->fetch($id, $productid, $batch);
$object->ref = $object->batch; // Old system for document management ( it uses $object->ref)

if (isModEnabled('productbatch')) {
$upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
$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);
$upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions htdocs/takepos/receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
<tr>
<th class="right"><?php if ($gift != 1) {
echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
} ?></td>
} ?></th>
</tr>
<?php }

Expand All @@ -300,20 +300,20 @@
<tr>
<th class="right"><?php if ($gift != 1) {
echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
} ?></td>
} ?></th>
</tr>
<?php } ?>
<?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
<tr>
<th class="right"><?php if ($gift != 1) {
echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
} ?></td>
} ?></th>
</tr>
<?php } ?>
<tr>
<th class="right"><?php if ($gift != 1) {
echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
} ?></td>
} ?></th>
</tr>
<?php
if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
Expand Down

0 comments on commit ba46e7d

Please sign in to comment.