lambda-erp 1.4.11__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.11 → lambda_erp-1.4.13}/PKG-INFO +1 -1
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/chat.py +33 -2
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf_contract.py +6 -2
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf_profiles.py +5 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/masters.py +29 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/reports.py +109 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/services.py +5 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/stock_actions.py +31 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/frontend/src/api/client.ts +6 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/pos_invoice.py +1 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/purchase_invoice.py +1 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/sales_invoice.py +1 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/database.py +119 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/stock/consignment.py +15 -5
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/stock/delivery_note.py +4 -1
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/stock/purchase_receipt.py +2 -0
- {lambda_erp-1.4.11 → 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.13/lambda_erp/stock/stock_count.py +255 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/stock/stock_entry.py +25 -12
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/stock/stock_ledger.py +49 -2
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/workflow.py +20 -1
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/pyproject.toml +1 -1
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/.gitignore +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/LICENSE +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/README.md +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/attachments.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/auth.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/chat_links.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/deps.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/erp_context.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/errors.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/list_values.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/main.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/mentions.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/oauth.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/providers.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/record_notes.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/document.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/record.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/time_filters.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/api/write_context.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/frontend/README.md +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.11 → lambda_erp-1.4.13}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.11 → 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", "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,21 @@ 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"))
|
|
2002
|
+
elif report_type == "batch-recipients":
|
|
2003
|
+
from api.routers.reports import _batch_recipients
|
|
2004
|
+
if not filters.get("batch_no"):
|
|
2005
|
+
return {"error": "batch-recipients needs filters.batch_no"}
|
|
2006
|
+
return _batch_recipients(db, filters.get("batch_no"), filters.get("item_code"))
|
|
2007
|
+
elif report_type == "batch-changes":
|
|
2008
|
+
from api.routers.reports import _batch_changes
|
|
2009
|
+
if not filters.get("batch_no") and not filters.get("item_code"):
|
|
2010
|
+
return {"error": "batch-changes needs filters.batch_no or filters.item_code"}
|
|
2011
|
+
return _batch_changes(db, filters.get("batch_no"), filters.get("item_code"))
|
|
1997
2012
|
elif report_type == "batch-movements":
|
|
1998
2013
|
from api.routers.reports import _batch_movements
|
|
1999
2014
|
if not filters.get("batch_no"):
|
|
@@ -2929,6 +2944,13 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2929
2944
|
- **Material Transfer:** Moves stock between warehouses. No GL impact.
|
|
2930
2945
|
- **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.
|
|
2931
2946
|
|
|
2947
|
+
### Stock counts (inventory)
|
|
2948
|
+
- 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.
|
|
2949
|
+
- 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.
|
|
2950
|
+
- 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.
|
|
2951
|
+
- 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.
|
|
2952
|
+
- Use a Stock Count, not Material Receipt / Issue, when the reason is "what is there differs from what the system says".
|
|
2953
|
+
|
|
2932
2954
|
### Consignment (own stock lying at a customer)
|
|
2933
2955
|
- 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
2956
|
- **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.
|
|
@@ -2960,6 +2982,12 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2960
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.
|
|
2961
2983
|
- Expired or blocked stock can still be moved, returned to the supplier or written off with a Stock Entry.
|
|
2962
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
|
+
|
|
2963
2991
|
### Storage locations (places inside a warehouse)
|
|
2964
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.
|
|
2965
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.
|
|
@@ -3036,6 +3064,9 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3036
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".
|
|
3037
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".
|
|
3038
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.
|
|
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.
|
|
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.
|
|
3039
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.
|
|
3040
3071
|
- **dashboard-summary** — KPI overview (revenue, receivables, payables, stock value).
|
|
3041
3072
|
- **Custom analytics drafts** — reserved for when the user **explicitly asks
|
|
@@ -3066,7 +3097,7 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3066
3097
|
|
|
3067
3098
|
## Stock Entry specifics
|
|
3068
3099
|
When creating a stock-entry, the `data` object MUST include:
|
|
3069
|
-
- `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"
|
|
3070
3101
|
- `company`, `posting_date`
|
|
3071
3102
|
- `items` array where each item uses `basic_rate` (NOT `rate`) and warehouse fields:
|
|
3072
3103
|
- Opening Stock: items need `t_warehouse` (target). Set `to_warehouse` on the parent too.
|
|
@@ -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', 'Serial 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,11 @@ 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),)),
|
|
85
90
|
'Consignment Withdrawal': PDFProfile('record', 'Consignment withdrawal',
|
|
86
91
|
fields=('company', 'customer', 'warehouse', 'posting_date', 'external_reference', 'sales_invoice', 'remarks'),
|
|
87
92
|
required=('customer', 'warehouse', 'posting_date', 'items'),
|
|
@@ -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
|
|
@@ -509,6 +534,10 @@ def _update_master_record(master_type: str, name: str, data: dict) -> dict:
|
|
|
509
534
|
update_fields["modified"] = now()
|
|
510
535
|
if update_fields:
|
|
511
536
|
db.set_value(doctype, name, update_fields)
|
|
537
|
+
if master_type == 'batch':
|
|
538
|
+
# A batch's expiry date and block decide what may be sold: keep the trail.
|
|
539
|
+
from lambda_erp.stock.stock_ledger import log_batch_changes
|
|
540
|
+
log_batch_changes(name, stored, update_fields, 'Batch master')
|
|
512
541
|
|
|
513
542
|
rows = db.get_all(doctype, filters={"name": name}, fields=["*"])
|
|
514
543
|
if not rows:
|
|
@@ -602,6 +602,115 @@ def _batch_movements(db, batch_no=None, item_code=None, warehouse=None):
|
|
|
602
602
|
return {"rows": result}
|
|
603
603
|
|
|
604
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
|
+
|
|
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
|
+
|
|
605
714
|
@router.get("/batch-movements")
|
|
606
715
|
def batch_movements(
|
|
607
716
|
batch_no: str,
|
|
@@ -35,6 +35,7 @@ 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
37
|
from lambda_erp.stock.consignment import ConsignmentWithdrawal
|
|
38
|
+
from lambda_erp.stock.stock_count import StockCount
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
# --- Doctype registries ---
|
|
@@ -68,6 +69,8 @@ DOCUMENT_CLASSES = {
|
|
|
68
69
|
"Stock Reservation": StockReservation,
|
|
69
70
|
# What a customer reported as used from their consignment warehouse.
|
|
70
71
|
"Consignment Withdrawal": ConsignmentWithdrawal,
|
|
72
|
+
# Counted quantities; submitting books the differences with a reason.
|
|
73
|
+
"Stock Count": StockCount,
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
CONVERTERS = {
|
|
@@ -98,6 +101,8 @@ MASTER_TABLES = {
|
|
|
98
101
|
"batch": ("Batch", "batch_no"),
|
|
99
102
|
# One row per (warehouse, location label).
|
|
100
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"),
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
# Auto-naming prefixes: masters created without an explicit `name` get a
|
|
@@ -52,6 +52,28 @@ 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 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
|
+
|
|
55
77
|
class ConsignmentLine(mentions.Input):
|
|
56
78
|
item_code: str = Field(min_length=1, max_length=200)
|
|
57
79
|
qty: float | None = Field(default=None, gt=0)
|
|
@@ -141,6 +163,15 @@ def confirm_purchase_order(args, user=None):
|
|
|
141
163
|
|
|
142
164
|
|
|
143
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")
|
|
144
175
|
services.register_action(
|
|
145
176
|
"record_consignment_withdrawal", record_consignment_withdrawal,
|
|
146
177
|
description=(
|
|
@@ -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)}`),
|
|
@@ -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
|
))
|
|
@@ -3436,6 +3436,122 @@ def _m057_consignment(db: "Database") -> None:
|
|
|
3436
3436
|
db._text_col_cache.pop(table, None)
|
|
3437
3437
|
|
|
3438
3438
|
|
|
3439
|
+
def _m058_stock_count(db: "Database") -> None:
|
|
3440
|
+
"""Stock Count: counted quantities per item, batch and storage location,
|
|
3441
|
+
posted as a correction with a reason (see docs/stock-counts.md)."""
|
|
3442
|
+
db.conn.execute(db._ddl(
|
|
3443
|
+
"""CREATE TABLE IF NOT EXISTS "Stock Count" (
|
|
3444
|
+
name TEXT PRIMARY KEY,
|
|
3445
|
+
company TEXT,
|
|
3446
|
+
warehouse TEXT NOT NULL,
|
|
3447
|
+
posting_date TEXT,
|
|
3448
|
+
reason TEXT,
|
|
3449
|
+
remarks TEXT,
|
|
3450
|
+
counted_lines INTEGER DEFAULT 0,
|
|
3451
|
+
difference_lines INTEGER DEFAULT 0,
|
|
3452
|
+
status TEXT DEFAULT 'Draft',
|
|
3453
|
+
docstatus INTEGER DEFAULT 0,
|
|
3454
|
+
discarded INTEGER DEFAULT 0,
|
|
3455
|
+
creation TEXT,
|
|
3456
|
+
modified TEXT
|
|
3457
|
+
)"""))
|
|
3458
|
+
db.conn.execute(db._ddl(
|
|
3459
|
+
"""CREATE TABLE IF NOT EXISTS "Stock Count Item" (
|
|
3460
|
+
name TEXT PRIMARY KEY,
|
|
3461
|
+
parent TEXT NOT NULL,
|
|
3462
|
+
idx INTEGER DEFAULT 0,
|
|
3463
|
+
item_code TEXT,
|
|
3464
|
+
item_name TEXT,
|
|
3465
|
+
warehouse TEXT,
|
|
3466
|
+
location TEXT,
|
|
3467
|
+
batch_no TEXT,
|
|
3468
|
+
expiry_date TEXT,
|
|
3469
|
+
system_qty REAL DEFAULT 0,
|
|
3470
|
+
counted_qty REAL,
|
|
3471
|
+
difference_qty REAL,
|
|
3472
|
+
remarks TEXT
|
|
3473
|
+
)"""))
|
|
3474
|
+
db.conn.execute(db._ddl(
|
|
3475
|
+
'CREATE INDEX IF NOT EXISTS "ix_stock_count_item_parent" ON "Stock Count Item" (parent)'))
|
|
3476
|
+
db.conn.commit()
|
|
3477
|
+
for table in ("Stock Count", "Stock Count Item"):
|
|
3478
|
+
db._col_cache.pop(table, None)
|
|
3479
|
+
db._text_col_cache.pop(table, None)
|
|
3480
|
+
|
|
3481
|
+
|
|
3482
|
+
def _m059_batch_change_log(db: "Database") -> None:
|
|
3483
|
+
"""Who changed a batch's expiry date or block, when, and from what
|
|
3484
|
+
(see docs/batches.md). Changes made before this migration are not known."""
|
|
3485
|
+
db.conn.execute(db._ddl(
|
|
3486
|
+
"""CREATE TABLE IF NOT EXISTS "Batch Change" (
|
|
3487
|
+
name TEXT PRIMARY KEY,
|
|
3488
|
+
batch TEXT NOT NULL,
|
|
3489
|
+
item_code TEXT,
|
|
3490
|
+
batch_no TEXT,
|
|
3491
|
+
field TEXT NOT NULL,
|
|
3492
|
+
old_value TEXT,
|
|
3493
|
+
new_value TEXT,
|
|
3494
|
+
changed_by TEXT,
|
|
3495
|
+
changed_at TEXT,
|
|
3496
|
+
source TEXT
|
|
3497
|
+
)"""))
|
|
3498
|
+
db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_batch_change_batch" ON "Batch Change" (batch)'))
|
|
3499
|
+
db.conn.commit()
|
|
3500
|
+
db._col_cache.pop("Batch Change", None)
|
|
3501
|
+
db._text_col_cache.pop("Batch Change", None)
|
|
3502
|
+
|
|
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
|
+
|
|
3439
3555
|
def _m052_access_profiles(db: "Database") -> None:
|
|
3440
3556
|
"""Access profiles narrow what a user's role allows (lambda_erp.permissions).
|
|
3441
3557
|
No profile is created and no user is assigned one: nothing changes for
|
|
@@ -3533,6 +3649,9 @@ Database.MIGRATIONS = [
|
|
|
3533
3649
|
(55, "price_decisions", _m055_price_decisions),
|
|
3534
3650
|
(56, "order_progress", _m056_order_progress),
|
|
3535
3651
|
(57, "consignment", _m057_consignment),
|
|
3652
|
+
(58, "stock_count", _m058_stock_count),
|
|
3653
|
+
(59, "batch_change_log", _m059_batch_change_log),
|
|
3654
|
+
(60, "serial_numbers", _m060_serial_numbers),
|
|
3536
3655
|
]
|
|
3537
3656
|
|
|
3538
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"])):
|