lambda-erp 1.4.30__tar.gz → 1.4.31__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.30 → lambda_erp-1.4.31}/PKG-INFO +4 -4
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/README.md +3 -3
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/chat.py +18 -11
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/main.py +2 -0
- lambda_erp-1.4.31/api/order_actions.py +98 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/providers.py +4 -3
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/reports.py +22 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/frontend/src/api/client.ts +3 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/backlog.py +18 -11
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/buying/purchase_order.py +3 -1
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/database.py +12 -0
- lambda_erp-1.4.31/lambda_erp/order_closing.py +184 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/permissions.py +1 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/selling/sales_order.py +3 -1
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/delivery_note.py +141 -26
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/purchase_receipt.py +1 -1
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/reservation.py +7 -4
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/workflow.py +24 -10
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/pyproject.toml +1 -1
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/.gitignore +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/LICENSE +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/attachments.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/auth.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/chat_links.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/deps.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/erp_context.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/errors.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/list_columns.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/list_values.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/mentions.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/number_series.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/oauth.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/record_notes.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/services.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/document.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/record.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/time_filters.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/tool_results.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/api/write_context.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/frontend/README.md +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/units.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.30 → lambda_erp-1.4.31}/terraform/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lambda-erp
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.31
|
|
4
4
|
Summary: Core ERP logic - accounting, sales, purchasing, inventory
|
|
5
5
|
Author: TORUS INVESTMENTS AG
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -266,8 +266,8 @@ Open `http://localhost:5173`. Vite proxies `/api/*` to the backend.
|
|
|
266
266
|
|
|
267
267
|
```
|
|
268
268
|
OPENAI_API_KEY=sk-...
|
|
269
|
-
LAMBDA_ERP_CHAT_MODEL=gpt-6.
|
|
270
|
-
LAMBDA_ERP_REPORT_MODEL=gpt-6.
|
|
269
|
+
LAMBDA_ERP_CHAT_MODEL=gpt-6.1-sol # optional chat override; default shown
|
|
270
|
+
LAMBDA_ERP_REPORT_MODEL=gpt-6.1-sol # optional specialist override; default shown
|
|
271
271
|
LAMBDA_ERP_TITLE_MODEL=gpt-6-luna # optional chat-title override; default shown
|
|
272
272
|
LAMBDA_ERP_ADMIN_EMAIL=admin@example.com # optional, seeds the admin at boot
|
|
273
273
|
LAMBDA_ERP_ADMIN_PASSWORD=... # optional, required with the line above
|
|
@@ -275,7 +275,7 @@ LAMBDA_ERP_ADMIN_NAME=Administrator # optional, display name for the seed
|
|
|
275
275
|
```
|
|
276
276
|
|
|
277
277
|
Chat, chat titles and custom-report specification generation share
|
|
278
|
-
`OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.
|
|
278
|
+
`OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.1 Sol,
|
|
279
279
|
titles to GPT-6 Luna; see [docs/llm-pricing.md](docs/llm-pricing.md) for prices.
|
|
280
280
|
|
|
281
281
|
**Seeded admin.** By default the first person to register becomes the admin. Set `LAMBDA_ERP_ADMIN_EMAIL` + `LAMBDA_ERP_ADMIN_PASSWORD` to instead provision that admin automatically at startup — useful when the database is recreated on every deploy, so a redeployed instance can't be claimed by whoever visits first. It's create-if-missing and idempotent (an existing account with that email is promoted to an enabled admin; its password is left untouched), and the password is only ever read from the environment.
|
|
@@ -235,8 +235,8 @@ Open `http://localhost:5173`. Vite proxies `/api/*` to the backend.
|
|
|
235
235
|
|
|
236
236
|
```
|
|
237
237
|
OPENAI_API_KEY=sk-...
|
|
238
|
-
LAMBDA_ERP_CHAT_MODEL=gpt-6.
|
|
239
|
-
LAMBDA_ERP_REPORT_MODEL=gpt-6.
|
|
238
|
+
LAMBDA_ERP_CHAT_MODEL=gpt-6.1-sol # optional chat override; default shown
|
|
239
|
+
LAMBDA_ERP_REPORT_MODEL=gpt-6.1-sol # optional specialist override; default shown
|
|
240
240
|
LAMBDA_ERP_TITLE_MODEL=gpt-6-luna # optional chat-title override; default shown
|
|
241
241
|
LAMBDA_ERP_ADMIN_EMAIL=admin@example.com # optional, seeds the admin at boot
|
|
242
242
|
LAMBDA_ERP_ADMIN_PASSWORD=... # optional, required with the line above
|
|
@@ -244,7 +244,7 @@ LAMBDA_ERP_ADMIN_NAME=Administrator # optional, display name for the seed
|
|
|
244
244
|
```
|
|
245
245
|
|
|
246
246
|
Chat, chat titles and custom-report specification generation share
|
|
247
|
-
`OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.
|
|
247
|
+
`OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.1 Sol,
|
|
248
248
|
titles to GPT-6 Luna; see [docs/llm-pricing.md](docs/llm-pricing.md) for prices.
|
|
249
249
|
|
|
250
250
|
**Seeded admin.** By default the first person to register becomes the admin. Set `LAMBDA_ERP_ADMIN_EMAIL` + `LAMBDA_ERP_ADMIN_PASSWORD` to instead provision that admin automatically at startup — useful when the database is recreated on every deploy, so a redeployed instance can't be claimed by whoever visits first. It's create-if-missing and idempotent (an existing account with that email is promoted to an enabled admin; its password is left untouched), and the password is only ever read from the environment.
|
|
@@ -1057,7 +1057,7 @@ TOOLS = [
|
|
|
1057
1057
|
"properties": {
|
|
1058
1058
|
"limit": {"type": "integer", "description": "Maximum rows of a list report, default 200, range 1–2000. The general ledger uses filters.limit / filters.offset instead."},
|
|
1059
1059
|
"offset": {"type": "integer", "description": "Skip this many rows.", "default": 0},
|
|
1060
|
-
"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"]},
|
|
1060
|
+
"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", "unbilled-deliveries", "dashboard-summary", "profit-and-loss", "balance-sheet", "ar-aging", "ap-aging"]},
|
|
1061
1061
|
"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": {}},
|
|
1062
1062
|
},
|
|
1063
1063
|
"required": ["report_type"],
|
|
@@ -2270,6 +2270,10 @@ def _run_report(args):
|
|
|
2270
2270
|
from api.routers.reports import _purchase_backlog
|
|
2271
2271
|
return _purchase_backlog(db, filters.get("supplier"), filters.get("item_code"), filters.get("warehouse"),
|
|
2272
2272
|
bool(filters.get("overdue_only")))
|
|
2273
|
+
elif report_type == "unbilled-deliveries":
|
|
2274
|
+
from api.routers.reports import _unbilled_deliveries
|
|
2275
|
+
return _unbilled_deliveries(db, filters.get("customer"), filters.get("company"), filters.get("from_date"),
|
|
2276
|
+
filters.get("to_date"), filters.get("delivery_note"))
|
|
2273
2277
|
elif report_type == "stock-availability":
|
|
2274
2278
|
from api.routers.reports import _stock_availability
|
|
2275
2279
|
return _stock_availability(db, filters.get("item_code"), filters.get("warehouse"), filters.get("item_prefix"))
|
|
@@ -3283,9 +3287,11 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
3283
3287
|
- If it is unclear whether an incoming order is a stocking request, a withdrawal or a normal order, ask.
|
|
3284
3288
|
|
|
3285
3289
|
### Partial deliveries, backorders and invoicing after delivery
|
|
3286
|
-
- 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.
|
|
3290
|
+
- Order progress is derived from the submitted documents, per order line: delivered_qty (net of returns), returned_qty, billed_qty. Never set them. closed_qty is what was closed by hand. Open = qty − closed_qty − delivered_qty.
|
|
3287
3291
|
- 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.
|
|
3288
3292
|
- Deliver first, invoice after: convert the submitted **Delivery Note** to a Sales Invoice (convert_document doctype="delivery-note", target_doctype="Sales Invoice"). It bills what that delivery delivered and has not been billed, and does not move stock again. Converting the Sales Order to a Sales Invoice instead bills the ordered quantity regardless of delivery.
|
|
3293
|
+
- **Closing the rest of a line** (the customer no longer wants what is still open, a supplier will never deliver the rest): use the `close_order_lines` action on the submitted order with the lines and a reason. Do not cancel or amend the order, and do not create a return for goods that were never delivered. Deliveries and invoices already posted stay. Delivered or invoiced quantities cannot be closed (a credit note corrects those). `reopen_order_lines` undoes it.
|
|
3294
|
+
- **Monthly / collective invoice** (several deliveries to one customer billed together): check the unbilled-deliveries report for the customer and period, then use `prepare_collective_invoice` (customer + from_date/to_date, or delivery_notes, or the delivery note lines). It drafts ONE Sales Invoice whose lines keep their delivery note and order line; already billed lines are never taken again. Show the draft before submitting.
|
|
3289
3295
|
- Receive first, invoice after works the same on the purchasing side: convert the submitted **Purchase Receipt** to a Purchase Invoice (convert_document doctype="purchase-receipt", target_doctype="Purchase Invoice"). It bills what was received and not billed, at the received price, and does not move stock again.
|
|
3290
3296
|
- A Stock Reservation can name `batch_no` and / or `location` to hold exactly that stock; without them it holds a quantity in the warehouse and the batch is decided when picking.
|
|
3291
3297
|
- "What is still open / on backorder / can go out now" → sales-backlog report. "Is it on order, and when does it come" → the same report's purchase order columns, or purchase-backlog.
|
|
@@ -3411,7 +3417,8 @@ Master records CAN be deleted — use the `delete_master` tool (ADMIN role only)
|
|
|
3411
3417
|
- **ar-aging** — Outstanding receivables bucketed by overdue days (Current, 1-30, 31-60, 61-90, 90+). Filters: company, as_of_date.
|
|
3412
3418
|
- **ap-aging** — Outstanding payables bucketed by overdue days. Filters: company, as_of_date.
|
|
3413
3419
|
- **stock-balance** — Inventory quantities and valuations. Filters: item_code, warehouse.
|
|
3414
|
-
- **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.
|
|
3420
|
+
- **sales-backlog** — Open sales order lines (ordered − closed > delivered): ordered_qty, delivered_qty (net of returns), returned_qty, billed_qty, closed_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.
|
|
3421
|
+
- **unbilled-deliveries** — Delivered and not yet invoiced, per delivery note line (oldest first): delivery_note, posting_date, customer, item_code, qty, billed_qty, unbilled_qty, rate, unbilled_amount, sales_order. Filters: customer, company, from_date, to_date, delivery_note. What prepare_collective_invoice would bill.
|
|
3415
3422
|
- **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".
|
|
3416
3423
|
- **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".
|
|
3417
3424
|
- **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".
|
|
@@ -3519,14 +3526,14 @@ Users can attach PDFs and images (receipts, bills, contracts, screenshots) to th
|
|
|
3519
3526
|
# ---------------------------------------------------------------------------
|
|
3520
3527
|
# OpenAI report-spec specialist
|
|
3521
3528
|
#
|
|
3522
|
-
# GPT-6.
|
|
3529
|
+
# GPT-6.1 Sol acts as the planner/orchestrator. When it decides a report needs
|
|
3523
3530
|
# a custom analytics view it calls the create/update custom analytics tools.
|
|
3524
|
-
# Those handlers make a separate, narrowly prompted GPT-6.
|
|
3531
|
+
# Those handlers make a separate, narrowly prompted GPT-6.1 Sol call for the bounded
|
|
3525
3532
|
# declarative report spec. Both roles use the same provider and key (api/llm_provider.py).
|
|
3526
3533
|
# ---------------------------------------------------------------------------
|
|
3527
3534
|
|
|
3528
3535
|
|
|
3529
|
-
REPORT_SPECIALIST_MODEL = "gpt-6.
|
|
3536
|
+
REPORT_SPECIALIST_MODEL = "gpt-6.1-sol"
|
|
3530
3537
|
|
|
3531
3538
|
|
|
3532
3539
|
def _report_specialist_model() -> str:
|
|
@@ -3953,12 +3960,12 @@ async def generate_title(
|
|
|
3953
3960
|
# Reasoning loop
|
|
3954
3961
|
# ---------------------------------------------------------------------------
|
|
3955
3962
|
|
|
3956
|
-
# GPT-6.
|
|
3963
|
+
# GPT-6.1 Sol (the default; GPT-6.2 Sol in core 1.4.26 to 1.4.30) requires
|
|
3957
3964
|
# Responses for function tools and does not support
|
|
3958
3965
|
# reasoning effort "none", including tool-free wrap-ups after the step limit.
|
|
3959
3966
|
# LAMBDA_ERP_CHAT_MODEL overrides it per deployment (e.g. to trial a cheaper
|
|
3960
3967
|
# model on dev); see docs/llm-pricing.md.
|
|
3961
|
-
ORCHESTRATOR_MODEL = "gpt-6.
|
|
3968
|
+
ORCHESTRATOR_MODEL = "gpt-6.1-sol"
|
|
3962
3969
|
|
|
3963
3970
|
|
|
3964
3971
|
def _chat_model() -> str:
|
|
@@ -4241,11 +4248,11 @@ async def run_thinking_loop(
|
|
|
4241
4248
|
):
|
|
4242
4249
|
"""Run the agentic reasoning loop.
|
|
4243
4250
|
|
|
4244
|
-
The orchestrator and the report specialist use GPT-6.
|
|
4251
|
+
The orchestrator and the report specialist use GPT-6.1 Sol.
|
|
4245
4252
|
When GPT decides to call
|
|
4246
4253
|
`create_custom_analytics_report` or `update_custom_analytics_report`
|
|
4247
4254
|
with an intent/feedback hint, the tool handler itself delegates the
|
|
4248
|
-
declarative-spec step to a separate narrowly prompted GPT-6.
|
|
4255
|
+
declarative-spec step to a separate narrowly prompted GPT-6.1 Sol call. We emit an
|
|
4249
4256
|
`llm_provider` event around that delegation so the UI can surface it.
|
|
4250
4257
|
"""
|
|
4251
4258
|
if not llm_configured():
|
|
@@ -4461,7 +4468,7 @@ async def run_thinking_loop(
|
|
|
4461
4468
|
principal_ref[0] = refresh_auth_principal(principal_ref[0])
|
|
4462
4469
|
live_role = principal_ref[0].get("role") if principal_ref[0] else None
|
|
4463
4470
|
|
|
4464
|
-
# If the orchestrator is delegating report-spec generation to GPT-6.
|
|
4471
|
+
# If the orchestrator is delegating report-spec generation to GPT-6.1 Sol,
|
|
4465
4472
|
# surface the handoff in the UI.
|
|
4466
4473
|
will_delegate_to_report_specialist = (
|
|
4467
4474
|
tool_allowed(fn_name, live_role)
|
|
@@ -72,6 +72,8 @@ async def lifespan(app: FastAPI):
|
|
|
72
72
|
initialize_stock_actions()
|
|
73
73
|
from api.pricing_actions import initialize_pricing_actions
|
|
74
74
|
initialize_pricing_actions()
|
|
75
|
+
from api.order_actions import initialize_order_actions
|
|
76
|
+
initialize_order_actions()
|
|
75
77
|
from api.menu_layout import initialize_menu_layout
|
|
76
78
|
initialize_menu_layout()
|
|
77
79
|
from api.list_columns import initialize_list_columns
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Order actions beyond a single document save: closing what is left open on
|
|
2
|
+
order lines and one invoice for several deliveries. REST
|
|
3
|
+
(/api/actions/...), chat and MCP."""
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
from pydantic import Field
|
|
7
|
+
|
|
8
|
+
from api import mentions, services
|
|
9
|
+
from lambda_erp import permissions
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CloseOrderLines(mentions.Input):
|
|
13
|
+
doctype: Literal["Sales Order", "Purchase Order"] = "Sales Order"
|
|
14
|
+
order: str = Field(min_length=1, max_length=200)
|
|
15
|
+
reason: str = Field(min_length=1, max_length=500)
|
|
16
|
+
lines: list[str] | None = Field(default=None, max_length=500)
|
|
17
|
+
qty: float | None = Field(default=None, gt=0)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ReopenOrderLines(mentions.Input):
|
|
21
|
+
doctype: Literal["Sales Order", "Purchase Order"] = "Sales Order"
|
|
22
|
+
order: str = Field(min_length=1, max_length=200)
|
|
23
|
+
lines: list[str] | None = Field(default=None, max_length=500)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CollectiveInvoice(mentions.Input):
|
|
27
|
+
customer: str | None = Field(default=None, max_length=200)
|
|
28
|
+
company: str | None = Field(default=None, max_length=200)
|
|
29
|
+
from_date: str | None = Field(default=None, max_length=10)
|
|
30
|
+
to_date: str | None = Field(default=None, max_length=10)
|
|
31
|
+
delivery_notes: list[str] | None = Field(default=None, max_length=500)
|
|
32
|
+
lines: list[str] | None = Field(default=None, max_length=2000)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _user_id(user):
|
|
36
|
+
return (user or {}).get("user_id") or (user or {}).get("name")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def close_lines(args, user=None):
|
|
40
|
+
data = CloseOrderLines.model_validate(args)
|
|
41
|
+
permissions.require_readable(data.doctype, data.order)
|
|
42
|
+
permissions.require(data.doctype, "update")
|
|
43
|
+
from lambda_erp.order_closing import close_order_lines
|
|
44
|
+
return close_order_lines(data.doctype, data.order, reason=data.reason, lines=data.lines, qty=data.qty,
|
|
45
|
+
closed_by=_user_id(user))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def reopen_lines(args):
|
|
49
|
+
data = ReopenOrderLines.model_validate(args)
|
|
50
|
+
permissions.require_readable(data.doctype, data.order)
|
|
51
|
+
permissions.require(data.doctype, "update")
|
|
52
|
+
from lambda_erp.order_closing import reopen_order_lines
|
|
53
|
+
return reopen_order_lines(data.doctype, data.order, lines=data.lines)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def prepare_collective_invoice(args):
|
|
57
|
+
data = CollectiveInvoice.model_validate(args)
|
|
58
|
+
permissions.require_writable("Sales Invoice", "create", keeps_hidden_fields=True)
|
|
59
|
+
permissions.require("Delivery Note", "read")
|
|
60
|
+
permissions.require_in_scope("customer", data.customer, optional=True)
|
|
61
|
+
for name in data.delivery_notes or []:
|
|
62
|
+
permissions.require_readable("Delivery Note", name)
|
|
63
|
+
from lambda_erp.stock.delivery_note import make_collective_sales_invoice
|
|
64
|
+
invoice = make_collective_sales_invoice(
|
|
65
|
+
data.customer, company=data.company, from_date=data.from_date, to_date=data.to_date,
|
|
66
|
+
delivery_notes=data.delivery_notes, lines=data.lines)
|
|
67
|
+
permissions.require_in_scope("customer", invoice.customer)
|
|
68
|
+
invoice.save()
|
|
69
|
+
return services.load_document("sales-invoice", invoice.name)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def initialize_order_actions():
|
|
73
|
+
services.register_action(
|
|
74
|
+
"close_order_lines", close_lines,
|
|
75
|
+
description=(
|
|
76
|
+
"Close what is left OPEN on lines of a SUBMITTED sales order (doctype 'Sales Order', the default) or "
|
|
77
|
+
"purchase order ('Purchase Order'): the customer cancelled the rest, or the supplier will never send it. "
|
|
78
|
+
"All lines with something open, or `lines` (row names or positions); `qty` closes only part of one "
|
|
79
|
+
"line. A reason is required. The closed quantity is no longer to deliver, receive or bill; deliveries "
|
|
80
|
+
"and invoices already posted stay as they are; a reservation for it is released. Delivered or invoiced "
|
|
81
|
+
"quantities cannot be closed. Confirm with the user which lines before closing."),
|
|
82
|
+
parameters=CloseOrderLines.model_json_schema(), minimum_role="manager", pass_user=True)
|
|
83
|
+
services.register_action(
|
|
84
|
+
"reopen_order_lines", reopen_lines,
|
|
85
|
+
description=(
|
|
86
|
+
"Undo close_order_lines on a submitted sales or purchase order: the closed quantity of `lines` (or of "
|
|
87
|
+
"every closed line) is open again. A released reservation is not restored; reserve again if needed."),
|
|
88
|
+
parameters=ReopenOrderLines.model_json_schema(), minimum_role="manager")
|
|
89
|
+
services.register_action(
|
|
90
|
+
"prepare_collective_invoice", prepare_collective_invoice,
|
|
91
|
+
description=(
|
|
92
|
+
"Create ONE DRAFT Sales Invoice for what several deliveries delivered and has not been billed yet "
|
|
93
|
+
"(monthly / collective invoice): every unbilled line of the customer's submitted delivery notes, "
|
|
94
|
+
"optionally from_date / to_date (posting dates, YYYY-MM-DD), or the named delivery_notes, or only the "
|
|
95
|
+
"delivery note lines in `lines`. Each invoice line keeps its delivery note and order line; already "
|
|
96
|
+
"billed lines are never taken again. Check what is open first with the unbilled-deliveries report. "
|
|
97
|
+
"Nothing is posted until the draft is submitted."),
|
|
98
|
+
parameters=CollectiveInvoice.model_json_schema(), minimum_role="manager")
|
|
@@ -34,7 +34,8 @@ OPENAI_PRICING: dict[str, dict[str, Any]] = {
|
|
|
34
34
|
],
|
|
35
35
|
},
|
|
36
36
|
# The models available to us, Standard tier, verified 2026-10-30 (the
|
|
37
|
-
# GPT-6.2 models 2026-11-18,
|
|
37
|
+
# GPT-6.2 models 2026-11-18, all rechecked 2026-11-24,
|
|
38
|
+
# developers.openai.com/api/docs/pricing; there is no GPT-6.1 Astra). Above
|
|
38
39
|
# 272K input tokens the higher rates apply to the entire request
|
|
39
40
|
# (including cache hits). cache_write is the 30-minute retention rate,
|
|
40
41
|
# cache_write_12h the 12-hour one.
|
|
@@ -78,14 +79,14 @@ TRANSCRIBE_PRICING: dict[str, dict[str, float]] = {
|
|
|
78
79
|
|
|
79
80
|
|
|
80
81
|
# ---------------------------------------------------------------------------
|
|
81
|
-
# Rate lookup — unknown model IDs are estimated at the gpt-6.
|
|
82
|
+
# Rate lookup — unknown model IDs are estimated at the gpt-6.1-sol rates.
|
|
82
83
|
# Register a model explicitly before using it; this fallback is not a price cap.
|
|
83
84
|
# ---------------------------------------------------------------------------
|
|
84
85
|
|
|
85
86
|
def get_openai_rates(model: str, input_tokens: int = 0) -> dict[str, float]:
|
|
86
87
|
entry = OPENAI_PRICING.get(model)
|
|
87
88
|
if entry is None:
|
|
88
|
-
entry = OPENAI_PRICING["gpt-6.
|
|
89
|
+
entry = OPENAI_PRICING["gpt-6.1-sol"]
|
|
89
90
|
if entry.get("tiered"):
|
|
90
91
|
for tier in entry["tiers"]:
|
|
91
92
|
cap = tier.get("max_input_tokens")
|
|
@@ -544,6 +544,28 @@ def purchase_backlog_report(
|
|
|
544
544
|
return _purchase_backlog(get_db(), supplier, item_code, warehouse, overdue_only)
|
|
545
545
|
|
|
546
546
|
|
|
547
|
+
def _unbilled_deliveries(db, customer=None, company=None, from_date=None, to_date=None, delivery_note=None):
|
|
548
|
+
"""Delivered and not yet invoiced, per delivery note line: what a
|
|
549
|
+
collective (monthly) invoice would bill. Selling prices only."""
|
|
550
|
+
permissions.require_artifact("report", "unbilled-deliveries")
|
|
551
|
+
permissions.require("Delivery Note", "read")
|
|
552
|
+
from lambda_erp.stock.delivery_note import unbilled_delivery_lines
|
|
553
|
+
rows = unbilled_delivery_lines(customer, company=company, from_date=from_date, to_date=to_date,
|
|
554
|
+
delivery_notes=[delivery_note] if delivery_note else None)
|
|
555
|
+
return {"rows": permissions.scope_rows("report", "unbilled-deliveries", rows)}
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
@router.get("/unbilled-deliveries")
|
|
559
|
+
def unbilled_deliveries_report(
|
|
560
|
+
customer: str | None = None,
|
|
561
|
+
company: str | None = None,
|
|
562
|
+
from_date: str | None = None,
|
|
563
|
+
to_date: str | None = None,
|
|
564
|
+
delivery_note: str | None = None,
|
|
565
|
+
):
|
|
566
|
+
return _unbilled_deliveries(get_db(), customer, company, from_date, to_date, delivery_note)
|
|
567
|
+
|
|
568
|
+
|
|
547
569
|
@router.get("/stock-detail")
|
|
548
570
|
def stock_detail(
|
|
549
571
|
item_code: str | None = None,
|
|
@@ -593,6 +593,9 @@ export const api = {
|
|
|
593
593
|
purchaseBacklog: (params?: Record<string, string>) =>
|
|
594
594
|
request<{ rows: any[] }>(`/reports/purchase-backlog${qs(params)}`),
|
|
595
595
|
|
|
596
|
+
unbilledDeliveries: (params?: Record<string, string>) =>
|
|
597
|
+
request<{ rows: any[] }>(`/reports/unbilled-deliveries${qs(params)}`),
|
|
598
|
+
|
|
596
599
|
stockAvailability: (params?: Record<string, string>) =>
|
|
597
600
|
request<{ rows: any[] }>(`/reports/stock-availability${qs(params)}`),
|
|
598
601
|
|
|
@@ -12,7 +12,8 @@ Per sales order line:
|
|
|
12
12
|
returned how much of what was delivered came back
|
|
13
13
|
billed invoiced, net of credit notes for returned goods
|
|
14
14
|
reserved still held by the line's stock reservation
|
|
15
|
-
|
|
15
|
+
closed closed by hand: will not be delivered (order_closing.py)
|
|
16
|
+
open ordered - closed - delivered
|
|
16
17
|
|
|
17
18
|
See docs/order-progress-and-backlog.md.
|
|
18
19
|
"""
|
|
@@ -27,7 +28,8 @@ EPSILON = 1e-9
|
|
|
27
28
|
|
|
28
29
|
def _open_purchase_lines(item_codes=None, supplier=None, item_code=None, warehouse=None):
|
|
29
30
|
db = get_db()
|
|
30
|
-
where = ["p.docstatus = 1", "COALESCE(p.discarded, 0) = 0",
|
|
31
|
+
where = ["p.docstatus = 1", "COALESCE(p.discarded, 0) = 0",
|
|
32
|
+
"i.qty - COALESCE(i.closed_qty, 0) > COALESCE(i.received_qty, 0) + 1e-9"]
|
|
31
33
|
params = []
|
|
32
34
|
if item_codes is not None:
|
|
33
35
|
if not item_codes:
|
|
@@ -41,7 +43,7 @@ def _open_purchase_lines(item_codes=None, supplier=None, item_code=None, warehou
|
|
|
41
43
|
return db.sql(
|
|
42
44
|
'SELECT p.name AS purchase_order, p.supplier, p.supplier_name, p.transaction_date, p.schedule_date, '
|
|
43
45
|
'i.name AS purchase_order_item, i.idx, i.item_code, i.item_name, i.warehouse, i.qty, '
|
|
44
|
-
'COALESCE(i.received_qty, 0) AS received_qty, i.confirmed_date, i.confirmed_qty, '
|
|
46
|
+
'COALESCE(i.received_qty, 0) AS received_qty, COALESCE(i.closed_qty, 0) AS closed_qty, i.confirmed_date, i.confirmed_qty, '
|
|
45
47
|
'i.confirmation_reference '
|
|
46
48
|
'FROM "Purchase Order Item" i JOIN "Purchase Order" p ON p.name = i.parent '
|
|
47
49
|
f'WHERE {" AND ".join(where)} ORDER BY p.transaction_date, p.name, i.idx', params)
|
|
@@ -64,7 +66,8 @@ def sales_backlog(customer=None, item_code=None, warehouse=None, sales_order=Non
|
|
|
64
66
|
from lambda_erp.stock.reservation import availability_rows
|
|
65
67
|
|
|
66
68
|
db = get_db()
|
|
67
|
-
where = ["o.docstatus = 1", "COALESCE(o.discarded, 0) = 0",
|
|
69
|
+
where = ["o.docstatus = 1", "COALESCE(o.discarded, 0) = 0",
|
|
70
|
+
"i.qty - COALESCE(i.closed_qty, 0) > COALESCE(i.delivered_qty, 0) + 1e-9"]
|
|
68
71
|
params = []
|
|
69
72
|
for column, value in (("o.customer", customer), ("i.item_code", item_code), ("i.warehouse", warehouse),
|
|
70
73
|
("o.name", sales_order)):
|
|
@@ -79,7 +82,7 @@ def sales_backlog(customer=None, item_code=None, warehouse=None, sales_order=Non
|
|
|
79
82
|
'SELECT o.name AS sales_order, o.customer, o.customer_name, o.transaction_date, o.delivery_date, '
|
|
80
83
|
'i.name AS sales_order_item, i.idx, i.item_code, i.item_name, i.warehouse, i.qty AS ordered_qty, '
|
|
81
84
|
'COALESCE(i.delivered_qty, 0) AS delivered_qty, COALESCE(i.returned_qty, 0) AS returned_qty, '
|
|
82
|
-
'COALESCE(i.billed_qty, 0) AS billed_qty, '
|
|
85
|
+
'COALESCE(i.billed_qty, 0) AS billed_qty, COALESCE(i.closed_qty, 0) AS closed_qty, '
|
|
83
86
|
f'COALESCE((SELECT SUM({held}) FROM "Stock Reservation" r WHERE r.sales_order_item = i.name '
|
|
84
87
|
"AND r.status IN ('Reserved', 'Partially Delivered') AND COALESCE(r.discarded, 0) = 0), 0) AS reserved_qty "
|
|
85
88
|
'FROM "Sales Order Item" i JOIN "Sales Order" o ON o.name = i.parent '
|
|
@@ -98,7 +101,7 @@ def sales_backlog(customer=None, item_code=None, warehouse=None, sales_order=Non
|
|
|
98
101
|
if key not in free:
|
|
99
102
|
rows = availability_rows(line["item_code"], line["warehouse"]) if line["warehouse"] else []
|
|
100
103
|
free[key] = rows[0].available_qty if rows else 0.0
|
|
101
|
-
open_qty = flt(line["ordered_qty"]) - flt(line["delivered_qty"])
|
|
104
|
+
open_qty = flt(line["ordered_qty"]) - flt(line["closed_qty"]) - flt(line["delivered_qty"])
|
|
102
105
|
reserved = min(flt(line["reserved_qty"]), open_qty)
|
|
103
106
|
from_free = min(open_qty - reserved, free[key])
|
|
104
107
|
free[key] -= from_free
|
|
@@ -107,15 +110,16 @@ def sales_backlog(customer=None, item_code=None, warehouse=None, sales_order=Non
|
|
|
107
110
|
continue
|
|
108
111
|
entry = {**dict(line), "ordered_qty": flt(line["ordered_qty"]), "delivered_qty": flt(line["delivered_qty"]),
|
|
109
112
|
"returned_qty": flt(line["returned_qty"]), "billed_qty": flt(line["billed_qty"]),
|
|
113
|
+
"closed_qty": flt(line["closed_qty"]),
|
|
110
114
|
"open_qty": open_qty, "reserved_qty": reserved, "deliverable_qty": deliverable,
|
|
111
115
|
"short_qty": max(0.0, open_qty - deliverable)}
|
|
112
116
|
if with_purchase_orders:
|
|
113
117
|
orders = incoming.get(key, [])
|
|
114
118
|
dated = sorted((str(_expected_date(row))[:10] for row in orders if _expected_date(row)))
|
|
115
|
-
entry["on_purchase_order_qty"] = sum(flt(row["qty"]) - flt(row["received_qty"]) for row in orders)
|
|
119
|
+
entry["on_purchase_order_qty"] = sum(flt(row["qty"]) - flt(row["closed_qty"]) - flt(row["received_qty"]) for row in orders)
|
|
116
120
|
entry["next_expected_date"] = dated[0] if dated else None
|
|
117
121
|
entry["purchase_orders"] = [
|
|
118
|
-
{"purchase_order": row["purchase_order"], "open_qty": flt(row["qty"]) - flt(row["received_qty"]),
|
|
122
|
+
{"purchase_order": row["purchase_order"], "open_qty": flt(row["qty"]) - flt(row["closed_qty"]) - flt(row["received_qty"]),
|
|
119
123
|
"confirmed_date": row.get("confirmed_date") or None,
|
|
120
124
|
"schedule_date": row.get("schedule_date") or None,
|
|
121
125
|
"confirmation_reference": row.get("confirmation_reference") or None}
|
|
@@ -136,7 +140,8 @@ def purchase_backlog(supplier=None, item_code=None, warehouse=None, overdue_only
|
|
|
136
140
|
if overdue_only and not overdue:
|
|
137
141
|
continue
|
|
138
142
|
result.append({**dict(row), "qty": flt(row["qty"]), "received_qty": flt(row["received_qty"]),
|
|
139
|
-
"
|
|
143
|
+
"closed_qty": flt(row["closed_qty"]),
|
|
144
|
+
"open_qty": flt(row["qty"]) - flt(row["closed_qty"]) - flt(row["received_qty"]),
|
|
140
145
|
"confirmed_qty": flt(row["confirmed_qty"]) if row.get("confirmed_qty") is not None else None,
|
|
141
146
|
"expected_date": str(expected)[:10] if expected else None,
|
|
142
147
|
"confirmed": bool(row.get("confirmed_date")), "overdue": overdue,
|
|
@@ -175,7 +180,8 @@ def confirm_purchase_order_lines(purchase_order, confirmed_date, *, lines=None,
|
|
|
175
180
|
if len(chosen) != len(wanted):
|
|
176
181
|
raise ValidationError(f"Purchase Order {purchase_order} has no line(s) {', '.join(sorted(wanted))}")
|
|
177
182
|
else:
|
|
178
|
-
chosen = [row for row in rows
|
|
183
|
+
chosen = [row for row in rows
|
|
184
|
+
if flt(row.get("qty")) - flt(row.get("closed_qty")) > flt(row.get("received_qty")) + EPSILON]
|
|
179
185
|
if not chosen:
|
|
180
186
|
raise ValidationError(f"Purchase Order {purchase_order} has no open lines to confirm")
|
|
181
187
|
if confirmed_qty is not None:
|
|
@@ -193,4 +199,5 @@ def confirm_purchase_order_lines(purchase_order, confirmed_date, *, lines=None,
|
|
|
193
199
|
db.set_value("Purchase Order", purchase_order, "modified", stamp)
|
|
194
200
|
return {"purchase_order": purchase_order, "confirmed_date": date,
|
|
195
201
|
"lines": [{"purchase_order_item": row["name"], "idx": row.get("idx"), "item_code": row.get("item_code"),
|
|
196
|
-
"open_qty": flt(row.get("qty")) - flt(row.get("
|
|
202
|
+
"open_qty": flt(row.get("qty")) - flt(row.get("closed_qty")) - flt(row.get("received_qty"))}
|
|
203
|
+
for row in chosen]}
|
|
@@ -54,6 +54,8 @@ class PurchaseOrder(Document):
|
|
|
54
54
|
raise ValidationError("At least one item is required")
|
|
55
55
|
if not self.transaction_date:
|
|
56
56
|
self.transaction_date = nowdate()
|
|
57
|
+
from lambda_erp.order_closing import reset_draft_closings
|
|
58
|
+
reset_draft_closings(self)
|
|
57
59
|
|
|
58
60
|
apply_external_source_defaults(self)
|
|
59
61
|
self._set_supplier_name()
|
|
@@ -108,7 +110,7 @@ def make_purchase_invoice(purchase_order_name):
|
|
|
108
110
|
)
|
|
109
111
|
|
|
110
112
|
for item in po.get("items"):
|
|
111
|
-
unbilled = flt(item.get("qty")) - flt(item.get("billed_qty"))
|
|
113
|
+
unbilled = flt(item.get("qty")) - flt(item.get("closed_qty")) - flt(item.get("billed_qty"))
|
|
112
114
|
if unbilled <= 0:
|
|
113
115
|
continue
|
|
114
116
|
|
|
@@ -3882,6 +3882,17 @@ def _m070_chat_manual_title(db: "Database") -> None:
|
|
|
3882
3882
|
db.ensure_column("Chat Session", "title_is_manual", "INTEGER NOT NULL DEFAULT 0")
|
|
3883
3883
|
|
|
3884
3884
|
|
|
3885
|
+
def _m071_order_line_closing(db: "Database") -> None:
|
|
3886
|
+
"""Closing what is left open on an order line (see
|
|
3887
|
+
docs/order-progress-and-backlog.md): how much of the line will not be
|
|
3888
|
+
delivered / received any more, why, who closed it and when. Nothing is
|
|
3889
|
+
closed by the migration."""
|
|
3890
|
+
for table in ("Sales Order Item", "Purchase Order Item"):
|
|
3891
|
+
db.ensure_column(table, "closed_qty", "REAL DEFAULT 0")
|
|
3892
|
+
for column in ("close_reason", "closed_by", "closed_at"):
|
|
3893
|
+
db.ensure_column(table, column, "TEXT")
|
|
3894
|
+
|
|
3895
|
+
|
|
3885
3896
|
Database.MIGRATIONS = [
|
|
3886
3897
|
(1, "chat_message_session_id", _m001_chat_message_session_id),
|
|
3887
3898
|
(2, "chat_session_user_id", _m002_chat_session_user_id),
|
|
@@ -3953,6 +3964,7 @@ Database.MIGRATIONS = [
|
|
|
3953
3964
|
(68, "units_completed", _m068_units_completed),
|
|
3954
3965
|
(69, "chat_attachment_data", _m069_chat_attachment_data),
|
|
3955
3966
|
(70, "chat_manual_title", _m070_chat_manual_title),
|
|
3967
|
+
(71, "order_line_closing", _m071_order_line_closing),
|
|
3956
3968
|
]
|
|
3957
3969
|
|
|
3958
3970
|
|