lambda-erp 1.4.12__tar.gz → 1.4.13__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.12 → lambda_erp-1.4.13}/PKG-INFO +1 -1
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/chat.py +14 -2
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf_contract.py +1 -1
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/masters.py +25 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/reports.py +16 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/services.py +2 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/pos_invoice.py +1 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/purchase_invoice.py +1 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/sales_invoice.py +1 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/database.py +52 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/consignment.py +15 -5
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/delivery_note.py +4 -1
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/purchase_receipt.py +2 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/reservation.py +8 -3
- lambda_erp-1.4.13/lambda_erp/stock/serial.py +274 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/stock_count.py +3 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/stock_entry.py +25 -12
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/stock_ledger.py +10 -2
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/workflow.py +20 -1
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/pyproject.toml +1 -1
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/.gitignore +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/LICENSE +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/README.md +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/attachments.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/auth.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/chat_links.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/deps.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/erp_context.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/errors.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/list_values.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/main.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/mentions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/oauth.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/providers.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/record_notes.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/document.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/record.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/time_filters.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/api/write_context.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/frontend/README.md +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.12 → lambda_erp-1.4.13}/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", "batch-recipients", "batch-changes", "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", "serial-trace", "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"],
|
|
@@ -1994,6 +1994,11 @@ def _handle_get_report(args):
|
|
|
1994
1994
|
filters.get("expiring_before"), filters.get("expiring_after"),
|
|
1995
1995
|
bool(filters.get("include_empty")), filters.get("consignment_customer"),
|
|
1996
1996
|
None if consignment is None else bool(consignment))
|
|
1997
|
+
elif report_type == "serial-trace":
|
|
1998
|
+
from api.routers.reports import _serial_trace
|
|
1999
|
+
if not filters.get("serial_no"):
|
|
2000
|
+
return {"error": "serial-trace needs filters.serial_no"}
|
|
2001
|
+
return _serial_trace(db, filters.get("serial_no"), filters.get("item_code"))
|
|
1997
2002
|
elif report_type == "batch-recipients":
|
|
1998
2003
|
from api.routers.reports import _batch_recipients
|
|
1999
2004
|
if not filters.get("batch_no"):
|
|
@@ -2977,6 +2982,12 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2977
2982
|
- A sale never ships an expired or blocked batch. If the item has a minimum shelf life (`min_shelf_life_days`) and the batch has less left, the line needs `shelf_life_exception` with the approved reason; do not write one unless the user gives it.
|
|
2978
2983
|
- Expired or blocked stock can still be moved, returned to the supplier or written off with a Stock Entry.
|
|
2979
2984
|
|
|
2985
|
+
### Serial numbers
|
|
2986
|
+
- An item with `has_serial_no=1` is serial-tracked: every stock-moving line lists `serial_no`, as many numbers as its qty (line breaks or commas), each once; qty is a whole number. A number is unique per item and one unit is in one place at a time.
|
|
2987
|
+
- Receipts create the units; a number already in stock is refused. A unit can only be delivered, issued or transferred from the warehouse it is in. Returns must name units of the original document.
|
|
2988
|
+
- Never invent or guess a serial number. If the user has not given them, ask; to see what is in stock use search_masters master_type="serial-no" (filter item_code, warehouse) or the serial-trace report for one number.
|
|
2989
|
+
- Units from before the item was serial-tracked have no number: give them one with a Stock Entry of type "Serial Assignment" (item_code, qty, t_warehouse, serial_no).
|
|
2990
|
+
|
|
2980
2991
|
### Storage locations (places inside a warehouse)
|
|
2981
2992
|
- A warehouse with `use_locations=1` has storage locations (master `storage-location`: warehouse + location label, e.g. "A12"). The same label may exist in several warehouses.
|
|
2982
2993
|
- In such a warehouse every stock-moving line names its location: `location` on Delivery Note, Purchase Receipt and invoice lines (with update_stock=1); on Stock Entry lines `s_location` for the source side and `t_location` for the target side. Drafts may be saved without it; submit is refused. A warehouse without storage locations takes no location.
|
|
@@ -3053,6 +3064,7 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3053
3064
|
- **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".
|
|
3054
3065
|
- **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".
|
|
3055
3066
|
- **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.
|
|
3067
|
+
- **serial-trace** — Where one serial-numbered unit is now (warehouse, location, batch, or gone and to which customer) and every movement with its document and party. Filters: serial_no (required), item_code. A number alone can match several items.
|
|
3056
3068
|
- **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
3069
|
- **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.
|
|
3058
3070
|
- **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.
|
|
@@ -3085,7 +3097,7 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3085
3097
|
|
|
3086
3098
|
## Stock Entry specifics
|
|
3087
3099
|
When creating a stock-entry, the `data` object MUST include:
|
|
3088
|
-
- `stock_entry_type`: "Opening Stock", "Material Receipt", "Material Issue", "Material Transfer", or "
|
|
3100
|
+
- `stock_entry_type`: "Opening Stock", "Material Receipt", "Material Issue", "Material Transfer", "Batch Assignment", or "Serial Assignment"
|
|
3089
3101
|
- `company`, `posting_date`
|
|
3090
3102
|
- `items` array where each item uses `basic_rate` (NOT `rate`) and warehouse fields:
|
|
3091
3103
|
- Opening Stock: items need `t_warehouse` (target). Set `to_warehouse` on the parent too.
|
|
@@ -200,7 +200,7 @@ def prepare(doctype, doc):
|
|
|
200
200
|
if doctype == 'Stock Entry':
|
|
201
201
|
movement = doc['stock_entry_type']
|
|
202
202
|
if movement not in {'Material Receipt', 'Opening Stock', 'Material Issue', 'Material Transfer',
|
|
203
|
-
'Batch Assignment'}:
|
|
203
|
+
'Batch Assignment', 'Serial Assignment'}:
|
|
204
204
|
raise PDFError('PDF requires a supported stock_entry_type')
|
|
205
205
|
keys = ('s_warehouse', 't_warehouse') if movement == 'Material Transfer' else ('s_warehouse',) if movement == 'Material Issue' else ('t_warehouse',)
|
|
206
206
|
require(row, keys, f'items[{i}].')
|
|
@@ -64,6 +64,9 @@ DELETE_REFERENCE_CHECKS = {
|
|
|
64
64
|
('SELECT 1 FROM "Stock Ledger Entry" s JOIN "Batch" b ON b.item_code = s.item_code '
|
|
65
65
|
'AND b.batch_no = s.batch_no WHERE b.name = ? LIMIT 1', "stock ledger entry"),
|
|
66
66
|
],
|
|
67
|
+
"serial-no": [
|
|
68
|
+
('SELECT 1 FROM "Serial Movement" WHERE serial = ? LIMIT 1', "stock movement"),
|
|
69
|
+
],
|
|
67
70
|
"storage-location": [
|
|
68
71
|
('SELECT 1 FROM "Stock Ledger Entry" s JOIN "Storage Location" l ON l.warehouse = s.warehouse '
|
|
69
72
|
'AND l.location = s.location WHERE l.name = ? LIMIT 1', "stock ledger entry"),
|
|
@@ -226,6 +229,7 @@ MASTER_LINK_FIELDS = {
|
|
|
226
229
|
'cost-center': {'company': 'Company', 'parent_cost_center': 'Cost Center'},
|
|
227
230
|
'batch': {'item_code': 'Item'},
|
|
228
231
|
'storage-location': {'warehouse': 'Warehouse'},
|
|
232
|
+
'serial-no': {'item_code': 'Item'},
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
|
|
@@ -291,6 +295,8 @@ def _validate_master_input(master_type, doctype, data, name=None):
|
|
|
291
295
|
_validate_item_batch_flags(db, merged, name)
|
|
292
296
|
if master_type == 'batch':
|
|
293
297
|
_validate_batch(db, merged, name)
|
|
298
|
+
if master_type == 'serial-no':
|
|
299
|
+
_validate_serial(db, data, name)
|
|
294
300
|
if master_type == 'warehouse':
|
|
295
301
|
_validate_warehouse_locations(db, merged, name)
|
|
296
302
|
if master_type == 'storage-location':
|
|
@@ -311,12 +317,31 @@ def _validate_item_batch_flags(db, merged, name):
|
|
|
311
317
|
stock_item = merged.get('is_stock_item')
|
|
312
318
|
if tracked and stock_item is not None and not flt(stock_item):
|
|
313
319
|
raise ValidationError('Item: only a stock item can be batch-tracked')
|
|
320
|
+
numbered = bool(flt(merged.get('has_serial_no')))
|
|
321
|
+
if numbered and stock_item is not None and not flt(stock_item):
|
|
322
|
+
raise ValidationError('Item: only a stock item can be serial-tracked')
|
|
323
|
+
if name and not numbered and db.sql(
|
|
324
|
+
'SELECT 1 FROM "Serial No" WHERE item_code = ? LIMIT 1', [name]):
|
|
325
|
+
raise ValidationError(f'Item {name}: serial tracking cannot be switched off, the item has serial numbers')
|
|
314
326
|
if name and not tracked and db.sql(
|
|
315
327
|
'SELECT 1 FROM "Stock Ledger Entry" WHERE item_code = ? AND batch_no IS NOT NULL '
|
|
316
328
|
'AND batch_no <> \'\' LIMIT 1', [name]):
|
|
317
329
|
raise ValidationError(f'Item {name}: batch tracking cannot be switched off, the stock ledger has batches of it')
|
|
318
330
|
|
|
319
331
|
|
|
332
|
+
def _validate_serial(db, data, name):
|
|
333
|
+
"""Where a unit is comes from the stock ledger. Only remarks about it can
|
|
334
|
+
be edited here."""
|
|
335
|
+
if not name:
|
|
336
|
+
raise ValidationError('Serial numbers are created by receiving stock (or a Serial Assignment), not here')
|
|
337
|
+
fixed = sorted(set(data) - {'name', 'description', 'disabled', 'modified'})
|
|
338
|
+
stored = db.get_value('Serial No', name, fixed) or {} if fixed else {}
|
|
339
|
+
changed = [field for field in fixed if (data.get(field) or None) != (stored.get(field) or None)]
|
|
340
|
+
if changed:
|
|
341
|
+
raise ValidationError(
|
|
342
|
+
f'Serial No: {", ".join(changed)} follow the stock movements of the unit and cannot be edited')
|
|
343
|
+
|
|
344
|
+
|
|
320
345
|
def _validate_warehouse_locations(db, merged, name):
|
|
321
346
|
"""Storage locations can be switched on at any time (stock already there
|
|
322
347
|
stays without a location until it is put away). They cannot be switched
|
|
@@ -695,6 +695,22 @@ def batch_changes(batch_no: str | None = None, item_code: str | None = None):
|
|
|
695
695
|
return _batch_changes(get_db(), batch_no, item_code)
|
|
696
696
|
|
|
697
697
|
|
|
698
|
+
def _serial_trace(db, serial_no=None, item_code=None):
|
|
699
|
+
"""Where a serial-numbered unit is and everything that happened to it,
|
|
700
|
+
with documents and the customer or supplier. A number alone can belong
|
|
701
|
+
to several items: one row per item."""
|
|
702
|
+
permissions.require_artifact("report", "serial-trace")
|
|
703
|
+
if not serial_no:
|
|
704
|
+
raise HTTPException(status_code=422, detail="serial_no is required")
|
|
705
|
+
from lambda_erp.stock.serial import serial_trace
|
|
706
|
+
return {"rows": serial_trace(serial_no, item_code)}
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
@router.get("/serial-trace")
|
|
710
|
+
def serial_trace_report(serial_no: str, item_code: str | None = None):
|
|
711
|
+
return _serial_trace(get_db(), serial_no, item_code)
|
|
712
|
+
|
|
713
|
+
|
|
698
714
|
@router.get("/batch-movements")
|
|
699
715
|
def batch_movements(
|
|
700
716
|
batch_no: str,
|
|
@@ -101,6 +101,8 @@ MASTER_TABLES = {
|
|
|
101
101
|
"batch": ("Batch", "batch_no"),
|
|
102
102
|
# One row per (warehouse, location label).
|
|
103
103
|
"storage-location": ("Storage Location", "location"),
|
|
104
|
+
# One row per (item, serial number); written by the stock ledger.
|
|
105
|
+
"serial-no": ("Serial No", "serial_no"),
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
# Auto-naming prefixes: masters created without an explicit `name` get a
|
|
@@ -476,6 +476,7 @@ def make_purchase_return(pinv_name):
|
|
|
476
476
|
warehouse=item.get("warehouse"),
|
|
477
477
|
batch_no=item.get("batch_no"),
|
|
478
478
|
location=item.get("location"),
|
|
479
|
+
serial_no=item.get("serial_no"),
|
|
479
480
|
purchase_order=item.get("purchase_order"),
|
|
480
481
|
purchase_order_item=item.get("purchase_order_item"),
|
|
481
482
|
))
|
|
@@ -464,6 +464,7 @@ def make_sales_return(sinv_name):
|
|
|
464
464
|
warehouse=item.get("warehouse"),
|
|
465
465
|
batch_no=item.get("batch_no"),
|
|
466
466
|
location=item.get("location"),
|
|
467
|
+
serial_no=item.get("serial_no"),
|
|
467
468
|
sales_order=item.get("sales_order"),
|
|
468
469
|
sales_order_item=item.get("sales_order_item"),
|
|
469
470
|
))
|
|
@@ -3501,6 +3501,57 @@ def _m059_batch_change_log(db: "Database") -> None:
|
|
|
3501
3501
|
db._text_col_cache.pop("Batch Change", None)
|
|
3502
3502
|
|
|
3503
3503
|
|
|
3504
|
+
def _m060_serial_numbers(db: "Database") -> None:
|
|
3505
|
+
"""Serial-tracked items: one number per unit (see docs/serial-numbers.md).
|
|
3506
|
+
No item becomes serial-tracked and no serial number is invented."""
|
|
3507
|
+
db.conn.execute(db._ddl(
|
|
3508
|
+
"""CREATE TABLE IF NOT EXISTS "Serial No" (
|
|
3509
|
+
name TEXT PRIMARY KEY,
|
|
3510
|
+
item_code TEXT NOT NULL,
|
|
3511
|
+
serial_no TEXT NOT NULL,
|
|
3512
|
+
warehouse TEXT,
|
|
3513
|
+
location TEXT,
|
|
3514
|
+
batch_no TEXT,
|
|
3515
|
+
status TEXT,
|
|
3516
|
+
customer TEXT,
|
|
3517
|
+
description TEXT,
|
|
3518
|
+
disabled INTEGER DEFAULT 0,
|
|
3519
|
+
creation TEXT,
|
|
3520
|
+
modified TEXT
|
|
3521
|
+
)"""))
|
|
3522
|
+
db.conn.execute(db._ddl(
|
|
3523
|
+
'CREATE UNIQUE INDEX IF NOT EXISTS "ux_serial_no_item_serial" ON "Serial No" (item_code, serial_no)'))
|
|
3524
|
+
db.conn.execute(db._ddl(
|
|
3525
|
+
'CREATE INDEX IF NOT EXISTS "ix_serial_no_warehouse" ON "Serial No" (item_code, warehouse)'))
|
|
3526
|
+
db.conn.execute(db._ddl(
|
|
3527
|
+
"""CREATE TABLE IF NOT EXISTS "Serial Movement" (
|
|
3528
|
+
name TEXT PRIMARY KEY,
|
|
3529
|
+
serial TEXT NOT NULL,
|
|
3530
|
+
item_code TEXT,
|
|
3531
|
+
serial_no TEXT,
|
|
3532
|
+
stock_ledger_entry TEXT,
|
|
3533
|
+
voucher_type TEXT,
|
|
3534
|
+
voucher_no TEXT,
|
|
3535
|
+
voucher_detail_no TEXT,
|
|
3536
|
+
warehouse TEXT,
|
|
3537
|
+
location TEXT,
|
|
3538
|
+
batch_no TEXT,
|
|
3539
|
+
actual_qty REAL DEFAULT 0,
|
|
3540
|
+
posting_date TEXT,
|
|
3541
|
+
creation TEXT
|
|
3542
|
+
)"""))
|
|
3543
|
+
db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_serial_movement_serial" ON "Serial Movement" (serial)'))
|
|
3544
|
+
db.conn.execute(db._ddl(
|
|
3545
|
+
'CREATE INDEX IF NOT EXISTS "ix_serial_movement_voucher" ON "Serial Movement" (voucher_type, voucher_no)'))
|
|
3546
|
+
db.conn.commit()
|
|
3547
|
+
for table in ("Serial No", "Serial Movement"):
|
|
3548
|
+
db._col_cache.pop(table, None)
|
|
3549
|
+
db._text_col_cache.pop(table, None)
|
|
3550
|
+
db.ensure_column("Item", "has_serial_no", "INTEGER DEFAULT 0")
|
|
3551
|
+
for table in (*BATCH_LINE_TABLES, "Stock Count Item", "Consignment Withdrawal Item"):
|
|
3552
|
+
db.ensure_column(table, "serial_no", "TEXT")
|
|
3553
|
+
|
|
3554
|
+
|
|
3504
3555
|
def _m052_access_profiles(db: "Database") -> None:
|
|
3505
3556
|
"""Access profiles narrow what a user's role allows (lambda_erp.permissions).
|
|
3506
3557
|
No profile is created and no user is assigned one: nothing changes for
|
|
@@ -3600,6 +3651,7 @@ Database.MIGRATIONS = [
|
|
|
3600
3651
|
(57, "consignment", _m057_consignment),
|
|
3601
3652
|
(58, "stock_count", _m058_stock_count),
|
|
3602
3653
|
(59, "batch_change_log", _m059_batch_change_log),
|
|
3654
|
+
(60, "serial_numbers", _m060_serial_numbers),
|
|
3603
3655
|
]
|
|
3604
3656
|
|
|
3605
3657
|
|
|
@@ -52,12 +52,18 @@ def validate_consignment_sale(doc):
|
|
|
52
52
|
f"{owner}. Recall the goods to one of your own warehouses before selling them to someone else")
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
def _serials(value):
|
|
56
|
+
from lambda_erp.stock.serial import parse_serials
|
|
57
|
+
return parse_serials(value)
|
|
58
|
+
|
|
59
|
+
|
|
55
60
|
def content_hash(warehouse, items, replenish=False):
|
|
56
61
|
"""What a withdrawal report says, reduced to what matters: the same
|
|
57
62
|
report gives the same hash whatever the order of its lines."""
|
|
58
63
|
lines = sorted(
|
|
59
64
|
(str(row.get("item_code") or ""), str(row.get("batch_no") or ""), str(row.get("location") or ""),
|
|
60
|
-
round(flt(row.get("qty")), 6), None if row.get("rate") in (None, "") else round(flt(row.get("rate")), 6)
|
|
65
|
+
round(flt(row.get("qty")), 6), None if row.get("rate") in (None, "") else round(flt(row.get("rate")), 6),
|
|
66
|
+
sorted(_serials(row.get("serial_no"))))
|
|
61
67
|
for row in items or [])
|
|
62
68
|
payload = json.dumps({"warehouse": warehouse, "lines": lines, "replenish": bool(flt(replenish))},
|
|
63
69
|
sort_keys=True, default=str)
|
|
@@ -172,7 +178,8 @@ class ConsignmentWithdrawal(Document):
|
|
|
172
178
|
+ (f" ({self.external_reference})" if self._data.get("external_reference") else ""))
|
|
173
179
|
for row in self.get("items"):
|
|
174
180
|
line = _dict(item_code=row["item_code"], qty=flt(row["qty"]), warehouse=self.warehouse,
|
|
175
|
-
batch_no=row.get("batch_no") or None, location=row.get("location") or None
|
|
181
|
+
batch_no=row.get("batch_no") or None, location=row.get("location") or None,
|
|
182
|
+
serial_no=row.get("serial_no") or None)
|
|
176
183
|
if row.get("rate") is not None:
|
|
177
184
|
line["rate"] = flt(row["rate"])
|
|
178
185
|
invoice.append("items", line)
|
|
@@ -259,7 +266,7 @@ def record_withdrawal(warehouse, items, *, external_source=None, external_refere
|
|
|
259
266
|
external_reference=external_reference or None, replenish=1 if replenish else 0,
|
|
260
267
|
replenish_from_warehouse=replenish_from_warehouse, remarks=remarks)
|
|
261
268
|
for row in items or []:
|
|
262
|
-
doc.append("items", _dict({key: row.get(key) for key in ("item_code", "qty", "batch_no", "location", "rate", "uom")
|
|
269
|
+
doc.append("items", _dict({key: row.get(key) for key in ("item_code", "qty", "batch_no", "location", "rate", "uom", "serial_no")
|
|
263
270
|
if row.get(key) not in (None, "")}))
|
|
264
271
|
doc.save()
|
|
265
272
|
doc.submit()
|
|
@@ -328,7 +335,8 @@ def make_consignment_stocking(warehouse, items, *, from_warehouse=None):
|
|
|
328
335
|
for pick in picks:
|
|
329
336
|
entry.append("items", _dict(
|
|
330
337
|
item_code=row["item_code"], qty=flt(pick["qty"]), s_warehouse=origin, t_warehouse=warehouse,
|
|
331
|
-
batch_no=pick.get("batch_no"), s_location=pick.get("location"),
|
|
338
|
+
batch_no=pick.get("batch_no"), s_location=pick.get("location"),
|
|
339
|
+
serial_no=pick.get("serial_no"), **target))
|
|
332
340
|
if not entry.get("items"):
|
|
333
341
|
raise ValidationError("Nothing to stock")
|
|
334
342
|
return entry
|
|
@@ -352,9 +360,11 @@ def make_consignment_recall(warehouse, to_warehouse, *, items=None, to_location=
|
|
|
352
360
|
from_warehouse=warehouse, to_warehouse=to_warehouse)
|
|
353
361
|
|
|
354
362
|
def add(row, qty):
|
|
363
|
+
from lambda_erp.stock.serial import propose_serials
|
|
355
364
|
entry.append("items", _dict(
|
|
356
365
|
item_code=row["item_code"], qty=qty, s_warehouse=warehouse, t_warehouse=to_warehouse,
|
|
357
|
-
batch_no=row["batch_no"] or None, s_location=row["location"] or None, t_location=to_location or None
|
|
366
|
+
batch_no=row["batch_no"] or None, s_location=row["location"] or None, t_location=to_location or None,
|
|
367
|
+
serial_no=propose_serials(row["item_code"], warehouse, qty, row["batch_no"], row["location"])))
|
|
358
368
|
|
|
359
369
|
if not items:
|
|
360
370
|
for row in sorted(stock, key=lambda r: (r["item_code"], r["batch_no"], r["location"])):
|
|
@@ -152,7 +152,8 @@ def _proposed_picks(so, item, qty):
|
|
|
152
152
|
return plain
|
|
153
153
|
tracked = flt(db.get_value("Item", item["item_code"], "has_batch_no"))
|
|
154
154
|
located = flt(db.get_value("Warehouse", item["warehouse"], "use_locations"))
|
|
155
|
-
|
|
155
|
+
from lambda_erp.stock.serial import is_serial_item
|
|
156
|
+
if not tracked and not located and not is_serial_item(item["item_code"]):
|
|
156
157
|
return plain
|
|
157
158
|
from lambda_erp.stock.reservation import suggest_picks
|
|
158
159
|
picks = suggest_picks(item["item_code"], item["warehouse"], qty, customer=so.customer,
|
|
@@ -195,6 +196,7 @@ def make_delivery_note(sales_order_name):
|
|
|
195
196
|
warehouse=item.get("warehouse"),
|
|
196
197
|
batch_no=pick.get("batch_no"),
|
|
197
198
|
location=pick.get("location"),
|
|
199
|
+
serial_no=pick.get("serial_no"),
|
|
198
200
|
against_sales_order=so.name,
|
|
199
201
|
so_detail=item.get("name"),
|
|
200
202
|
))
|
|
@@ -241,6 +243,7 @@ def make_delivery_return(dn_name):
|
|
|
241
243
|
warehouse=item.get("warehouse"),
|
|
242
244
|
batch_no=item.get("batch_no"),
|
|
243
245
|
location=item.get("location"),
|
|
246
|
+
serial_no=item.get("serial_no"),
|
|
244
247
|
against_sales_order=item.get("against_sales_order"),
|
|
245
248
|
so_detail=item.get("so_detail"),
|
|
246
249
|
))
|
|
@@ -182,6 +182,7 @@ class PurchaseReceipt(Document):
|
|
|
182
182
|
batch_no=item.get("batch_no"),
|
|
183
183
|
expiry_date=item.get("expiry_date"),
|
|
184
184
|
location=item.get("location"),
|
|
185
|
+
serial_no=item.get("serial_no"),
|
|
185
186
|
posting_date=self.posting_date,
|
|
186
187
|
company=self.company,
|
|
187
188
|
))
|
|
@@ -314,6 +315,7 @@ def make_purchase_receipt_return(prec_name):
|
|
|
314
315
|
warehouse=item.get("warehouse"),
|
|
315
316
|
batch_no=item.get("batch_no"),
|
|
316
317
|
location=item.get("location"),
|
|
318
|
+
serial_no=item.get("serial_no"),
|
|
317
319
|
against_purchase_order=item.get("against_purchase_order"),
|
|
318
320
|
po_detail=item.get("po_detail"),
|
|
319
321
|
))
|
|
@@ -534,9 +534,14 @@ def suggest_picks(item_code, warehouse, qty, *, customer=None, on_date=None, sal
|
|
|
534
534
|
if remaining <= EPSILON:
|
|
535
535
|
break
|
|
536
536
|
take = min(remaining, candidate["available_qty"])
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
537
|
+
pick = {"batch_no": candidate["batch_no"], "location": candidate["location"],
|
|
538
|
+
"expiry_date": candidate["expiry_date"], "days_left": candidate["days_left"],
|
|
539
|
+
"qty": take, "needs_exception": candidate["needs_exception"]}
|
|
540
|
+
from lambda_erp.stock.serial import propose_serials
|
|
541
|
+
units = propose_serials(item_code, warehouse, take, candidate["batch_no"], candidate["location"])
|
|
542
|
+
if units:
|
|
543
|
+
pick["serial_no"] = units
|
|
544
|
+
picks.append(pick)
|
|
540
545
|
remaining -= take
|
|
541
546
|
picked = sum(pick["qty"] for pick in picks)
|
|
542
547
|
return {"item_code": item_code, "warehouse": warehouse, "strategy": "FEFO", "requested_qty": qty,
|