Skip to content

FIX Wrong stock valuation when MultiCompany PMP per entity is enabled - #39738

Open
hregis wants to merge 1 commit into
Dolibarr:23.0from
hregis:fix_23_pmp_per_entity
Open

FIX Wrong stock valuation when MultiCompany PMP per entity is enabled#39738
hregis wants to merge 1 commit into
Dolibarr:23.0from
hregis:fix_23_pmp_per_entity

Conversation

@hregis

@hregis hregis commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Rows in llx_product_perentity are only created on the first stock movement of a product in an entity, so a product with no row yet is the norm on an existing database, not an edge case. Product::fetch() already handles this by falling back on the global llx_product.pmp, but three other places did not, each in a different way:

  • Entrepot::nb_products(): inner join, so such a product was excluded from both the product count and the warehouse value.
  • product/stock/card.php: inner join, so such a product did not appear at all in the warehouse content list.
  • product/stock/list.php: left join but no fallback, so pa.pmp was NULL and the product was valued at 0.

Align all three on the behaviour of Product::fetch(): left join plus an explicit COALESCE(pa.pmp, p.pmp) fallback. Behaviour is unchanged when the llx_product_perentity row exists.

Also fix product/stock/card.php where the "estimated value" column mixed both sources: ppmp (displayed) used pa.pmp while svalue (its sort key) used p.pmp, so the column did not sort on the value it showed.

Rows in llx_product_perentity are only created on the first stock movement
of a product in an entity, so a product with no row yet is the norm on an
existing database, not an edge case. Product::fetch() already handles this
by falling back on the global llx_product.pmp, but three other places did
not, each in a different way:

- Entrepot::nb_products(): inner join, so such a product was excluded from
  both the product count and the warehouse value.
- product/stock/card.php: inner join, so such a product did not appear at
  all in the warehouse content list.
- product/stock/list.php: left join but no fallback, so pa.pmp was NULL and
  the product was valued at 0.

Align all three on the behaviour of Product::fetch(): left join plus an
explicit COALESCE(pa.pmp, p.pmp) fallback. Behaviour is unchanged when the
llx_product_perentity row exists.

Also fix product/stock/card.php where the "estimated value" column mixed
both sources: ppmp (displayed) used pa.pmp while svalue (its sort key) used
p.pmp, so the column did not sort on the value it showed.
@hregis
hregis requested a review from eldy August 25, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant