Don't block type changes on a pre-existing répartition écart
updateType() only ever touches field_type_ligne (and possibly field_entree_liee) -- never montant_ht or field_repartition -- so it can't introduce a new répartition mismatch, only leave an existing one (preserved from historical data, per the module's own docblock) untouched. Wrap the save in the same skip_validation state flag the migration scripts use, scoped tightly with try/finally so it always clears even if save() throws for an unrelated reason. Verified: changing the type of a line with a known -0.02€ écart now succeeds, the écart is unchanged afterward (montant_ht and the répartition sum both identical to before), and the state flag reads back unset once the request completes.
This commit is contained in:
@@ -66,12 +66,26 @@ class LedgerActionsController extends ControllerBase {
|
||||
$node->set('field_entree_liee', NULL);
|
||||
}
|
||||
|
||||
// Only field_type_ligne (and possibly field_entree_liee) changes here
|
||||
// -- montant_ht and field_repartition are untouched, so this can never
|
||||
// *introduce* a répartition mismatch, only leave a pre-existing one
|
||||
// (from historical data, never corrected -- see figli_compta_ledger's
|
||||
// module docblock) exactly as it was. The présave check exists to
|
||||
// catch new inconsistent entries, not to block relabeling the type of
|
||||
// an already-migrated line, so skip it for this save only. try/finally
|
||||
// guarantees the global flag clears even if save() throws for an
|
||||
// unrelated reason -- leaving it on would silently skip validation on
|
||||
// every other save on the site.
|
||||
\Drupal::state()->set('figli_compta_ledger.skip_validation', TRUE);
|
||||
try {
|
||||
$node->save();
|
||||
}
|
||||
catch (EntityStorageException $e) {
|
||||
return new JsonResponse(['error' => $e->getMessage()], 422);
|
||||
}
|
||||
finally {
|
||||
\Drupal::state()->delete('figli_compta_ledger.skip_validation');
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'success' => TRUE,
|
||||
|
||||
Reference in New Issue
Block a user