lambda-erp 1.4.9__tar.gz → 1.4.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/PKG-INFO +1 -1
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/chat.py +33 -3
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/errors.py +5 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf_profiles.py +4 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/masters.py +15 -1
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/reports.py +65 -10
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/services.py +7 -1
- lambda_erp-1.4.11/api/stock_actions.py +200 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/frontend/src/api/client.ts +6 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/pos_invoice.py +2 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/sales_invoice.py +2 -0
- lambda_erp-1.4.11/lambda_erp/backlog.py +196 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/database.py +72 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/exceptions.py +4 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/hooks.py +6 -2
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/model.py +4 -0
- lambda_erp-1.4.11/lambda_erp/stock/consignment.py +378 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/stock/delivery_note.py +60 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/stock/stock_entry.py +12 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/validation.py +10 -1
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/workflow.py +97 -1
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/pyproject.toml +1 -1
- lambda_erp-1.4.9/api/stock_actions.py +0 -79
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/.gitignore +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/LICENSE +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/README.md +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/attachments.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/auth.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/chat_links.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/deps.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/erp_context.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/list_values.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/main.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/mentions.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/oauth.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/providers.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/record_notes.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/document.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/record.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/time_filters.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/api/write_context.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/frontend/README.md +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.9 → lambda_erp-1.4.11}/terraform/README.md +0 -0
|
@@ -878,7 +878,7 @@ TOOLS = [
|
|
|
878
878
|
"parameters": {
|
|
879
879
|
"type": "object",
|
|
880
880
|
"properties": {
|
|
881
|
-
"report_type": {"type": "string", "enum": ["trial-balance", "general-ledger", "stock-balance", "stock-availability", "stock-detail", "batch-stock", "batch-movements", "dashboard-summary", "profit-and-loss", "balance-sheet", "ar-aging", "ap-aging"]},
|
|
881
|
+
"report_type": {"type": "string", "enum": ["trial-balance", "general-ledger", "stock-balance", "stock-availability", "stock-detail", "batch-stock", "batch-movements", "sales-backlog", "purchase-backlog", "dashboard-summary", "profit-and-loss", "balance-sheet", "ar-aging", "ap-aging"]},
|
|
882
882
|
"filters": {"type": "object", "description": "Optional filters: company, account, from_date, to_date, item_code, warehouse; for batch-stock also batch_no, item_prefix, expiring_before, include_empty; for stock-detail also location, batch_no, item_prefix, item_group, expiring_before, expiring_after, include_empty; batch-movements requires batch_no. For trial-balance / profit-and-loss / balance-sheet you may also pass `presentation_currency` (e.g. \"EUR\") to view the report translated from the company's base currency at the period's closing rate — display only, the ledger stays in base currency.", "default": {}},
|
|
883
883
|
},
|
|
884
884
|
"required": ["report_type"],
|
|
@@ -1974,15 +1974,26 @@ def _handle_get_report(args):
|
|
|
1974
1974
|
return _batch_stock(db, filters.get("item_code"), filters.get("warehouse"), filters.get("batch_no"),
|
|
1975
1975
|
filters.get("item_prefix"), filters.get("expiring_before"),
|
|
1976
1976
|
bool(filters.get("include_empty")))
|
|
1977
|
+
elif report_type == "sales-backlog":
|
|
1978
|
+
from api.routers.reports import _sales_backlog
|
|
1979
|
+
return _sales_backlog(db, filters.get("customer"), filters.get("item_code"), filters.get("warehouse"),
|
|
1980
|
+
filters.get("sales_order"), filters.get("item_prefix"),
|
|
1981
|
+
bool(filters.get("only_deliverable")))
|
|
1982
|
+
elif report_type == "purchase-backlog":
|
|
1983
|
+
from api.routers.reports import _purchase_backlog
|
|
1984
|
+
return _purchase_backlog(db, filters.get("supplier"), filters.get("item_code"), filters.get("warehouse"),
|
|
1985
|
+
bool(filters.get("overdue_only")))
|
|
1977
1986
|
elif report_type == "stock-availability":
|
|
1978
1987
|
from api.routers.reports import _stock_availability
|
|
1979
1988
|
return _stock_availability(db, filters.get("item_code"), filters.get("warehouse"), filters.get("item_prefix"))
|
|
1980
1989
|
elif report_type == "stock-detail":
|
|
1981
1990
|
from api.routers.reports import _stock_detail
|
|
1991
|
+
consignment = filters.get("consignment")
|
|
1982
1992
|
return _stock_detail(db, filters.get("item_code"), filters.get("warehouse"), filters.get("location"),
|
|
1983
1993
|
filters.get("batch_no"), filters.get("item_prefix"), filters.get("item_group"),
|
|
1984
1994
|
filters.get("expiring_before"), filters.get("expiring_after"),
|
|
1985
|
-
bool(filters.get("include_empty")))
|
|
1995
|
+
bool(filters.get("include_empty")), filters.get("consignment_customer"),
|
|
1996
|
+
None if consignment is None else bool(consignment))
|
|
1986
1997
|
elif report_type == "batch-movements":
|
|
1987
1998
|
from api.routers.reports import _batch_movements
|
|
1988
1999
|
if not filters.get("batch_no"):
|
|
@@ -2918,6 +2929,23 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2918
2929
|
- **Material Transfer:** Moves stock between warehouses. No GL impact.
|
|
2919
2930
|
- **Batch Assignment:** Gives stock that has no batch (from before the item was batch-tracked) its batch, in place: row = item_code, qty, t_warehouse, batch_no (+ expiry_date for a new batch). No GL impact, no quantity or value change.
|
|
2920
2931
|
|
|
2932
|
+
### Consignment (own stock lying at a customer)
|
|
2933
|
+
- A **consignment warehouse** is a warehouse with `consignment_customer` set. The goods in it are still ours (in stock and stock value) until the customer uses them.
|
|
2934
|
+
- **Stocking** (sending goods to the customer's consignment stock) is NOT a sale and gets NO invoice: use the `prepare_consignment_stocking` action (warehouse, items) to draft the Material Transfer, review it, then submit it.
|
|
2935
|
+
- **Withdrawal** (the customer reports what they used, usually with lot numbers) is billed: use the `record_consignment_withdrawal` action with the consignment warehouse, the items (item_code, qty, batch_no as reported) and, when the report has a number, external_source + external_reference. It creates ONE Sales Invoice that also takes the goods out of stock. Never create a separate delivery note or invoice for the same goods. Sending the same report again returns the first result; the same report number with different content is refused (cancel the recorded withdrawal first).
|
|
2936
|
+
- **Withdrawal with replacement** (the customer wants the used goods restocked): pass replenish=true. The replacement is a separate draft Material Transfer with its own status; the withdrawal is billed even when the replacement cannot be shipped yet.
|
|
2937
|
+
- **Recall** (taking goods back) is a transfer, not a credit note: `prepare_consignment_recall` (warehouse, to_warehouse, optional items).
|
|
2938
|
+
- Goods in a consignment warehouse can only be sold to its customer. To give them to someone else, recall them first.
|
|
2939
|
+
- If a reported batch is not in that consignment warehouse (wrong or mistyped lot number), the withdrawal is refused: tell the user what the stock-detail report shows there and ask, do not substitute a batch.
|
|
2940
|
+
- If it is unclear whether an incoming order is a stocking request, a withdrawal or a normal order, ask.
|
|
2941
|
+
|
|
2942
|
+
### Partial deliveries, backorders and invoicing after delivery
|
|
2943
|
+
- Order progress is derived from the submitted documents, per order line: delivered_qty (net of returns), returned_qty, billed_qty. Never set them. Open = qty − delivered_qty.
|
|
2944
|
+
- A delivery for less than ordered leaves the rest of the line open; convert the order again later for the remainder. Converters only ever propose what is left, and submit rechecks, so a repeated conversion cannot deliver or bill twice.
|
|
2945
|
+
- Deliver first, invoice after: convert the submitted **Delivery Note** to a Sales Invoice (convert_document doctype="delivery-note", target_doctype="Sales Invoice"). It bills what that delivery delivered and has not been billed, and does not move stock again. Converting the Sales Order to a Sales Invoice instead bills the ordered quantity regardless of delivery.
|
|
2946
|
+
- "What is still open / on backorder / can go out now" → sales-backlog report. "Is it on order, and when does it come" → the same report's purchase order columns, or purchase-backlog.
|
|
2947
|
+
- When a supplier's order confirmation arrives, record its date with the `confirm_purchase_order` action.
|
|
2948
|
+
|
|
2921
2949
|
### Prices: how they are found, and explaining them
|
|
2922
2950
|
- A line without a rate is priced when the document is saved: the Item Price of the document's price list (a row for this customer/supplier beats the list price; the highest min_qty reached; the narrower, then newer validity), else the item's standard rate. Then at most ONE Pricing Rule applies on top: highest priority, then the most specific match, then min_qty, validity and name.
|
|
2923
2951
|
- Prices and rules are looked up for the document's date (`pricing_date` if set, else posting/transaction date). A price valid from next month does not apply to a document dated today.
|
|
@@ -3003,8 +3031,10 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3003
3031
|
- **ar-aging** — Outstanding receivables bucketed by overdue days (Current, 1-30, 31-60, 61-90, 90+). Filters: company, as_of_date.
|
|
3004
3032
|
- **ap-aging** — Outstanding payables bucketed by overdue days. Filters: company, as_of_date.
|
|
3005
3033
|
- **stock-balance** — Inventory quantities and valuations. Filters: item_code, warehouse.
|
|
3034
|
+
- **sales-backlog** — Open sales order lines (ordered > delivered): ordered_qty, delivered_qty (net of returns), returned_qty, billed_qty, open_qty, reserved_qty, deliverable_qty (what can be delivered NOW; stock is shared out in due-date order, so it is never promised twice), short_qty, on_purchase_order_qty, next_expected_date and the purchase orders behind it. Filters: customer, item_code, item_prefix, warehouse, sales_order, only_deliverable. Use only_deliverable=true after a goods receipt to see which open orders can now go out. Read-only: it books nothing.
|
|
3035
|
+
- **purchase-backlog** — Open purchase order lines with expected_date (the supplier's confirmed date, else the order's schedule date), confirmed, overdue and days_overdue. Filters: supplier, item_code, warehouse, overdue_only. Use overdue_only=true for "what should have arrived".
|
|
3006
3036
|
- **stock-availability** — Per item × warehouse: physical_qty (in stock), blocked_qty (expired or blocked batches), reserved_qty (open Stock Reservations), available_qty (= physical − blocked − reserved), plus open_sales_order_qty (ordered by customers, not yet delivered) and on_purchase_order_qty (ordered from suppliers, not yet received). Filters: item_code, warehouse, item_prefix. Use this to answer "can we deliver X" and "is it already on order".
|
|
3007
|
-
- **stock-detail** — Where stock is, in one view: item, warehouse, storage location, batch, expiry date, quantity. Filters: item_code, warehouse, location, batch_no, item_prefix, item_group, expiring_before, expiring_after, include_empty. Use this for "what is in location B4", "where is item X", "what expires in the next 3 months in warehouse Y".
|
|
3037
|
+
- **stock-detail** — Where stock is, in one view: item, warehouse, consignment_customer (who it lies with, for consignment warehouses), storage location, batch, expiry date, quantity. Filters: item_code, warehouse, location, batch_no, item_prefix, item_group, expiring_before, expiring_after, include_empty, consignment_customer (one customer's consignment stock), consignment (true = only consignment, false = only own warehouses). Use this for "what is in location B4", "where is item X", "what expires in the next 3 months in warehouse Y".
|
|
3008
3038
|
- **batch-stock** — Quantity per item × warehouse × batch with the batch's expiry date (batch-tracked items only). Filters: item_code, warehouse, batch_no, item_prefix (item codes starting with…), expiring_before (date), include_empty. A batch label is NOT unique: the same label can exist on several items, so a batch_no-only lookup can return several items — show them all, never pick one.
|
|
3009
3039
|
- **batch-movements** — Every stock movement of a batch with document, line and customer/supplier: where it came from and who received it (recalls). Filters: batch_no (required), item_code, warehouse.
|
|
3010
3040
|
- **dashboard-summary** — KPI overview (revenue, receivables, payables, stock value).
|
|
@@ -14,6 +14,7 @@ from lambda_erp.exceptions import (
|
|
|
14
14
|
InvalidCurrency,
|
|
15
15
|
InsufficientFunds,
|
|
16
16
|
PermissionDenied,
|
|
17
|
+
ConflictError,
|
|
17
18
|
)
|
|
18
19
|
|
|
19
20
|
|
|
@@ -86,6 +87,10 @@ def register_exception_handlers(app: FastAPI):
|
|
|
86
87
|
async def value_error(request: Request, exc: ValueError):
|
|
87
88
|
return JSONResponse(status_code=422, content={"detail": str(exc)})
|
|
88
89
|
|
|
90
|
+
@app.exception_handler(ConflictError)
|
|
91
|
+
async def conflict_error(request: Request, exc: ConflictError):
|
|
92
|
+
return JSONResponse(status_code=409, content={"detail": str(exc)})
|
|
93
|
+
|
|
89
94
|
@app.exception_handler(PermissionDenied)
|
|
90
95
|
async def permission_denied(request: Request, exc: PermissionDenied):
|
|
91
96
|
return JSONResponse(status_code=403, content={"detail": str(exc)})
|
|
@@ -82,6 +82,10 @@ PROFILES.update({
|
|
|
82
82
|
fields=('company', 'party_type', 'party', 'start_date', 'end_date', 'billing_interval', 'current_invoice_start', 'current_invoice_end'),
|
|
83
83
|
required=('company', 'party_type', 'party', 'start_date', 'billing_interval'),
|
|
84
84
|
tables=(PDFTable('plans', ('item_code', 'item_name', 'qty', 'rate'), ('item_code', 'qty', 'rate'), True),)),
|
|
85
|
+
'Consignment Withdrawal': PDFProfile('record', 'Consignment withdrawal',
|
|
86
|
+
fields=('company', 'customer', 'warehouse', 'posting_date', 'external_reference', 'sales_invoice', 'remarks'),
|
|
87
|
+
required=('customer', 'warehouse', 'posting_date', 'items'),
|
|
88
|
+
tables=(PDFTable('items', ('item_code', 'item_name', 'qty', 'uom', 'batch_no'), ('item_code', 'qty'), True),)),
|
|
85
89
|
'Stock Reservation': PDFProfile('record', 'Stock reservation overview',
|
|
86
90
|
fields=('item_code', 'warehouse', 'reserved_qty', 'sales_order', 'customer', 'status', 'remarks', 'reserved_by', 'company'),
|
|
87
91
|
required=('item_code', 'warehouse', 'reserved_qty')),
|
|
@@ -220,7 +220,8 @@ MASTER_LINK_FIELDS = {
|
|
|
220
220
|
'customer': {'default_price_list': 'Price List'},
|
|
221
221
|
'company': {'default_price_list': 'Price List'},
|
|
222
222
|
'item': {'default_warehouse': 'Warehouse'},
|
|
223
|
-
'warehouse': {'company': 'Company', 'account': 'Account', 'parent_warehouse': 'Warehouse'
|
|
223
|
+
'warehouse': {'company': 'Company', 'account': 'Account', 'parent_warehouse': 'Warehouse',
|
|
224
|
+
'consignment_customer': 'Customer', 'replenishment_warehouse': 'Warehouse'},
|
|
224
225
|
'account': {'company': 'Company', 'parent_account': 'Account'},
|
|
225
226
|
'cost-center': {'company': 'Company', 'parent_cost_center': 'Cost Center'},
|
|
226
227
|
'batch': {'item_code': 'Item'},
|
|
@@ -322,6 +323,19 @@ def _validate_warehouse_locations(db, merged, name):
|
|
|
322
323
|
off while stock lies in a location."""
|
|
323
324
|
if flt(merged.get('use_locations')) and flt(merged.get('is_group')):
|
|
324
325
|
raise ValidationError('Warehouse: a group warehouse holds no stock and cannot use storage locations')
|
|
326
|
+
customer = merged.get('consignment_customer') or None
|
|
327
|
+
if customer and flt(merged.get('is_group')):
|
|
328
|
+
raise ValidationError('Warehouse: a group warehouse holds no stock and cannot be a consignment warehouse')
|
|
329
|
+
if name:
|
|
330
|
+
stored = db.get_value('Warehouse', name, 'consignment_customer') or None
|
|
331
|
+
if stored != customer and db.sql(
|
|
332
|
+
'SELECT 1 FROM "Bin" WHERE warehouse = ? AND actual_qty <> 0 LIMIT 1', [name]):
|
|
333
|
+
raise ValidationError(
|
|
334
|
+
f'Warehouse {name}: the consignment customer cannot be changed while stock lies in it; recall the stock first')
|
|
335
|
+
origin = merged.get('replenishment_warehouse') or None
|
|
336
|
+
if origin:
|
|
337
|
+
if origin == name or db.get_value('Warehouse', origin, 'consignment_customer'):
|
|
338
|
+
raise ValidationError('Warehouse: the replenishment warehouse must be one of your own warehouses')
|
|
325
339
|
if name and not flt(merged.get('use_locations')) and db.sql(
|
|
326
340
|
'SELECT 1 FROM "Stock Balance Detail" WHERE warehouse = ? AND location <> \'\' '
|
|
327
341
|
'AND actual_qty <> 0 LIMIT 1', [name]):
|
|
@@ -387,10 +387,14 @@ def stock_balance(
|
|
|
387
387
|
|
|
388
388
|
|
|
389
389
|
def _stock_detail_where(item_code=None, warehouse=None, batch_no=None, item_prefix=None, expiring_before=None,
|
|
390
|
-
include_empty=False, location=None, item_group=None, expiring_after=None
|
|
390
|
+
include_empty=False, location=None, item_group=None, expiring_after=None,
|
|
391
|
+
consignment_customer=None, consignment=None):
|
|
391
392
|
where, params = [], []
|
|
393
|
+
if consignment is not None:
|
|
394
|
+
where.append("COALESCE(w.consignment_customer, '') " + ("<> ''" if consignment else "= ''"))
|
|
392
395
|
for column, value in (("d.item_code", item_code), ("d.warehouse", warehouse), ("d.batch_no", batch_no),
|
|
393
|
-
("d.location", location), ("i.item_group", item_group)
|
|
396
|
+
("d.location", location), ("i.item_group", item_group),
|
|
397
|
+
("w.consignment_customer", consignment_customer)):
|
|
394
398
|
if value:
|
|
395
399
|
where.append(f"{column} = ?")
|
|
396
400
|
params.append(value)
|
|
@@ -411,6 +415,7 @@ def _stock_detail_where(item_code=None, warehouse=None, batch_no=None, item_pref
|
|
|
411
415
|
_STOCK_DETAIL_FROM = (
|
|
412
416
|
'FROM "Stock Balance Detail" d '
|
|
413
417
|
'LEFT JOIN "Item" i ON i.name = d.item_code '
|
|
418
|
+
'LEFT JOIN "Warehouse" w ON w.name = d.warehouse '
|
|
414
419
|
'LEFT JOIN "Batch" b ON b.item_code = d.item_code AND b.batch_no = d.batch_no ')
|
|
415
420
|
|
|
416
421
|
|
|
@@ -439,16 +444,20 @@ def _batch_stock(db, item_code=None, warehouse=None, batch_no=None, item_prefix=
|
|
|
439
444
|
|
|
440
445
|
|
|
441
446
|
def _stock_detail(db, item_code=None, warehouse=None, location=None, batch_no=None, item_prefix=None,
|
|
442
|
-
item_group=None, expiring_before=None, expiring_after=None, include_empty=False
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
447
|
+
item_group=None, expiring_before=None, expiring_after=None, include_empty=False,
|
|
448
|
+
consignment_customer=None, consignment=None):
|
|
449
|
+
"""Where stock is, in one view: item, warehouse, the customer it lies
|
|
450
|
+
with (consignment), storage location, batch, expiry date and quantity.
|
|
451
|
+
Every stock item appears, with an empty batch_no or location where it has
|
|
452
|
+
none. `consignment_customer` shows one customer's consignment stock;
|
|
453
|
+
`consignment` true / false shows only consignment or only own warehouses."""
|
|
446
454
|
permissions.require_artifact("report", "stock-detail")
|
|
447
455
|
where, params = _stock_detail_where(item_code, warehouse, batch_no, item_prefix, expiring_before,
|
|
448
|
-
include_empty, location, item_group, expiring_after
|
|
456
|
+
include_empty, location, item_group, expiring_after,
|
|
457
|
+
consignment_customer, consignment)
|
|
449
458
|
rows = db.sql(
|
|
450
|
-
'SELECT d.item_code, i.item_name, i.item_group, d.warehouse,
|
|
451
|
-
'd.actual_qty '
|
|
459
|
+
'SELECT d.item_code, i.item_name, i.item_group, d.warehouse, w.consignment_customer, d.location, '
|
|
460
|
+
'd.batch_no, b.expiry_date, d.actual_qty '
|
|
452
461
|
+ _STOCK_DETAIL_FROM
|
|
453
462
|
+ (f"WHERE {' AND '.join(where)} " if where else "")
|
|
454
463
|
+ 'ORDER BY d.item_code, d.warehouse, d.location, b.expiry_date, d.batch_no', params)
|
|
@@ -481,6 +490,50 @@ def stock_availability(
|
|
|
481
490
|
return _stock_availability(get_db(), item_code, warehouse, item_prefix)
|
|
482
491
|
|
|
483
492
|
|
|
493
|
+
def _sales_backlog(db, customer=None, item_code=None, warehouse=None, sales_order=None, item_prefix=None,
|
|
494
|
+
only_deliverable=False):
|
|
495
|
+
"""Open sales order lines: ordered, delivered, returned, billed, open,
|
|
496
|
+
reserved, what can be delivered now, and what is on purchase order with
|
|
497
|
+
its expected date."""
|
|
498
|
+
permissions.require_artifact("report", "sales-backlog")
|
|
499
|
+
permissions.require("Sales Order", "read")
|
|
500
|
+
from lambda_erp.backlog import sales_backlog
|
|
501
|
+
# Purchase orders behind a shortage are shown to those who may read them.
|
|
502
|
+
return {"rows": sales_backlog(customer, item_code, warehouse, sales_order, item_prefix, only_deliverable,
|
|
503
|
+
with_purchase_orders=permissions.can("Purchase Order", "read"))}
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
@router.get("/sales-backlog")
|
|
507
|
+
def sales_backlog_report(
|
|
508
|
+
customer: str | None = None,
|
|
509
|
+
item_code: str | None = None,
|
|
510
|
+
warehouse: str | None = None,
|
|
511
|
+
sales_order: str | None = None,
|
|
512
|
+
item_prefix: str | None = None,
|
|
513
|
+
only_deliverable: bool = False,
|
|
514
|
+
):
|
|
515
|
+
return _sales_backlog(get_db(), customer, item_code, warehouse, sales_order, item_prefix, only_deliverable)
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def _purchase_backlog(db, supplier=None, item_code=None, warehouse=None, overdue_only=False):
|
|
519
|
+
"""Open purchase order lines with the supplier's confirmed date and
|
|
520
|
+
whether they are overdue. Quantities and dates only, no prices."""
|
|
521
|
+
permissions.require_artifact("report", "purchase-backlog")
|
|
522
|
+
permissions.require("Purchase Order", "read")
|
|
523
|
+
from lambda_erp.backlog import purchase_backlog
|
|
524
|
+
return {"rows": purchase_backlog(supplier, item_code, warehouse, overdue_only)}
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
@router.get("/purchase-backlog")
|
|
528
|
+
def purchase_backlog_report(
|
|
529
|
+
supplier: str | None = None,
|
|
530
|
+
item_code: str | None = None,
|
|
531
|
+
warehouse: str | None = None,
|
|
532
|
+
overdue_only: bool = False,
|
|
533
|
+
):
|
|
534
|
+
return _purchase_backlog(get_db(), supplier, item_code, warehouse, overdue_only)
|
|
535
|
+
|
|
536
|
+
|
|
484
537
|
@router.get("/stock-detail")
|
|
485
538
|
def stock_detail(
|
|
486
539
|
item_code: str | None = None,
|
|
@@ -492,9 +545,11 @@ def stock_detail(
|
|
|
492
545
|
expiring_before: str | None = None,
|
|
493
546
|
expiring_after: str | None = None,
|
|
494
547
|
include_empty: bool = False,
|
|
548
|
+
consignment_customer: str | None = None,
|
|
549
|
+
consignment: bool | None = None,
|
|
495
550
|
):
|
|
496
551
|
return _stock_detail(get_db(), item_code, warehouse, location, batch_no, item_prefix, item_group,
|
|
497
|
-
expiring_before, expiring_after, include_empty)
|
|
552
|
+
expiring_before, expiring_after, include_empty, consignment_customer, consignment)
|
|
498
553
|
|
|
499
554
|
|
|
500
555
|
@router.get("/batch-stock")
|
|
@@ -20,7 +20,9 @@ from lambda_erp.accounting.purchase_invoice import PurchaseInvoice, make_purchas
|
|
|
20
20
|
from lambda_erp.accounting.payment_entry import PaymentEntry
|
|
21
21
|
from lambda_erp.accounting.journal_entry import JournalEntry
|
|
22
22
|
from lambda_erp.stock.stock_entry import StockEntry
|
|
23
|
-
from lambda_erp.stock.delivery_note import
|
|
23
|
+
from lambda_erp.stock.delivery_note import (
|
|
24
|
+
DeliveryNote, make_delivery_note, make_delivery_return, make_sales_invoice_from_delivery_note,
|
|
25
|
+
)
|
|
24
26
|
from lambda_erp.stock.purchase_receipt import PurchaseReceipt, make_purchase_receipt, make_purchase_receipt_return
|
|
25
27
|
from lambda_erp.accounting.pos_invoice import POSInvoice
|
|
26
28
|
from lambda_erp.controllers.pricing_rule import PricingRule
|
|
@@ -32,6 +34,7 @@ from lambda_erp.accounting.bank_account import BankAccount
|
|
|
32
34
|
from lambda_erp.assets.asset import Asset
|
|
33
35
|
from lambda_erp.assets.reservation import Reservation
|
|
34
36
|
from lambda_erp.stock.reservation import StockReservation
|
|
37
|
+
from lambda_erp.stock.consignment import ConsignmentWithdrawal
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
# --- Doctype registries ---
|
|
@@ -63,6 +66,8 @@ DOCUMENT_CLASSES = {
|
|
|
63
66
|
"Reservation": Reservation,
|
|
64
67
|
# Stock set aside for a sales order line (or with a reason); also status-driven.
|
|
65
68
|
"Stock Reservation": StockReservation,
|
|
69
|
+
# What a customer reported as used from their consignment warehouse.
|
|
70
|
+
"Consignment Withdrawal": ConsignmentWithdrawal,
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
CONVERTERS = {
|
|
@@ -71,6 +76,7 @@ CONVERTERS = {
|
|
|
71
76
|
("Quotation", "Delivery Note"): make_delivery_note_from_quotation,
|
|
72
77
|
("Sales Order", "Sales Invoice"): make_sales_invoice,
|
|
73
78
|
("Sales Order", "Delivery Note"): make_delivery_note,
|
|
79
|
+
("Delivery Note", "Sales Invoice"): make_sales_invoice_from_delivery_note,
|
|
74
80
|
("Purchase Order", "Purchase Invoice"): make_purchase_invoice,
|
|
75
81
|
("Purchase Order", "Purchase Receipt"): make_purchase_receipt,
|
|
76
82
|
# Returns (same-to-same conversion creates a return document)
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Stock actions that are more than a single document save, available over
|
|
2
|
+
REST (/api/actions/...), chat and MCP."""
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
5
|
+
from api import mentions, services
|
|
6
|
+
from lambda_erp import permissions
|
|
7
|
+
from lambda_erp.stock.stock_entry import make_location_move
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MoveLocation(mentions.Input):
|
|
11
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
12
|
+
from_location: str = Field(min_length=1, max_length=200)
|
|
13
|
+
to_location: str | None = Field(default=None, max_length=200)
|
|
14
|
+
to_warehouse: str | None = Field(default=None, max_length=200)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def prepare_location_move(args):
|
|
18
|
+
data = MoveLocation.model_validate(args)
|
|
19
|
+
permissions.require_writable("Stock Entry", "create")
|
|
20
|
+
entry = make_location_move(data.warehouse, data.from_location, data.to_location, data.to_warehouse)
|
|
21
|
+
entry.save()
|
|
22
|
+
return services.load_document("stock-entry", entry.name)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ReserveOrder(mentions.Input):
|
|
26
|
+
sales_order: str = Field(min_length=1, max_length=200)
|
|
27
|
+
sales_order_items: list[str] | None = Field(default=None, max_length=500)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SuggestPicks(mentions.Input):
|
|
31
|
+
item_code: str = Field(min_length=1, max_length=200)
|
|
32
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
33
|
+
qty: float = Field(gt=0)
|
|
34
|
+
customer: str | None = Field(default=None, max_length=200)
|
|
35
|
+
sales_order_item: str | None = Field(default=None, max_length=200)
|
|
36
|
+
include_short_dated: bool = False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def reserve_order(args):
|
|
40
|
+
data = ReserveOrder.model_validate(args)
|
|
41
|
+
permissions.require_readable("Sales Order", data.sales_order)
|
|
42
|
+
permissions.require_writable("Stock Reservation", "create")
|
|
43
|
+
from lambda_erp.stock.reservation import reserve_sales_order
|
|
44
|
+
return reserve_sales_order(data.sales_order, data.sales_order_items)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def suggest(args):
|
|
48
|
+
data = SuggestPicks.model_validate(args)
|
|
49
|
+
permissions.require("Stock Reservation", "read")
|
|
50
|
+
from lambda_erp.stock.reservation import suggest_picks
|
|
51
|
+
return suggest_picks(data.item_code, data.warehouse, data.qty, customer=data.customer,
|
|
52
|
+
sales_order_item=data.sales_order_item, include_short_dated=data.include_short_dated)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ConsignmentLine(mentions.Input):
|
|
56
|
+
item_code: str = Field(min_length=1, max_length=200)
|
|
57
|
+
qty: float | None = Field(default=None, gt=0)
|
|
58
|
+
batch_no: str | None = Field(default=None, max_length=200)
|
|
59
|
+
location: str | None = Field(default=None, max_length=200)
|
|
60
|
+
rate: float | None = Field(default=None, ge=0)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class RecordWithdrawal(mentions.Input):
|
|
64
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
65
|
+
items: list[ConsignmentLine] = Field(min_length=1, max_length=500)
|
|
66
|
+
external_source: str | None = Field(default=None, max_length=200)
|
|
67
|
+
external_reference: str | None = Field(default=None, max_length=200)
|
|
68
|
+
posting_date: str | None = Field(default=None, max_length=10)
|
|
69
|
+
replenish: bool = False
|
|
70
|
+
replenish_from_warehouse: str | None = Field(default=None, max_length=200)
|
|
71
|
+
remarks: str | None = Field(default=None, max_length=2000)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class PrepareStocking(mentions.Input):
|
|
75
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
76
|
+
items: list[ConsignmentLine] = Field(min_length=1, max_length=500)
|
|
77
|
+
from_warehouse: str | None = Field(default=None, max_length=200)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class PrepareRecall(mentions.Input):
|
|
81
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
82
|
+
to_warehouse: str = Field(min_length=1, max_length=200)
|
|
83
|
+
to_location: str | None = Field(default=None, max_length=200)
|
|
84
|
+
items: list[ConsignmentLine] | None = Field(default=None, max_length=500)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def record_consignment_withdrawal(args):
|
|
88
|
+
data = RecordWithdrawal.model_validate(args)
|
|
89
|
+
permissions.require_writable("Consignment Withdrawal", "create")
|
|
90
|
+
permissions.require("Consignment Withdrawal", "submit")
|
|
91
|
+
permissions.require_writable("Sales Invoice", "create")
|
|
92
|
+
from lambda_erp.stock.consignment import record_withdrawal
|
|
93
|
+
for line in data.items:
|
|
94
|
+
if line.qty is None:
|
|
95
|
+
raise ValueError("Every withdrawal line needs a qty")
|
|
96
|
+
return record_withdrawal(
|
|
97
|
+
data.warehouse, [line.model_dump(exclude_none=True) for line in data.items],
|
|
98
|
+
external_source=data.external_source, external_reference=data.external_reference,
|
|
99
|
+
posting_date=data.posting_date, replenish=data.replenish,
|
|
100
|
+
replenish_from_warehouse=data.replenish_from_warehouse, remarks=data.remarks)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def prepare_consignment_stocking(args):
|
|
104
|
+
data = PrepareStocking.model_validate(args)
|
|
105
|
+
permissions.require_writable("Stock Entry", "create")
|
|
106
|
+
from lambda_erp.stock.consignment import make_consignment_stocking
|
|
107
|
+
entry = make_consignment_stocking(
|
|
108
|
+
data.warehouse, [line.model_dump(exclude_none=True) for line in data.items], from_warehouse=data.from_warehouse)
|
|
109
|
+
entry.save()
|
|
110
|
+
return services.load_document("stock-entry", entry.name)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def prepare_consignment_recall(args):
|
|
114
|
+
data = PrepareRecall.model_validate(args)
|
|
115
|
+
permissions.require_writable("Stock Entry", "create")
|
|
116
|
+
from lambda_erp.stock.consignment import make_consignment_recall
|
|
117
|
+
entry = make_consignment_recall(
|
|
118
|
+
data.warehouse, data.to_warehouse, to_location=data.to_location,
|
|
119
|
+
items=[line.model_dump(exclude_none=True) for line in data.items] if data.items else None)
|
|
120
|
+
entry.save()
|
|
121
|
+
return services.load_document("stock-entry", entry.name)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class ConfirmPurchaseOrder(mentions.Input):
|
|
125
|
+
purchase_order: str = Field(min_length=1, max_length=200)
|
|
126
|
+
confirmed_date: str = Field(min_length=8, max_length=10)
|
|
127
|
+
lines: list[str] | None = Field(default=None, max_length=500)
|
|
128
|
+
confirmed_qty: float | None = Field(default=None, gt=0)
|
|
129
|
+
confirmation_reference: str | None = Field(default=None, max_length=200)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def confirm_purchase_order(args, user=None):
|
|
133
|
+
data = ConfirmPurchaseOrder.model_validate(args)
|
|
134
|
+
permissions.require_readable("Purchase Order", data.purchase_order)
|
|
135
|
+
permissions.require("Purchase Order", "update")
|
|
136
|
+
from lambda_erp.backlog import confirm_purchase_order_lines
|
|
137
|
+
return confirm_purchase_order_lines(
|
|
138
|
+
data.purchase_order, data.confirmed_date, lines=data.lines, confirmed_qty=data.confirmed_qty,
|
|
139
|
+
confirmation_reference=data.confirmation_reference,
|
|
140
|
+
confirmed_by=(user or {}).get("user_id") or (user or {}).get("name"))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def initialize_stock_actions():
|
|
144
|
+
services.register_action(
|
|
145
|
+
"record_consignment_withdrawal", record_consignment_withdrawal,
|
|
146
|
+
description=(
|
|
147
|
+
"Record what a customer reported as USED from their consignment warehouse and bill it: creates and "
|
|
148
|
+
"submits a Consignment Withdrawal and ONE Sales Invoice that also takes the goods out of that warehouse. "
|
|
149
|
+
"items: item_code, qty, batch_no as reported (and location if the warehouse uses storage locations). "
|
|
150
|
+
"Give external_source + external_reference (the customer's report / order number) whenever there is one: "
|
|
151
|
+
"the same report sent again then returns the first result (replayed=true) instead of billing twice, and "
|
|
152
|
+
"the same number with different content is refused. replenish=true also drafts a replacement stocking."),
|
|
153
|
+
parameters=RecordWithdrawal.model_json_schema(), minimum_role="manager")
|
|
154
|
+
services.register_action(
|
|
155
|
+
"prepare_consignment_stocking", prepare_consignment_stocking,
|
|
156
|
+
description=(
|
|
157
|
+
"Draft the stocking of a customer's consignment warehouse: a DRAFT Stock Entry (Material Transfer) from "
|
|
158
|
+
"from_warehouse (default: the warehouse's replenishment_warehouse) with batches proposed first-expired-"
|
|
159
|
+
"first-out. No sale and no invoice. Nothing moves until the draft is submitted."),
|
|
160
|
+
parameters=PrepareStocking.model_json_schema(), minimum_role="manager")
|
|
161
|
+
services.register_action(
|
|
162
|
+
"prepare_consignment_recall", prepare_consignment_recall,
|
|
163
|
+
description=(
|
|
164
|
+
"Draft bringing goods back from a customer's consignment warehouse to one of your own (to_warehouse): "
|
|
165
|
+
"everything in it, or the given items / batches. A DRAFT Stock Entry; no credit note, the goods were "
|
|
166
|
+
"never sold. Nothing moves until the draft is submitted."),
|
|
167
|
+
parameters=PrepareRecall.model_json_schema(), minimum_role="manager")
|
|
168
|
+
services.register_action(
|
|
169
|
+
"confirm_purchase_order", confirm_purchase_order,
|
|
170
|
+
description=(
|
|
171
|
+
"Record the supplier's confirmed delivery date on a SUBMITTED purchase order: on all open lines, or on "
|
|
172
|
+
"`lines` (row names or positions). Optional confirmation_reference (the supplier's confirmation number) "
|
|
173
|
+
"and, for one line, confirmed_qty. Use it when an order confirmation arrives; the date then shows in the "
|
|
174
|
+
"sales-backlog and purchase-backlog reports. Only assign a confirmation to an order when the order number "
|
|
175
|
+
"is stated or the user confirms which order it belongs to."),
|
|
176
|
+
parameters=ConfirmPurchaseOrder.model_json_schema(), minimum_role="manager", pass_user=True)
|
|
177
|
+
services.register_action(
|
|
178
|
+
"reserve_sales_order", reserve_order,
|
|
179
|
+
description=(
|
|
180
|
+
"Reserve stock for the undelivered part of a submitted sales order (all stock lines, or only "
|
|
181
|
+
"sales_order_items). Reserves as much as is available per line and reports short_qty for the rest. "
|
|
182
|
+
"Reserved stock cannot be delivered, issued or transferred away for anyone else. To give stock back, "
|
|
183
|
+
"update the Stock Reservation's status to Released."),
|
|
184
|
+
parameters=ReserveOrder.model_json_schema(), minimum_role="manager")
|
|
185
|
+
services.register_action(
|
|
186
|
+
"suggest_picks", suggest,
|
|
187
|
+
description=(
|
|
188
|
+
"READ-ONLY picking proposal, first expired first out: which batches and storage locations to take a "
|
|
189
|
+
"quantity of an item from in a warehouse. Never proposes blocked or expired batches or stock reserved "
|
|
190
|
+
"for other orders; batches with too little shelf life left are listed under excluded unless "
|
|
191
|
+
"include_short_dated. Changes nothing: no reservation, no stock movement, no invoice."),
|
|
192
|
+
parameters=SuggestPicks.model_json_schema(), minimum_role="viewer")
|
|
193
|
+
services.register_action(
|
|
194
|
+
"prepare_location_move", prepare_location_move,
|
|
195
|
+
description=(
|
|
196
|
+
"Prepare moving EVERYTHING that lies in one storage location to another location "
|
|
197
|
+
"(same warehouse, or to_warehouse): creates a DRAFT Stock Entry (Material Transfer) with one row "
|
|
198
|
+
"per item and batch found there. Nothing moves until that draft is submitted with submit_document; "
|
|
199
|
+
"show the rows to the user first. For single items create a Material Transfer directly."),
|
|
200
|
+
parameters=MoveLocation.model_json_schema(), minimum_role="manager")
|
|
@@ -568,6 +568,12 @@ export const api = {
|
|
|
568
568
|
batchStock: (params?: Record<string, string>) =>
|
|
569
569
|
request<{ rows: any[] }>(`/reports/batch-stock${qs(params)}`),
|
|
570
570
|
|
|
571
|
+
salesBacklog: (params?: Record<string, string>) =>
|
|
572
|
+
request<{ rows: any[] }>(`/reports/sales-backlog${qs(params)}`),
|
|
573
|
+
|
|
574
|
+
purchaseBacklog: (params?: Record<string, string>) =>
|
|
575
|
+
request<{ rows: any[] }>(`/reports/purchase-backlog${qs(params)}`),
|
|
576
|
+
|
|
571
577
|
stockAvailability: (params?: Record<string, string>) =>
|
|
572
578
|
request<{ rows: any[] }>(`/reports/stock-availability${qs(params)}`),
|
|
573
579
|
|
|
@@ -174,6 +174,8 @@ class POSInvoice(Document):
|
|
|
174
174
|
if flt(self._data.get("update_stock")):
|
|
175
175
|
from lambda_erp.stock.reservation import validate_sellable
|
|
176
176
|
validate_sellable(self)
|
|
177
|
+
from lambda_erp.stock.consignment import validate_consignment_sale
|
|
178
|
+
validate_consignment_sale(self)
|
|
177
179
|
sl_entries = self._get_sl_entries()
|
|
178
180
|
if sl_entries:
|
|
179
181
|
make_sl_entries(sl_entries)
|
|
@@ -296,6 +296,8 @@ class SalesInvoice(Document):
|
|
|
296
296
|
if flt(self.get("update_stock")):
|
|
297
297
|
from lambda_erp.stock.reservation import validate_sellable
|
|
298
298
|
validate_sellable(self)
|
|
299
|
+
from lambda_erp.stock.consignment import validate_consignment_sale
|
|
300
|
+
validate_consignment_sale(self)
|
|
299
301
|
sl_entries = self._get_stock_sl_entries()
|
|
300
302
|
if sl_entries:
|
|
301
303
|
make_sl_entries(sl_entries)
|