diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index a3bdeb5c12d..eb84e7b2b12 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2087,6 +2087,12 @@ if (empty($reshook)) { $object->situation_counter += 1; + // Set extrafields from the create form BEFORE createFromCurrent(), so they are already + // present when create() inserts them and fires the BILL_CREATE trigger. This avoids firing + // BILL_CREATE a second time just to expose the extrafields (#32217). + $extrafields->fetch_name_optionals_label($object->table_element); + $extrafields->setOptionalsFromPost(null, $object); + $id = $object->createFromCurrent($user); if ($id <= 0) { $mesg = $object->error; @@ -2094,13 +2100,6 @@ if (empty($reshook)) { $nextSituationInvoice = new Facture($db); $nextSituationInvoice->fetch($id); - // create extrafields with data from create form - $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element); - $ret = $extrafields->setOptionalsFromPost(null, $nextSituationInvoice); - if ($ret > 0) { - $nextSituationInvoice->insertExtraFields(); - } - // Hooks $parameters = array('origin_type' => $object->origin_type, 'origin_id' => $object->origin_id); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $nextSituationInvoice, $action); // Note that $action and $object may have been diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e50ddfbc420..f8cd4900f31 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1178,7 +1178,10 @@ class Facture extends CommonInvoice // Retrieve all extrafield // fetch optionals attributes and labels - $this->fetch_optionals(); + // (unless the caller already set array_options, e.g. from a create form, so we don't overwrite them) + if (empty($this->array_options)) { + $this->fetch_optionals(); + } if (!empty($this->array_options)) { $facture->array_options = $this->array_options;