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) {