Generation Modes and Triggers

The generation mode answers how the work runs. The trigger answers which sales event is meant to start it. Configure and test both for invoices and credit memos; they are separate settings.

Generation modes

Mode What happens after the sales document is saved Additional service required
Disabled Automatic processing is disabled and the status becomes disabled No
Immediate Generation runs in the Magento request No
Message Queue The document becomes queued and its entity ID is published Matching queue consumer
Scheduled The document becomes scheduled until the hourly cron worker picks it up Magento cron

Choose based on failure handling and operational ownership, not just invoice count. Immediate mode gives quick feedback but adds work to invoice creation. Queue mode separates the work cleanly but requires monitored consumers. Scheduled mode is a simple batch workflow but intentionally delays the file.

A Magento invoice or credit memo enters the selected generation mode. Immediate, queue, cron, and manual paths all use the generator and validator, then store either a generated status or an error for recovery.

The scheduled worker

One cron job handles both document flows:

Job Schedule
einvoice_process_scheduled minute 00 every hour

The job runs in Magento's default cron group. For each store it processes up to the flow's Scheduled Batch Size (default 100, allowed range 1–1000) of due scheduled rows — invoices and credit memos each have their own setting.

The same worker also performs stale-claim recovery: queued or processing rows that have not finished within the flow's Recovery Timeout (Minutes) (default 30, allowed range 5–1440) are claimed again and reprocessed. This recovery covers interrupted workers; it does not retry documents already marked error.

Queue consumers

Queue mode uses two consumers:

php bin/magento queue:consumers:start mageb2b.einvoice.generate
php bin/magento queue:consumers:start mageb2b.einvoice.generate.creditmemo

Run them under the same process supervision you use for other Magento consumers. Starting the invoice consumer does not process credit memos.

Generation triggers

Invoice options are:

  • On Invoice Creation
  • On Invoice Payment
  • Manual Only

Credit-memo options are:

  • On Credit Memo Creation
  • Manual Only

Trigger behavior

The configured trigger must match the actual sales event, otherwise nothing is scheduled. With Manual Only, saving an invoice or credit memo never starts automatic processing — generation is only available through the manual paths below. To stop automatic invoice processing entirely, combine Manual Only with generation mode Disabled.

Immediate mode

Immediate mode is the easiest workflow to observe:

  1. Magento commits the invoice or credit memo.
  2. The extension claims the document and sets processing.
  3. It generates and validates the selected format.
  4. Permanent storage writes files; on-demand storage keeps only generation metadata.
  5. The status becomes generated, or error with the last message.

Because invoice generation is attached to an after-commit event, Block Invoice on E-Invoice Error cannot safely promise that a failed e-invoice prevents the Magento invoice from existing. It can propagate an immediate failure to the request. It cannot roll back async failures, and an already committed sales entity may remain.

Start with this setting disabled. Treat e-invoice failure as an operational status that must be recovered, not as a transactional substitute for Magento's invoice lifecycle.

Queue mode

Queue mode stores queued with a claim token before publishing a message containing the numeric entity ID, store ID and selected context. The consumer loads the document, generates it and writes generated or error.

Monitor all three parts:

  • queued and processing rows in the Magento grids;
  • consumer process health;
  • queue backlog and failed messages in your queue backend.

If a row stays queued, confirm that the matching consumer is running before regenerating manually. Rows stuck beyond the flow's Recovery Timeout are picked up again by the scheduled worker.

Scheduled mode

The hourly einvoice_process_scheduled job processes due scheduled rows per store, up to each flow's Scheduled Batch Size. It also reclaims queued/processing rows whose claim is older than the flow's Recovery Timeout (Minutes), so a crashed worker or consumer does not strand documents.

Cron must run frequently enough for Magento to execute the schedule. Running php bin/magento cron:run --group=default once is a diagnostic step, not a production scheduler.

Manual generation

Manual generation remains available through:

  • Generate E-Invoice on the admin invoice or credit-memo view;
  • grid mass actions;
  • php bin/magento einvoice:generate;
  • the authenticated REST generation endpoints.

The management service skips documents already marked generated. Deliberate regeneration uses force: the REST endpoints accept force: true, and the admin detail-page action automatically applies it when the current status is error. Grid mass actions and einvoice:generate run without force — they skip generated documents and cannot retry an error document.

Recovering a failed document

There is no automatic retry for error documents; recovery is a deliberate manual step:

  1. Open the invoice or credit memo and read the stored error.
  2. Correct the source or configuration problem.
  3. Regenerate once through the detail-page Generate E-Invoice action (it applies force for error rows) or the REST endpoint with force: true.
  4. Download and validate the result before sending it.

Repeated attempts cannot fix missing VAT IDs, wrong buyer references or a format that is not configured correctly. Fix the cause first.