From 2149bb6f0fb77f7f60bc2d7c0f13831e0dfae5ac Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 14 Jun 2026 00:34:36 +0200 Subject: [PATCH] Fix #37773 align inventory pmp-perentity write condition with Product::fetch read (#38802) htdocs/product/inventory/inventory.php:264 wrote into llx_product_perentity under MAIN_PRODUCT_PERENTITY_SHARED, but Product::fetch at line 2995-2997 of htdocs/product/class/product.class.php only reads pmp from that table when both MULTICOMPANY_PRODUCT_SHARING_ENABLED and MULTICOMPANY_PMP_PER_ENTITY_ENABLED are set. MAIN_PRODUCT_PERENTITY_SHARED is the accountancy-codes flag; using it to gate the pmp write meant inventory wrote a value that fetch would silently ignore (and overwriting whatever was there before). Align the inventory write with the fetch read so the two stay in sync. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/product/inventory/inventory.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 1a37449726f..6cd7cfc1d5f 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -261,7 +261,12 @@ if (empty($reshook)) { setEventMessages($db->lasterror(), null, 'errors'); break; } - if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { + // Mirror Product::fetch (product.class.php:2995-2997) which reads pmp from + // llx_product_perentity only when MULTICOMPANY_PRODUCT_SHARING_ENABLED and + // MULTICOMPANY_PMP_PER_ENTITY_ENABLED are both set. MAIN_PRODUCT_PERENTITY_SHARED + // is the accountancy-codes flag; using it to gate the pmp write here means we + // silently write into a row that fetch never looks at (#37773). + if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) { $sqlpmp = 'UPDATE '.MAIN_DB_PREFIX.'product_perentity SET pmp = '.((float) $line->pmp_real).' WHERE fk_product = '.((int) $line->fk_product).' AND entity='.$conf->entity; $resqlpmp = $db->query($sqlpmp); if (! $resqlpmp) {