#40730·dolibarr

Supplier order: notification subject carries the provisional PROV reference instead of the final one

Author: lhalfaouiCreated Sep 23, 2026Updated Sep 30, 2026

Bug

When a supplier order is validated for the first time, the notification e-mail sent by the Notifications module carries the provisional reference (PROVxxx) in its subject, while the order has already received its definitive reference in database.

The body of the very same e-mail carries the correct reference, because the default message is built from $newref, whereas the subject goes through the substitution array and reads $object->ref, which has not been refreshed yet.

Using a custom e-mail template does not work around it: __REF__ resolves from the same stale object.

Environment Version

22.0.3

Environment OS

Linux (shared hosting, O2Switch)

Environment Web server

Apache

Environment PHP

8.1.34

Environment Database

MariaDB 11.4

Steps to reproduce the behavior and expected behavior

Steps to reproduce

  1. Enable the Notifications module and declare a notification on ORDER_SUPPLIER_VALIDATE
  2. Create a new supplier order and leave it as draft — note its provisional reference, e.g. PROV123
  3. Validate it for the first time
  4. Read the notification e-mail

Current behaviour

  • Subject contains PROV123
  • Body of the same e-mail contains the definitive reference, e.g. CF2609-0001
  • Database holds the definitive reference

Re-validating an already validated order does not reproduce it: $this->ref no longer matches ^PROV, so the branch that regenerates the reference is skipped and the trigger sees the correct value.

Expected behaviour

The subject should carry the definitive reference, consistently with the body and the database.

Root cause

In htdocs/fourn/class/fournisseur.commande.class.php, method valid():

php
$num = $this->getNextNumRef($soc);          // definitive reference computed
$this->newref = dol_sanitizeFileName($num);
$sql .= " SET ref='".$this->db->escape($num)."',";   // written to database
...
$result = $this->call_trigger('ORDER_SUPPLIER_VALIDATE', $user);   // notification sent here
...                                          // file / directory renaming, which needs the OLD ref
$this->ref = $num;                           // object refreshed only now

The trigger fires before $this->ref is refreshed.

Simply moving the assignment earlier is not enough, since the renaming block deliberately relies on $this->ref still holding the previous value (// We rename directory ($this->ref = old ref, $num = new ref)). The call_trigger() call should be moved after that block instead, so the trigger receives a fully consistent object.

approve() shows the same ordering, with $this->ref = $this->newref; placed after call_trigger('ORDER_SUPPLIER_APPROVE', ...).

For reference, in htdocs/core/class/notify.class.php the default message builds its link from $newref, which is why the body is correct while the subject, produced by make_substitutions() over getCommonSubstitutionArray(..., $object), is not.

The same ordering is present on branch 22.0 and on the development branch, so the issue is not a regression limited to one release.

Attached files

No response