Skip to content

ffl_core.api.trade_in

Source: apps/ffl_core/ffl_core/api/trade_in.py · 3 endpoint(s)

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

create_accessory_item

POST /api/method/ffl_core.api.trade_in.create_accessory_item

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

Make a new accessory / ammo / parts Item from the Trade-in dialog, for something the store has never stocked.

arg type required default description
item_name string yes — The new Item's name; also its code.
item_group string yes — A leaf group under Ammunition, Accessory or Parts — never a firearm group.
sell_price number | null no None Optional selling price (Item.standard_rate).

Returns: {item_code, item_name}.

Permissions: roles.TRADE_IN_ROLES, like the trade-in itself: the counter takes in what the seller brings. Only a non-serialized, non-firearm stock Item can be made here; any other Item stays a stock job (receive_goods.create_item).

apps/ffl_core/ffl_core/api/trade_in.py:375

create_trade_in_intake

POST /api/method/ffl_core.api.trade_in.create_trade_in_intake

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

Create a Used Firearm Item + FFL Acquisition for an individual trade-in.

With payload.apply_credit truthy, the acquisition is parked as a DRAFT (booked at checkout submit) and the result carries credit — a locked negative TRADE-IN-CREDIT line payload for the POS cart. Re-running the dialog for a serial that already has a pending draft refreshes that draft (new cost honoured) instead of duplicating it.

Without apply_credit the store buys the gun and pays the seller now: payload.payout_method (Cash / Zelle / Check / ACH, and payout_reference unless Cash) is required. The gun is received on a Purchase Receipt from the seller, dated today, and the payment booked with it (Dr Stock Received But Not Billed / Cr Cash or the bank) so the cash drawer count includes it (_buy_now).

An antique (payload.is_antique, a pre-1899 receiver) never enters the bound book: it is filed under an antique Item (a new one for this gun, or a chosen antique Item), with credit parked as a draft Material Receipt its credit line locks to (_park_antique), paid now as an antique line on the seller's receipt.

Accessories / ammo (payload.accessories, [{item_code, qty, rate}] with rate the per-unit value) come in alone (has_firearm 0) or with the gun: with apply_credit a draft Material Receipt and a credit line of their own (_park_accessories), without it lines on the same paid receipt.

arg type required default description
payload — yes — Trade-in intake fields (same shape as firearm_intake.create_intake plus seller identity, apply_credit, has_firearm and accessories) — dict or JSON string. crm_deal (a sell-request CRM Deal the dialog was opened from) links the trade-in to that deal once it commits and wins the deal when the gun is booked (crm.sell_requests.after_intake); it changes nothing here.

Returns: {ok, item_code, acquisition} (None without a gun): with apply_credit from firearm_intake.create_intake (or _refresh_pending_draft), plus credits (one locked line per trade-in record: the gun's carries acquisition, the accessories' stock_entry), credit (the gun's) and accessory_receipt; without it from _buy_now (receive_goods._create_receive), plus purchase_receipt and payout ({entry, journal_entry}).

Raises: ValidationError: Missing fields / duplicate serial.

Permissions: roles.TRADE_IN_ROLES: the counter's sales role plus the stock roles; holding only the sales manager role is refused. Gated at entry, covering BOTH branches — the refresh branch (_refresh_pending_draft) rewrites A&D draft seller identity/cost and historically ran ungated (endpoint-gates hardening, 2026-08-07). A caller without a stock role files the gun under no Item (one is made for this gun) or an existing per-gun priced firearm Item (_check_counter_item); making or choosing any other Item stays a stock job. Everything behind the gate runs gate-free (firearm_intake.create_intake, receive_goods._create_receive), each of our writes with ignore_permissions; the ERPNext-internal checks against the session user (the gun's stock bundle) rest on the DocPerm setup/pos_compat.ROLE_GRANTS gives the counter.

apps/ffl_core/ffl_core/api/trade_in.py:117

seller_defaults

POST /api/method/ffl_core.api.trade_in.seller_defaults

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

Prefill for the POS Trade-in dialog's seller section.

A best-effort structured-name split of the Customer (generational suffix pulled out even mid-name — 'pat lee IV Sampleton' → first pat, middle lee, last Sampleton, suffix IV) plus their primary address as a single line ('addr1, City ST zip' — the shape the FastBound push parses). Everything is editable in the dialog; this only saves retyping.

arg type required default description
customer string yes — Customer name; unknown/blank returns {}.

Returns: {source_first_name, source_middle_name, source_last_name, source_suffix, source_address_line1, ...} or {} when unknown.

apps/ffl_core/ffl_core/api/trade_in.py:619