Skip to content

ffl_core.api.pos_consolidate

Source: apps/ffl_core/ffl_core/api/pos_consolidate.py · 2 endpoint(s)

Generated by make api-docs — do not edit by hand.

consolidate_pos_invoice_now

POST /api/method/ffl_core.api.pos_consolidate.consolidate_pos_invoice_now

Auth (derived from code): Roles: Sales User / Sales Manager / Stock Manager / System Manager

Consolidate one submitted POS Invoice immediately (out-of-band).

Out-of-band from the POS closing batch, so its stock + Sales Invoice post now — a sold serialized gun must leave stock at sale, not at the nightly close. Idempotent: no-ops if the invoice is missing, not submitted, already consolidated, or a return whose original sale is not yet consolidated (a return becomes a credit note against the original's consolidated Sales Invoice, so the original must go first — the sweep orders them that way; see reconsolidate_stuck_pos_invoices). A merge that loses a row race to a concurrent write, or times out waiting for a lock, is rolled back and run again: 3 attempts in all.

arg type required default description
pos_invoice string yes — Submitted POS Invoice name.

Returns: {consolidated: bool, pos_invoice, [sales_invoice]}.

Permissions: Sales User / Sales Manager / Stock Manager / System Manager.

apps/ffl_core/ffl_core/api/pos_consolidate.py:71

reconsolidate_stuck_pos_invoices

POST /api/method/ffl_core.api.pos_consolidate.reconsolidate_stuck_pos_invoices

Auth (derived from code): Roles: Sales Manager / Stock Manager / System Manager

Retry every submitted POS Invoice that never consolidated (the sweep).

Covers two ways a sale gets stranded: a firearm invoice whose immediate on-submit consolidation failed (always swept, never capped), and any invoice — returns included — from the last 30 days that the nightly POS close left behind (the close is owner-scoped, so a sale rung up by a clerk other than the shift opener is skipped — see _find_stuck_pos_invoices). The missed-close part works in batches of 50 per run, originals before their returns, invoices already carrying a stuck ToDo last; idempotent per invoice (consolidate_pos_invoice_now no-ops the already-done ones). A failure is logged AND surfaced as a ToDo (at most 5 new ToDos per run, plus one summary log when more failed); a return held for an original the sweep can never reach is surfaced the same way. Each run then closes those ToDos for every invoice that has merged since, however it merged. Runs from the scheduler (hooks.scheduler_events) and is whitelisted for an on-demand sweep.

arg type required default description
older_than_minutes integer | null no None Only sweep invoices older than this settle window (default 10), so the sweep never races the on-submit enqueue on a fresh sale.
batch integer | null no None Missed-close invoices to take this run (default 50, clamped to 1–500) — for a manual sweep of a known backlog.

Returns: {checked, consolidated: [names], failed: [names], held: [names]} — held = returns waiting for their original to consolidate first.

Permissions: Sales Manager / Stock Manager / System Manager.

apps/ffl_core/ffl_core/api/pos_consolidate.py:246