lambda-erp 1.4.10__tar.gz → 1.4.12__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.10 → lambda_erp-1.4.12}/PKG-INFO +1 -1
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/chat.py +34 -3
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/errors.py +5 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf_contract.py +6 -2
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf_profiles.py +9 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/masters.py +19 -1
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/reports.py +114 -10
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/services.py +6 -0
- lambda_erp-1.4.12/api/stock_actions.py +231 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/frontend/src/api/client.ts +6 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/pos_invoice.py +2 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/sales_invoice.py +2 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/database.py +121 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/exceptions.py +4 -0
- lambda_erp-1.4.12/lambda_erp/stock/consignment.py +378 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/stock/delivery_note.py +2 -0
- lambda_erp-1.4.12/lambda_erp/stock/stock_count.py +252 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/stock/stock_entry.py +12 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/stock/stock_ledger.py +39 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/workflow.py +6 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/pyproject.toml +1 -1
- lambda_erp-1.4.10/api/stock_actions.py +0 -107
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/.gitignore +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/LICENSE +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/README.md +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/attachments.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/auth.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/chat_links.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/deps.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/erp_context.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/list_values.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/main.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/mentions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/oauth.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/providers.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/record_notes.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/document.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/record.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/time_filters.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/api/write_context.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/frontend/README.md +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.12}/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", "sales-backlog", "purchase-backlog", "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", "batch-recipients", "batch-changes", "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"],
|
|
@@ -1988,10 +1988,22 @@ def _handle_get_report(args):
|
|
|
1988
1988
|
return _stock_availability(db, filters.get("item_code"), filters.get("warehouse"), filters.get("item_prefix"))
|
|
1989
1989
|
elif report_type == "stock-detail":
|
|
1990
1990
|
from api.routers.reports import _stock_detail
|
|
1991
|
+
consignment = filters.get("consignment")
|
|
1991
1992
|
return _stock_detail(db, filters.get("item_code"), filters.get("warehouse"), filters.get("location"),
|
|
1992
1993
|
filters.get("batch_no"), filters.get("item_prefix"), filters.get("item_group"),
|
|
1993
1994
|
filters.get("expiring_before"), filters.get("expiring_after"),
|
|
1994
|
-
bool(filters.get("include_empty")))
|
|
1995
|
+
bool(filters.get("include_empty")), filters.get("consignment_customer"),
|
|
1996
|
+
None if consignment is None else bool(consignment))
|
|
1997
|
+
elif report_type == "batch-recipients":
|
|
1998
|
+
from api.routers.reports import _batch_recipients
|
|
1999
|
+
if not filters.get("batch_no"):
|
|
2000
|
+
return {"error": "batch-recipients needs filters.batch_no"}
|
|
2001
|
+
return _batch_recipients(db, filters.get("batch_no"), filters.get("item_code"))
|
|
2002
|
+
elif report_type == "batch-changes":
|
|
2003
|
+
from api.routers.reports import _batch_changes
|
|
2004
|
+
if not filters.get("batch_no") and not filters.get("item_code"):
|
|
2005
|
+
return {"error": "batch-changes needs filters.batch_no or filters.item_code"}
|
|
2006
|
+
return _batch_changes(db, filters.get("batch_no"), filters.get("item_code"))
|
|
1995
2007
|
elif report_type == "batch-movements":
|
|
1996
2008
|
from api.routers.reports import _batch_movements
|
|
1997
2009
|
if not filters.get("batch_no"):
|
|
@@ -2927,6 +2939,23 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2927
2939
|
- **Material Transfer:** Moves stock between warehouses. No GL impact.
|
|
2928
2940
|
- **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.
|
|
2929
2941
|
|
|
2942
|
+
### Stock counts (inventory)
|
|
2943
|
+
- A **Stock Count** (doctype `stock-count`) covers one warehouse. Create the draft with the `prepare_stock_count` action; it lists system_qty per item, batch and storage location. Enter `counted_qty` on the lines that were counted (leave it empty on lines that were not) with update_document; add a line for stock the system does not list.
|
|
2944
|
+
- Saving a draft changes NO stock. Submitting posts counted_qty − system_qty per line and requires `reason`. If stock moved since the count was prepared, submitting is refused: refresh with prepare_stock_count(stock_count=…) and have the lines checked again.
|
|
2945
|
+
- When someone tells you what they counted, put it on the draft and report the differences (difference_qty). Do not submit a count unless the user explicitly asks to post it and may do so.
|
|
2946
|
+
- A count corrects quantities from now on. It never changes earlier delivery notes or invoices; do not use it to record where goods are believed to have gone.
|
|
2947
|
+
- Use a Stock Count, not Material Receipt / Issue, when the reason is "what is there differs from what the system says".
|
|
2948
|
+
|
|
2949
|
+
### Consignment (own stock lying at a customer)
|
|
2950
|
+
- 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.
|
|
2951
|
+
- **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.
|
|
2952
|
+
- **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).
|
|
2953
|
+
- **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.
|
|
2954
|
+
- **Recall** (taking goods back) is a transfer, not a credit note: `prepare_consignment_recall` (warehouse, to_warehouse, optional items).
|
|
2955
|
+
- Goods in a consignment warehouse can only be sold to its customer. To give them to someone else, recall them first.
|
|
2956
|
+
- 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.
|
|
2957
|
+
- If it is unclear whether an incoming order is a stocking request, a withdrawal or a normal order, ask.
|
|
2958
|
+
|
|
2930
2959
|
### Partial deliveries, backorders and invoicing after delivery
|
|
2931
2960
|
- 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.
|
|
2932
2961
|
- 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.
|
|
@@ -3022,8 +3051,10 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3022
3051
|
- **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.
|
|
3023
3052
|
- **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".
|
|
3024
3053
|
- **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".
|
|
3025
|
-
- **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".
|
|
3054
|
+
- **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".
|
|
3026
3055
|
- **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.
|
|
3056
|
+
- **batch-recipients** — Who has a batch (recall): one row per customer with delivered_qty, returned_qty, net_qty and the documents; `in_stock` says where the rest lies now (with the customer for consignment stock); `suppliers` where it came from. Filters: batch_no (required), item_code. Use this for "who received lot X" instead of adding up movements yourself.
|
|
3057
|
+
- **batch-changes** — Recorded changes of a batch's expiry date and block (old value, new value, who, when). Filters: batch_no and/or item_code.
|
|
3027
3058
|
- **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.
|
|
3028
3059
|
- **dashboard-summary** — KPI overview (revenue, receivables, payables, stock value).
|
|
3029
3060
|
- **Custom analytics drafts** — reserved for when the user **explicitly asks
|
|
@@ -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)})
|
|
@@ -190,13 +190,17 @@ def prepare(doctype, doc):
|
|
|
190
190
|
number(row[key], f'{table.key}[{i}].{key}')
|
|
191
191
|
if table.key in {'items', 'plans'}:
|
|
192
192
|
_item(row, tokens, i)
|
|
193
|
-
|
|
193
|
+
# A count sheet has an expected and a counted quantity (which
|
|
194
|
+
# may be empty or zero), not a line quantity.
|
|
195
|
+
if doctype != 'Stock Count':
|
|
196
|
+
_quantity(row, f'{table.key}[{i}].qty', bool(doc.get('is_return')))
|
|
194
197
|
if doctype in {'Delivery Note', 'Purchase Receipt'}:
|
|
195
198
|
if row.get('item_code') and get_db().get_value('Item', row['item_code'], 'is_stock_item'):
|
|
196
199
|
require(row, ('warehouse',), f'{table.key}[{i}].')
|
|
197
200
|
if doctype == 'Stock Entry':
|
|
198
201
|
movement = doc['stock_entry_type']
|
|
199
|
-
if movement not in {'Material Receipt', 'Opening Stock', 'Material Issue', 'Material Transfer'
|
|
202
|
+
if movement not in {'Material Receipt', 'Opening Stock', 'Material Issue', 'Material Transfer',
|
|
203
|
+
'Batch Assignment'}:
|
|
200
204
|
raise PDFError('PDF requires a supported stock_entry_type')
|
|
201
205
|
keys = ('s_warehouse', 't_warehouse') if movement == 'Material Transfer' else ('s_warehouse',) if movement == 'Material Issue' else ('t_warehouse',)
|
|
202
206
|
require(row, keys, f'items[{i}].')
|
|
@@ -82,6 +82,15 @@ 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
|
+
'Stock Count': PDFProfile('record', 'Stock count sheet',
|
|
86
|
+
fields=('company', 'warehouse', 'posting_date', 'reason', 'remarks'),
|
|
87
|
+
required=('warehouse', 'posting_date', 'items'),
|
|
88
|
+
tables=(PDFTable('items', ('location', 'item_code', 'item_name', 'batch_no', 'expiry_date', 'system_qty', 'counted_qty'),
|
|
89
|
+
('item_code',), True),)),
|
|
90
|
+
'Consignment Withdrawal': PDFProfile('record', 'Consignment withdrawal',
|
|
91
|
+
fields=('company', 'customer', 'warehouse', 'posting_date', 'external_reference', 'sales_invoice', 'remarks'),
|
|
92
|
+
required=('customer', 'warehouse', 'posting_date', 'items'),
|
|
93
|
+
tables=(PDFTable('items', ('item_code', 'item_name', 'qty', 'uom', 'batch_no'), ('item_code', 'qty'), True),)),
|
|
85
94
|
'Stock Reservation': PDFProfile('record', 'Stock reservation overview',
|
|
86
95
|
fields=('item_code', 'warehouse', 'reserved_qty', 'sales_order', 'customer', 'status', 'remarks', 'reserved_by', 'company'),
|
|
87
96
|
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]):
|
|
@@ -495,6 +509,10 @@ def _update_master_record(master_type: str, name: str, data: dict) -> dict:
|
|
|
495
509
|
update_fields["modified"] = now()
|
|
496
510
|
if update_fields:
|
|
497
511
|
db.set_value(doctype, name, update_fields)
|
|
512
|
+
if master_type == 'batch':
|
|
513
|
+
# A batch's expiry date and block decide what may be sold: keep the trail.
|
|
514
|
+
from lambda_erp.stock.stock_ledger import log_batch_changes
|
|
515
|
+
log_batch_changes(name, stored, update_fields, 'Batch master')
|
|
498
516
|
|
|
499
517
|
rows = db.get_all(doctype, filters={"name": name}, fields=["*"])
|
|
500
518
|
if not rows:
|
|
@@ -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)
|
|
@@ -536,9 +545,11 @@ def stock_detail(
|
|
|
536
545
|
expiring_before: str | None = None,
|
|
537
546
|
expiring_after: str | None = None,
|
|
538
547
|
include_empty: bool = False,
|
|
548
|
+
consignment_customer: str | None = None,
|
|
549
|
+
consignment: bool | None = None,
|
|
539
550
|
):
|
|
540
551
|
return _stock_detail(get_db(), item_code, warehouse, location, batch_no, item_prefix, item_group,
|
|
541
|
-
expiring_before, expiring_after, include_empty)
|
|
552
|
+
expiring_before, expiring_after, include_empty, consignment_customer, consignment)
|
|
542
553
|
|
|
543
554
|
|
|
544
555
|
@router.get("/batch-stock")
|
|
@@ -591,6 +602,99 @@ def _batch_movements(db, batch_no=None, item_code=None, warehouse=None):
|
|
|
591
602
|
return {"rows": result}
|
|
592
603
|
|
|
593
604
|
|
|
605
|
+
def _batch_recipients(db, batch_no=None, item_code=None):
|
|
606
|
+
"""Who has a batch: one row per customer it was delivered to (delivered,
|
|
607
|
+
returned and what they still have of it), where the rest lies now
|
|
608
|
+
(`in_stock`, with the customer for consignment stock) and which suppliers
|
|
609
|
+
it came from (`suppliers`). The first thing a recall needs."""
|
|
610
|
+
permissions.require_artifact("report", "batch-recipients")
|
|
611
|
+
if not batch_no:
|
|
612
|
+
raise HTTPException(status_code=422, detail="batch_no is required")
|
|
613
|
+
where, params = ["s.batch_no = ?"], [batch_no]
|
|
614
|
+
if item_code:
|
|
615
|
+
where.append("s.item_code = ?")
|
|
616
|
+
params.append(item_code)
|
|
617
|
+
rows = db.sql(
|
|
618
|
+
'SELECT s.item_code, s.posting_date, s.actual_qty, s.voucher_type, s.voucher_no '
|
|
619
|
+
f'FROM "Stock Ledger Entry" s WHERE {" AND ".join(where)} ORDER BY s.posting_date, s.creation, s.name', params)
|
|
620
|
+
parties, recipients, suppliers = {}, {}, {}
|
|
621
|
+
for row in rows:
|
|
622
|
+
field = _BATCH_PARTY.get(row["voucher_type"])
|
|
623
|
+
if not field:
|
|
624
|
+
continue
|
|
625
|
+
key = (row["voucher_type"], row["voucher_no"])
|
|
626
|
+
if key not in parties:
|
|
627
|
+
parties[key] = db.get_value(row["voucher_type"], row["voucher_no"], field[0])
|
|
628
|
+
party, qty = parties[key], flt(row["actual_qty"])
|
|
629
|
+
if not party:
|
|
630
|
+
continue
|
|
631
|
+
target = recipients if field[1] == "Customer" else suppliers
|
|
632
|
+
entry = target.setdefault((row["item_code"], party), {
|
|
633
|
+
"item_code": row["item_code"], field[0]: party, "out_qty": 0.0, "in_qty": 0.0,
|
|
634
|
+
"first_date": row["posting_date"], "last_date": row["posting_date"], "documents": []})
|
|
635
|
+
if qty < 0:
|
|
636
|
+
entry["out_qty"] += -qty
|
|
637
|
+
else:
|
|
638
|
+
entry["in_qty"] += qty
|
|
639
|
+
entry["last_date"] = row["posting_date"]
|
|
640
|
+
if row["voucher_no"] not in entry["documents"]:
|
|
641
|
+
entry["documents"].append(row["voucher_no"])
|
|
642
|
+
|
|
643
|
+
def named(table, field, party):
|
|
644
|
+
return db.get_value(table, party, field) or party
|
|
645
|
+
|
|
646
|
+
delivered = [{
|
|
647
|
+
"item_code": e["item_code"], "customer": e["customer"],
|
|
648
|
+
"customer_name": named("Customer", "customer_name", e["customer"]),
|
|
649
|
+
"delivered_qty": e["out_qty"], "returned_qty": e["in_qty"], "net_qty": e["out_qty"] - e["in_qty"],
|
|
650
|
+
"first_date": e["first_date"], "last_date": e["last_date"], "documents": e["documents"]}
|
|
651
|
+
for e in recipients.values()]
|
|
652
|
+
delivered.sort(key=lambda r: (r["item_code"], -r["net_qty"], r["customer"]))
|
|
653
|
+
result = {"rows": delivered}
|
|
654
|
+
stock_where, stock_params = ["d.batch_no = ?", "d.actual_qty <> 0"], [batch_no]
|
|
655
|
+
if item_code:
|
|
656
|
+
stock_where.append("d.item_code = ?")
|
|
657
|
+
stock_params.append(item_code)
|
|
658
|
+
result["in_stock"] = [{**dict(r), "actual_qty": flt(r["actual_qty"])} for r in db.sql(
|
|
659
|
+
'SELECT d.item_code, d.warehouse, w.consignment_customer, d.location, d.actual_qty '
|
|
660
|
+
'FROM "Stock Balance Detail" d LEFT JOIN "Warehouse" w ON w.name = d.warehouse '
|
|
661
|
+
f'WHERE {" AND ".join(stock_where)} ORDER BY d.item_code, d.warehouse, d.location', stock_params)]
|
|
662
|
+
if permissions.can("Supplier", "read"):
|
|
663
|
+
result["suppliers"] = [{
|
|
664
|
+
"item_code": e["item_code"], "supplier": e["supplier"],
|
|
665
|
+
"supplier_name": named("Supplier", "supplier_name", e["supplier"]),
|
|
666
|
+
"received_qty": e["in_qty"], "returned_qty": e["out_qty"], "documents": e["documents"]}
|
|
667
|
+
for e in suppliers.values()]
|
|
668
|
+
return result
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
@router.get("/batch-recipients")
|
|
672
|
+
def batch_recipients(batch_no: str, item_code: str | None = None):
|
|
673
|
+
return _batch_recipients(get_db(), batch_no, item_code)
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
def _batch_changes(db, batch_no=None, item_code=None):
|
|
677
|
+
"""The recorded changes of a batch's expiry date and block: what it was,
|
|
678
|
+
what it became, who changed it and when."""
|
|
679
|
+
permissions.require_artifact("report", "batch-changes")
|
|
680
|
+
where, params = [], []
|
|
681
|
+
for column, value in (("batch_no", batch_no), ("item_code", item_code)):
|
|
682
|
+
if value:
|
|
683
|
+
where.append(f"{column} = ?")
|
|
684
|
+
params.append(value)
|
|
685
|
+
if not where:
|
|
686
|
+
raise HTTPException(status_code=422, detail="batch_no or item_code is required")
|
|
687
|
+
rows = db.sql(
|
|
688
|
+
'SELECT batch, item_code, batch_no, field, old_value, new_value, changed_by, changed_at, source '
|
|
689
|
+
f'FROM "Batch Change" WHERE {" AND ".join(where)} ORDER BY changed_at, name', params)
|
|
690
|
+
return {"rows": [dict(row) for row in rows]}
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
@router.get("/batch-changes")
|
|
694
|
+
def batch_changes(batch_no: str | None = None, item_code: str | None = None):
|
|
695
|
+
return _batch_changes(get_db(), batch_no, item_code)
|
|
696
|
+
|
|
697
|
+
|
|
594
698
|
@router.get("/batch-movements")
|
|
595
699
|
def batch_movements(
|
|
596
700
|
batch_no: str,
|
|
@@ -34,6 +34,8 @@ from lambda_erp.accounting.bank_account import BankAccount
|
|
|
34
34
|
from lambda_erp.assets.asset import Asset
|
|
35
35
|
from lambda_erp.assets.reservation import Reservation
|
|
36
36
|
from lambda_erp.stock.reservation import StockReservation
|
|
37
|
+
from lambda_erp.stock.consignment import ConsignmentWithdrawal
|
|
38
|
+
from lambda_erp.stock.stock_count import StockCount
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
# --- Doctype registries ---
|
|
@@ -65,6 +67,10 @@ DOCUMENT_CLASSES = {
|
|
|
65
67
|
"Reservation": Reservation,
|
|
66
68
|
# Stock set aside for a sales order line (or with a reason); also status-driven.
|
|
67
69
|
"Stock Reservation": StockReservation,
|
|
70
|
+
# What a customer reported as used from their consignment warehouse.
|
|
71
|
+
"Consignment Withdrawal": ConsignmentWithdrawal,
|
|
72
|
+
# Counted quantities; submitting books the differences with a reason.
|
|
73
|
+
"Stock Count": StockCount,
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
CONVERTERS = {
|
|
@@ -0,0 +1,231 @@
|
|
|
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 PrepareCount(mentions.Input):
|
|
56
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
57
|
+
location: str | None = Field(default=None, max_length=200)
|
|
58
|
+
item_code: str | None = Field(default=None, max_length=200)
|
|
59
|
+
item_prefix: str | None = Field(default=None, max_length=200)
|
|
60
|
+
stock_count: str | None = Field(default=None, max_length=200)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def prepare_count(args):
|
|
64
|
+
data = PrepareCount.model_validate(args)
|
|
65
|
+
from lambda_erp.stock.stock_count import prepare_stock_count
|
|
66
|
+
if data.stock_count:
|
|
67
|
+
permissions.require_writable("Stock Count", "update")
|
|
68
|
+
permissions.require_readable("Stock Count", data.stock_count)
|
|
69
|
+
else:
|
|
70
|
+
permissions.require_writable("Stock Count", "create")
|
|
71
|
+
doc = prepare_stock_count(data.warehouse, location=data.location, item_code=data.item_code,
|
|
72
|
+
item_prefix=data.item_prefix, stock_count=data.stock_count)
|
|
73
|
+
doc.save()
|
|
74
|
+
return services.load_document("stock-count", doc.name)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class ConsignmentLine(mentions.Input):
|
|
78
|
+
item_code: str = Field(min_length=1, max_length=200)
|
|
79
|
+
qty: float | None = Field(default=None, gt=0)
|
|
80
|
+
batch_no: str | None = Field(default=None, max_length=200)
|
|
81
|
+
location: str | None = Field(default=None, max_length=200)
|
|
82
|
+
rate: float | None = Field(default=None, ge=0)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class RecordWithdrawal(mentions.Input):
|
|
86
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
87
|
+
items: list[ConsignmentLine] = Field(min_length=1, max_length=500)
|
|
88
|
+
external_source: str | None = Field(default=None, max_length=200)
|
|
89
|
+
external_reference: str | None = Field(default=None, max_length=200)
|
|
90
|
+
posting_date: str | None = Field(default=None, max_length=10)
|
|
91
|
+
replenish: bool = False
|
|
92
|
+
replenish_from_warehouse: str | None = Field(default=None, max_length=200)
|
|
93
|
+
remarks: str | None = Field(default=None, max_length=2000)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PrepareStocking(mentions.Input):
|
|
97
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
98
|
+
items: list[ConsignmentLine] = Field(min_length=1, max_length=500)
|
|
99
|
+
from_warehouse: str | None = Field(default=None, max_length=200)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class PrepareRecall(mentions.Input):
|
|
103
|
+
warehouse: str = Field(min_length=1, max_length=200)
|
|
104
|
+
to_warehouse: str = Field(min_length=1, max_length=200)
|
|
105
|
+
to_location: str | None = Field(default=None, max_length=200)
|
|
106
|
+
items: list[ConsignmentLine] | None = Field(default=None, max_length=500)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def record_consignment_withdrawal(args):
|
|
110
|
+
data = RecordWithdrawal.model_validate(args)
|
|
111
|
+
permissions.require_writable("Consignment Withdrawal", "create")
|
|
112
|
+
permissions.require("Consignment Withdrawal", "submit")
|
|
113
|
+
permissions.require_writable("Sales Invoice", "create")
|
|
114
|
+
from lambda_erp.stock.consignment import record_withdrawal
|
|
115
|
+
for line in data.items:
|
|
116
|
+
if line.qty is None:
|
|
117
|
+
raise ValueError("Every withdrawal line needs a qty")
|
|
118
|
+
return record_withdrawal(
|
|
119
|
+
data.warehouse, [line.model_dump(exclude_none=True) for line in data.items],
|
|
120
|
+
external_source=data.external_source, external_reference=data.external_reference,
|
|
121
|
+
posting_date=data.posting_date, replenish=data.replenish,
|
|
122
|
+
replenish_from_warehouse=data.replenish_from_warehouse, remarks=data.remarks)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def prepare_consignment_stocking(args):
|
|
126
|
+
data = PrepareStocking.model_validate(args)
|
|
127
|
+
permissions.require_writable("Stock Entry", "create")
|
|
128
|
+
from lambda_erp.stock.consignment import make_consignment_stocking
|
|
129
|
+
entry = make_consignment_stocking(
|
|
130
|
+
data.warehouse, [line.model_dump(exclude_none=True) for line in data.items], from_warehouse=data.from_warehouse)
|
|
131
|
+
entry.save()
|
|
132
|
+
return services.load_document("stock-entry", entry.name)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def prepare_consignment_recall(args):
|
|
136
|
+
data = PrepareRecall.model_validate(args)
|
|
137
|
+
permissions.require_writable("Stock Entry", "create")
|
|
138
|
+
from lambda_erp.stock.consignment import make_consignment_recall
|
|
139
|
+
entry = make_consignment_recall(
|
|
140
|
+
data.warehouse, data.to_warehouse, to_location=data.to_location,
|
|
141
|
+
items=[line.model_dump(exclude_none=True) for line in data.items] if data.items else None)
|
|
142
|
+
entry.save()
|
|
143
|
+
return services.load_document("stock-entry", entry.name)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class ConfirmPurchaseOrder(mentions.Input):
|
|
147
|
+
purchase_order: str = Field(min_length=1, max_length=200)
|
|
148
|
+
confirmed_date: str = Field(min_length=8, max_length=10)
|
|
149
|
+
lines: list[str] | None = Field(default=None, max_length=500)
|
|
150
|
+
confirmed_qty: float | None = Field(default=None, gt=0)
|
|
151
|
+
confirmation_reference: str | None = Field(default=None, max_length=200)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def confirm_purchase_order(args, user=None):
|
|
155
|
+
data = ConfirmPurchaseOrder.model_validate(args)
|
|
156
|
+
permissions.require_readable("Purchase Order", data.purchase_order)
|
|
157
|
+
permissions.require("Purchase Order", "update")
|
|
158
|
+
from lambda_erp.backlog import confirm_purchase_order_lines
|
|
159
|
+
return confirm_purchase_order_lines(
|
|
160
|
+
data.purchase_order, data.confirmed_date, lines=data.lines, confirmed_qty=data.confirmed_qty,
|
|
161
|
+
confirmation_reference=data.confirmation_reference,
|
|
162
|
+
confirmed_by=(user or {}).get("user_id") or (user or {}).get("name"))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def initialize_stock_actions():
|
|
166
|
+
services.register_action(
|
|
167
|
+
"prepare_stock_count", prepare_count,
|
|
168
|
+
description=(
|
|
169
|
+
"Create a DRAFT Stock Count for a warehouse (an own one or a customer's consignment warehouse) with one "
|
|
170
|
+
"line per item, batch and storage location and the quantity the system expects (system_qty); optionally "
|
|
171
|
+
"only one location, one item_code or an item_prefix. The counter then enters counted_qty per line with "
|
|
172
|
+
"update_document. Saving changes no stock; submitting posts the differences and needs a reason. With "
|
|
173
|
+
"stock_count (an existing draft) it refreshes the system quantities instead and keeps what was counted."),
|
|
174
|
+
parameters=PrepareCount.model_json_schema(), minimum_role="manager")
|
|
175
|
+
services.register_action(
|
|
176
|
+
"record_consignment_withdrawal", record_consignment_withdrawal,
|
|
177
|
+
description=(
|
|
178
|
+
"Record what a customer reported as USED from their consignment warehouse and bill it: creates and "
|
|
179
|
+
"submits a Consignment Withdrawal and ONE Sales Invoice that also takes the goods out of that warehouse. "
|
|
180
|
+
"items: item_code, qty, batch_no as reported (and location if the warehouse uses storage locations). "
|
|
181
|
+
"Give external_source + external_reference (the customer's report / order number) whenever there is one: "
|
|
182
|
+
"the same report sent again then returns the first result (replayed=true) instead of billing twice, and "
|
|
183
|
+
"the same number with different content is refused. replenish=true also drafts a replacement stocking."),
|
|
184
|
+
parameters=RecordWithdrawal.model_json_schema(), minimum_role="manager")
|
|
185
|
+
services.register_action(
|
|
186
|
+
"prepare_consignment_stocking", prepare_consignment_stocking,
|
|
187
|
+
description=(
|
|
188
|
+
"Draft the stocking of a customer's consignment warehouse: a DRAFT Stock Entry (Material Transfer) from "
|
|
189
|
+
"from_warehouse (default: the warehouse's replenishment_warehouse) with batches proposed first-expired-"
|
|
190
|
+
"first-out. No sale and no invoice. Nothing moves until the draft is submitted."),
|
|
191
|
+
parameters=PrepareStocking.model_json_schema(), minimum_role="manager")
|
|
192
|
+
services.register_action(
|
|
193
|
+
"prepare_consignment_recall", prepare_consignment_recall,
|
|
194
|
+
description=(
|
|
195
|
+
"Draft bringing goods back from a customer's consignment warehouse to one of your own (to_warehouse): "
|
|
196
|
+
"everything in it, or the given items / batches. A DRAFT Stock Entry; no credit note, the goods were "
|
|
197
|
+
"never sold. Nothing moves until the draft is submitted."),
|
|
198
|
+
parameters=PrepareRecall.model_json_schema(), minimum_role="manager")
|
|
199
|
+
services.register_action(
|
|
200
|
+
"confirm_purchase_order", confirm_purchase_order,
|
|
201
|
+
description=(
|
|
202
|
+
"Record the supplier's confirmed delivery date on a SUBMITTED purchase order: on all open lines, or on "
|
|
203
|
+
"`lines` (row names or positions). Optional confirmation_reference (the supplier's confirmation number) "
|
|
204
|
+
"and, for one line, confirmed_qty. Use it when an order confirmation arrives; the date then shows in the "
|
|
205
|
+
"sales-backlog and purchase-backlog reports. Only assign a confirmation to an order when the order number "
|
|
206
|
+
"is stated or the user confirms which order it belongs to."),
|
|
207
|
+
parameters=ConfirmPurchaseOrder.model_json_schema(), minimum_role="manager", pass_user=True)
|
|
208
|
+
services.register_action(
|
|
209
|
+
"reserve_sales_order", reserve_order,
|
|
210
|
+
description=(
|
|
211
|
+
"Reserve stock for the undelivered part of a submitted sales order (all stock lines, or only "
|
|
212
|
+
"sales_order_items). Reserves as much as is available per line and reports short_qty for the rest. "
|
|
213
|
+
"Reserved stock cannot be delivered, issued or transferred away for anyone else. To give stock back, "
|
|
214
|
+
"update the Stock Reservation's status to Released."),
|
|
215
|
+
parameters=ReserveOrder.model_json_schema(), minimum_role="manager")
|
|
216
|
+
services.register_action(
|
|
217
|
+
"suggest_picks", suggest,
|
|
218
|
+
description=(
|
|
219
|
+
"READ-ONLY picking proposal, first expired first out: which batches and storage locations to take a "
|
|
220
|
+
"quantity of an item from in a warehouse. Never proposes blocked or expired batches or stock reserved "
|
|
221
|
+
"for other orders; batches with too little shelf life left are listed under excluded unless "
|
|
222
|
+
"include_short_dated. Changes nothing: no reservation, no stock movement, no invoice."),
|
|
223
|
+
parameters=SuggestPicks.model_json_schema(), minimum_role="viewer")
|
|
224
|
+
services.register_action(
|
|
225
|
+
"prepare_location_move", prepare_location_move,
|
|
226
|
+
description=(
|
|
227
|
+
"Prepare moving EVERYTHING that lies in one storage location to another location "
|
|
228
|
+
"(same warehouse, or to_warehouse): creates a DRAFT Stock Entry (Material Transfer) with one row "
|
|
229
|
+
"per item and batch found there. Nothing moves until that draft is submitted with submit_document; "
|
|
230
|
+
"show the rows to the user first. For single items create a Material Transfer directly."),
|
|
231
|
+
parameters=MoveLocation.model_json_schema(), minimum_role="manager")
|
|
@@ -583,6 +583,12 @@ export const api = {
|
|
|
583
583
|
batchMovements: (params: Record<string, string>) =>
|
|
584
584
|
request<{ rows: any[] }>(`/reports/batch-movements${qs(params)}`),
|
|
585
585
|
|
|
586
|
+
batchRecipients: (params: Record<string, string>) =>
|
|
587
|
+
request<{ rows: any[]; in_stock: any[]; suppliers?: any[] }>(`/reports/batch-recipients${qs(params)}`),
|
|
588
|
+
|
|
589
|
+
batchChanges: (params: Record<string, string>) =>
|
|
590
|
+
request<{ rows: any[] }>(`/reports/batch-changes${qs(params)}`),
|
|
591
|
+
|
|
586
592
|
// --- Rentals: availability + fleet calendar ---
|
|
587
593
|
availability: (params: { item_code: string; from: string; to: string; warehouse?: string; exclude?: string }) =>
|
|
588
594
|
request<AvailabilityResult>(`/availability${qs(params)}`),
|
|
@@ -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)
|