lambda-erp 1.4.10__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.10 → lambda_erp-1.4.11}/PKG-INFO +1 -1
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/chat.py +14 -2
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/errors.py +5 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf_profiles.py +4 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/masters.py +15 -1
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/reports.py +21 -10
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/services.py +3 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/stock_actions.py +93 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/pos_invoice.py +2 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/sales_invoice.py +2 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/database.py +54 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/exceptions.py +4 -0
- lambda_erp-1.4.11/lambda_erp/stock/consignment.py +378 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/stock/delivery_note.py +2 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/stock/stock_entry.py +12 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/workflow.py +6 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/pyproject.toml +1 -1
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/.gitignore +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/LICENSE +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/README.md +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/attachments.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/auth.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/chat_links.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/deps.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/erp_context.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/list_values.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/main.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/mentions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/oauth.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/providers.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/record_notes.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/document.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/record.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/time_filters.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/api/write_context.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/frontend/README.md +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.10 → lambda_erp-1.4.11}/terraform/README.md +0 -0
|
@@ -1988,10 +1988,12 @@ 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))
|
|
1995
1997
|
elif report_type == "batch-movements":
|
|
1996
1998
|
from api.routers.reports import _batch_movements
|
|
1997
1999
|
if not filters.get("batch_no"):
|
|
@@ -2927,6 +2929,16 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2927
2929
|
- **Material Transfer:** Moves stock between warehouses. No GL impact.
|
|
2928
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.
|
|
2929
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
|
+
|
|
2930
2942
|
### Partial deliveries, backorders and invoicing after delivery
|
|
2931
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.
|
|
2932
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.
|
|
@@ -3022,7 +3034,7 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3022
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.
|
|
3023
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".
|
|
3024
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".
|
|
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".
|
|
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".
|
|
3026
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.
|
|
3027
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.
|
|
3028
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)
|
|
@@ -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")
|
|
@@ -34,6 +34,7 @@ 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
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
# --- Doctype registries ---
|
|
@@ -65,6 +66,8 @@ DOCUMENT_CLASSES = {
|
|
|
65
66
|
"Reservation": Reservation,
|
|
66
67
|
# Stock set aside for a sales order line (or with a reason); also status-driven.
|
|
67
68
|
"Stock Reservation": StockReservation,
|
|
69
|
+
# What a customer reported as used from their consignment warehouse.
|
|
70
|
+
"Consignment Withdrawal": ConsignmentWithdrawal,
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
CONVERTERS = {
|
|
@@ -52,6 +52,75 @@ def suggest(args):
|
|
|
52
52
|
sales_order_item=data.sales_order_item, include_short_dated=data.include_short_dated)
|
|
53
53
|
|
|
54
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
|
+
|
|
55
124
|
class ConfirmPurchaseOrder(mentions.Input):
|
|
56
125
|
purchase_order: str = Field(min_length=1, max_length=200)
|
|
57
126
|
confirmed_date: str = Field(min_length=8, max_length=10)
|
|
@@ -72,6 +141,30 @@ def confirm_purchase_order(args, user=None):
|
|
|
72
141
|
|
|
73
142
|
|
|
74
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")
|
|
75
168
|
services.register_action(
|
|
76
169
|
"confirm_purchase_order", confirm_purchase_order,
|
|
77
170
|
description=(
|
|
@@ -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)
|
|
@@ -3383,6 +3383,59 @@ def _m056_order_progress(db: "Database") -> None:
|
|
|
3383
3383
|
db.ensure_column("Purchase Order Item", column, definition)
|
|
3384
3384
|
|
|
3385
3385
|
|
|
3386
|
+
def _m057_consignment(db: "Database") -> None:
|
|
3387
|
+
"""Consignment warehouses and withdrawals (see docs/consignment.md). No
|
|
3388
|
+
warehouse becomes a consignment warehouse by the migration."""
|
|
3389
|
+
db.ensure_column("Warehouse", "consignment_customer", "TEXT")
|
|
3390
|
+
db.ensure_column("Warehouse", "replenishment_warehouse", "TEXT")
|
|
3391
|
+
db.conn.execute(db._ddl(
|
|
3392
|
+
"""CREATE TABLE IF NOT EXISTS "Consignment Withdrawal" (
|
|
3393
|
+
name TEXT PRIMARY KEY,
|
|
3394
|
+
company TEXT,
|
|
3395
|
+
customer TEXT,
|
|
3396
|
+
warehouse TEXT NOT NULL,
|
|
3397
|
+
posting_date TEXT,
|
|
3398
|
+
external_source TEXT,
|
|
3399
|
+
external_reference TEXT,
|
|
3400
|
+
content_hash TEXT,
|
|
3401
|
+
replenish INTEGER DEFAULT 0,
|
|
3402
|
+
replenish_from_warehouse TEXT,
|
|
3403
|
+
sales_invoice TEXT,
|
|
3404
|
+
replacement_stock_entry TEXT,
|
|
3405
|
+
replenishment_status TEXT DEFAULT 'Not Requested',
|
|
3406
|
+
remarks TEXT,
|
|
3407
|
+
status TEXT DEFAULT 'Draft',
|
|
3408
|
+
docstatus INTEGER DEFAULT 0,
|
|
3409
|
+
discarded INTEGER DEFAULT 0,
|
|
3410
|
+
creation TEXT,
|
|
3411
|
+
modified TEXT
|
|
3412
|
+
)"""))
|
|
3413
|
+
db.conn.execute(db._ddl(
|
|
3414
|
+
"""CREATE TABLE IF NOT EXISTS "Consignment Withdrawal Item" (
|
|
3415
|
+
name TEXT PRIMARY KEY,
|
|
3416
|
+
parent TEXT NOT NULL,
|
|
3417
|
+
idx INTEGER DEFAULT 0,
|
|
3418
|
+
item_code TEXT,
|
|
3419
|
+
item_name TEXT,
|
|
3420
|
+
qty REAL DEFAULT 0,
|
|
3421
|
+
uom TEXT,
|
|
3422
|
+
batch_no TEXT,
|
|
3423
|
+
location TEXT,
|
|
3424
|
+
rate REAL
|
|
3425
|
+
)"""))
|
|
3426
|
+
# One active withdrawal per customer report; a cancelled one frees the reference.
|
|
3427
|
+
db.conn.execute(db._ddl(
|
|
3428
|
+
'CREATE UNIQUE INDEX IF NOT EXISTS "ux_consignment_withdrawal_external" '
|
|
3429
|
+
'ON "Consignment Withdrawal" (external_source, external_reference) '
|
|
3430
|
+
'WHERE external_reference IS NOT NULL AND docstatus < 2 AND COALESCE(discarded, 0) = 0'))
|
|
3431
|
+
db.conn.execute(db._ddl(
|
|
3432
|
+
'CREATE INDEX IF NOT EXISTS "ix_consignment_withdrawal_item_parent" ON "Consignment Withdrawal Item" (parent)'))
|
|
3433
|
+
db.conn.commit()
|
|
3434
|
+
for table in ("Consignment Withdrawal", "Consignment Withdrawal Item"):
|
|
3435
|
+
db._col_cache.pop(table, None)
|
|
3436
|
+
db._text_col_cache.pop(table, None)
|
|
3437
|
+
|
|
3438
|
+
|
|
3386
3439
|
def _m052_access_profiles(db: "Database") -> None:
|
|
3387
3440
|
"""Access profiles narrow what a user's role allows (lambda_erp.permissions).
|
|
3388
3441
|
No profile is created and no user is assigned one: nothing changes for
|
|
@@ -3479,6 +3532,7 @@ Database.MIGRATIONS = [
|
|
|
3479
3532
|
(54, "reservations_and_shelf_life", _m054_reservations_and_shelf_life),
|
|
3480
3533
|
(55, "price_decisions", _m055_price_decisions),
|
|
3481
3534
|
(56, "order_progress", _m056_order_progress),
|
|
3535
|
+
(57, "consignment", _m057_consignment),
|
|
3482
3536
|
]
|
|
3483
3537
|
|
|
3484
3538
|
|
|
@@ -9,6 +9,10 @@ class MandatoryError(ValidationError):
|
|
|
9
9
|
pass
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
class ConflictError(ValidationError):
|
|
13
|
+
"""The request conflicts with what is already recorded (HTTP 409)."""
|
|
14
|
+
|
|
15
|
+
|
|
12
16
|
class PermissionDenied(ValidationError):
|
|
13
17
|
"""The caller's access profile does not allow this (HTTP 403)."""
|
|
14
18
|
|