lambda-erp 1.4.14__tar.gz → 1.4.15__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.14 → lambda_erp-1.4.15}/PKG-INFO +1 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/auth.py +1 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/chat.py +11 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/analytics.py +37 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/reports.py +31 -3
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/services.py +75 -4
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/permissions.py +18 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/stock_ledger.py +10 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/pyproject.toml +1 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/.gitignore +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/LICENSE +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/README.md +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/attachments.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/chat_links.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/deps.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/erp_context.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/errors.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/list_values.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/main.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/mentions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/oauth.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/providers.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/record_notes.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/document.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/record.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/time_filters.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/api/write_context.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/frontend/README.md +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/database.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.15}/terraform/README.md +0 -0
|
@@ -583,6 +583,7 @@ def _describe_restrictions(user):
|
|
|
583
583
|
if not permissions.can(doctype, "read"))
|
|
584
584
|
names = {route.path.rsplit("/", 1)[-1] for route in reports.router.routes
|
|
585
585
|
if getattr(route, "path", "").startswith("/reports/") and "{" not in route.path}
|
|
586
|
+
names |= set(services.REGISTERED_REPORTS)
|
|
586
587
|
described["denied_reports"] = sorted(name for name in names if permissions.artifact_denied("report", name))
|
|
587
588
|
return described
|
|
588
589
|
|
|
@@ -1568,7 +1568,8 @@ def build_tools(user_info: dict | None = None, *, native_chat: bool = False):
|
|
|
1568
1568
|
tool["function"]["name"] for tool in TOOLS
|
|
1569
1569
|
if not tool_allowed(tool["function"]["name"], role)
|
|
1570
1570
|
}
|
|
1571
|
-
|
|
1571
|
+
extra_reports = list(services.REGISTERED_REPORTS)
|
|
1572
|
+
if not extra_docs and not extra_masters and not action_tools and not hidden_tools and not extra_reports:
|
|
1572
1573
|
return TOOLS
|
|
1573
1574
|
tools = copy.deepcopy(TOOLS)
|
|
1574
1575
|
if hidden_tools:
|
|
@@ -1580,6 +1581,12 @@ def build_tools(user_info: dict | None = None, *, native_chat: bool = False):
|
|
|
1580
1581
|
schema["enum"] = DOCUMENT_SLUGS + extra_docs
|
|
1581
1582
|
elif schema.get("enum") == MASTER_TYPES:
|
|
1582
1583
|
schema["enum"] = MASTER_TYPES + extra_masters
|
|
1584
|
+
if extra_reports and tool["function"]["name"] == "get_report":
|
|
1585
|
+
props["report_type"]["enum"] = props["report_type"]["enum"] + extra_reports
|
|
1586
|
+
tool["function"]["description"] += " Reports of this deployment: " + "; ".join(
|
|
1587
|
+
f"{name}: {meta['description']}"
|
|
1588
|
+
+ (f" Filters: {', '.join(f'{k} ({v})' for k, v in meta['filters'].items())}." if meta["filters"] else "")
|
|
1589
|
+
for name, meta in services.REGISTERED_REPORTS.items())
|
|
1583
1590
|
existing_names = {tool["function"]["name"] for tool in tools}
|
|
1584
1591
|
tools.extend(tool for tool in action_tools if tool["function"]["name"] not in existing_names)
|
|
1585
1592
|
return tools
|
|
@@ -2065,6 +2072,9 @@ def _handle_get_report(args):
|
|
|
2065
2072
|
elif report_type == "ap-aging":
|
|
2066
2073
|
from api.routers.reports import _ap_aging
|
|
2067
2074
|
return _ap_aging(db, filters.get("company"), filters.get("as_of_date"))
|
|
2075
|
+
if report_type in services.REGISTERED_REPORTS:
|
|
2076
|
+
from lambda_erp import permissions
|
|
2077
|
+
return services.run_registered_report(report_type, filters, permissions.current_principal())
|
|
2068
2078
|
return {"error": f"Unknown report type: {report_type}"}
|
|
2069
2079
|
|
|
2070
2080
|
|
|
@@ -252,6 +252,43 @@ METRICS: dict[str, dict[str, Any]] = {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
|
|
255
|
+
_UNSET = object()
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def register_dataset(name: str, spec: dict, *, sensitivity=_UNSET, hidden_fields: dict | None = None,
|
|
259
|
+
scope: dict | None = None) -> None:
|
|
260
|
+
"""Plugin seam: add a dataset to the report runtime and the query_dataset
|
|
261
|
+
tool. ``spec`` has the shape of the entries of SEMANTIC_DATASETS (label,
|
|
262
|
+
description, sql_from, fields, field_sql, default_where, filter_fields,
|
|
263
|
+
default_limit, max_limit, default_order_by).
|
|
264
|
+
|
|
265
|
+
``sensitivity`` must be given: a sensitivity class (the whole dataset is
|
|
266
|
+
refused for a user it is hidden from) or None. ``hidden_fields``
|
|
267
|
+
({field: class}) hides single columns. ``scope`` gives, per record scope
|
|
268
|
+
dimension, the SQL expression of the field that carries it, a condition
|
|
269
|
+
with ``{values}``, or None when the dataset has nothing to do with it; a
|
|
270
|
+
dataset that does not say is refused for a user restricted to assigned
|
|
271
|
+
records.
|
|
272
|
+
"""
|
|
273
|
+
if sensitivity is _UNSET:
|
|
274
|
+
raise ValueError(f"register_dataset({name!r}): say sensitivity=<class> or sensitivity=None")
|
|
275
|
+
missing = [key for key in ("label", "sql_from", "fields", "field_sql") if not spec.get(key)]
|
|
276
|
+
if missing:
|
|
277
|
+
raise ValueError(f"Dataset {name}: spec lacks {', '.join(missing)}")
|
|
278
|
+
if set(spec["fields"]) != set(spec["field_sql"]):
|
|
279
|
+
raise ValueError(f"Dataset {name}: fields and field_sql must name the same fields")
|
|
280
|
+
if name in SEMANTIC_DATASETS and not SEMANTIC_DATASETS[name].get("registered"):
|
|
281
|
+
raise ValueError(f"Dataset name {name!r} is a core dataset")
|
|
282
|
+
if sensitivity is not None or hidden_fields:
|
|
283
|
+
permissions.register_sensitive_artifact("dataset", name, sensitivity, hidden_fields)
|
|
284
|
+
if scope:
|
|
285
|
+
permissions.register_scoped_artifact("dataset", name, **scope)
|
|
286
|
+
SEMANTIC_DATASETS[name] = {
|
|
287
|
+
"description": "", "default_where": [], "default_limit": 500, "max_limit": 5000,
|
|
288
|
+
"default_order_by": f"{next(iter(spec['field_sql'].values()))} ASC",
|
|
289
|
+
**spec, "filter_fields": set(spec.get("filter_fields") or ()), "registered": True}
|
|
290
|
+
|
|
291
|
+
|
|
255
292
|
def visible_dataset(name: str):
|
|
256
293
|
"""The dataset as the current caller may use it: None if unknown, refused
|
|
257
294
|
if their access profile denies it, and without the columns it hides (so
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from datetime import date
|
|
4
4
|
|
|
5
|
-
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
5
|
+
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
|
6
6
|
from lambda_erp.database import get_db
|
|
7
7
|
from lambda_erp.utils import flt, nowdate
|
|
8
8
|
from lambda_erp.controllers.currency import get_exchange_rate
|
|
@@ -462,8 +462,13 @@ def _stock_detail(db, item_code=None, warehouse=None, location=None, batch_no=No
|
|
|
462
462
|
+ _STOCK_DETAIL_FROM
|
|
463
463
|
+ (f"WHERE {' AND '.join(where)} " if where else "")
|
|
464
464
|
+ 'ORDER BY d.item_code, d.warehouse, d.location, b.expiry_date, d.batch_no', params)
|
|
465
|
-
|
|
466
|
-
"report", "stock-detail", [{**dict(row), "actual_qty": flt(row["actual_qty"])} for row in rows])
|
|
465
|
+
rows = permissions.scope_rows(
|
|
466
|
+
"report", "stock-detail", [{**dict(row), "actual_qty": flt(row["actual_qty"])} for row in rows])
|
|
467
|
+
# A deployment adds its own values per row here (a batch attribute, say);
|
|
468
|
+
# the rows are already limited to what the caller may see.
|
|
469
|
+
from lambda_erp.hooks import run_hooks
|
|
470
|
+
run_hooks("Report:stock-detail", rows)
|
|
471
|
+
return {"rows": rows}
|
|
467
472
|
|
|
468
473
|
|
|
469
474
|
def _stock_availability(db, item_code=None, warehouse=None, item_prefix=None):
|
|
@@ -1219,3 +1224,26 @@ def ap_aging(
|
|
|
1219
1224
|
as_of_date: str | None = None,
|
|
1220
1225
|
):
|
|
1221
1226
|
return _ap_aging(get_db(), company, as_of_date)
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
@router.get("/registered")
|
|
1230
|
+
def registered_reports():
|
|
1231
|
+
"""The reports a deployment has registered that the caller may open."""
|
|
1232
|
+
from api import services
|
|
1233
|
+
return {"reports": [{"name": name, "description": meta["description"], "filters": meta["filters"]}
|
|
1234
|
+
for name, meta in services.REGISTERED_REPORTS.items()
|
|
1235
|
+
if not permissions.artifact_denied("report", name)]}
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
@router.get("/registered/{name}")
|
|
1239
|
+
def registered_report(name: str, request: Request, user: dict = Depends(require_role("viewer"))):
|
|
1240
|
+
from api import services
|
|
1241
|
+
if name not in services.REGISTERED_REPORTS:
|
|
1242
|
+
raise HTTPException(status_code=404, detail=f"Unknown report: {name}")
|
|
1243
|
+
try:
|
|
1244
|
+
return services.run_registered_report(name, dict(request.query_params), user)
|
|
1245
|
+
except PermissionError as exc:
|
|
1246
|
+
raise HTTPException(status_code=403, detail=str(exc))
|
|
1247
|
+
except ValueError as exc:
|
|
1248
|
+
raise HTTPException(status_code=422, detail=str(exc))
|
|
1249
|
+
|
|
@@ -198,14 +198,19 @@ def register_table(ddl: str) -> None:
|
|
|
198
198
|
_PLUGIN_TABLES.append(ddl)
|
|
199
199
|
|
|
200
200
|
|
|
201
|
-
def register_migration(migration_id: str, fn) -> None:
|
|
201
|
+
def register_migration(migration_id: str, fn, *, required: bool = False) -> None:
|
|
202
202
|
"""Register a one-shot migration run exactly once per database, recorded in
|
|
203
203
|
_PluginMigrations by `migration_id` (namespace it, e.g. "internal:0001_x").
|
|
204
204
|
`fn(db)` receives the DB; use db.ensure_column(...) for idempotent ALTERs
|
|
205
205
|
and plain db.sql(...) for backfills. Runs after registered tables exist, in
|
|
206
206
|
registration order. Must be idempotent and self-contained (single logical
|
|
207
|
-
unit — it commits on success).
|
|
208
|
-
|
|
207
|
+
unit — it commits on success).
|
|
208
|
+
|
|
209
|
+
A failing migration is rolled back and retried on the next start; the
|
|
210
|
+
server starts anyway. With ``required=True`` it stops the start instead,
|
|
211
|
+
and no later migration runs: use it for a migration the plugin's code
|
|
212
|
+
cannot work without (a column it reads, a table it writes)."""
|
|
213
|
+
_PLUGIN_MIGRATIONS.append((migration_id, fn, bool(required)))
|
|
209
214
|
|
|
210
215
|
|
|
211
216
|
def apply_plugin_schema() -> None:
|
|
@@ -230,7 +235,7 @@ def apply_plugin_schema() -> None:
|
|
|
230
235
|
db.conn.commit()
|
|
231
236
|
applied = {r["migration_id"] for r in db.sql('SELECT migration_id FROM "_PluginMigrations"')}
|
|
232
237
|
|
|
233
|
-
for migration_id, fn in _PLUGIN_MIGRATIONS:
|
|
238
|
+
for migration_id, fn, required in _PLUGIN_MIGRATIONS:
|
|
234
239
|
if migration_id in applied:
|
|
235
240
|
continue
|
|
236
241
|
try:
|
|
@@ -243,6 +248,11 @@ def apply_plugin_schema() -> None:
|
|
|
243
248
|
print(f"[plugin-migration] applied {migration_id}", flush=True)
|
|
244
249
|
except Exception as e:
|
|
245
250
|
db.conn.rollback()
|
|
251
|
+
if required:
|
|
252
|
+
print(f"[plugin-migration] FAILED {migration_id}: {e!r} — required, stopping startup", flush=True)
|
|
253
|
+
raise RuntimeError(
|
|
254
|
+
f"Required plugin migration {migration_id} failed: {e!r}. Nothing of it was applied; "
|
|
255
|
+
f"fix the cause and start again") from e
|
|
246
256
|
print(f"[plugin-migration] FAILED {migration_id}: {e!r} — will retry next boot", flush=True)
|
|
247
257
|
|
|
248
258
|
db._ensure_list_indexes()
|
|
@@ -308,6 +318,67 @@ def register_master(slug: str, table: str, name_field: str, *,
|
|
|
308
318
|
MASTER_REFERENCE_CHECKS[slug] = list(reference_checks)
|
|
309
319
|
|
|
310
320
|
|
|
321
|
+
# --- Registered reports ----------------------------------------------------
|
|
322
|
+
#
|
|
323
|
+
# A deployment's own report: registered once, served at
|
|
324
|
+
# GET /api/reports/registered/{name} and through the get_report chat / MCP
|
|
325
|
+
# tool, with the access rules applied before the handler runs.
|
|
326
|
+
|
|
327
|
+
REGISTERED_REPORTS: dict[str, dict] = {}
|
|
328
|
+
_REPORT_NAME_RE = re.compile(r"^[a-z][a-z0-9-]*$")
|
|
329
|
+
_UNSET = object()
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def register_report(name: str, handler, *, description: str, filters: dict | None = None,
|
|
333
|
+
sensitivity=_UNSET, scope: dict | None = None, minimum_role: str = "viewer") -> None:
|
|
334
|
+
"""Register a report across REST, chat and MCP.
|
|
335
|
+
|
|
336
|
+
``handler(filters: dict)`` returns a JSON-compatible dict, by convention
|
|
337
|
+
``{"rows": [...]}``. ``filters`` describes the accepted filter keys
|
|
338
|
+
({key: description}) for the chat prompt; unknown keys are refused.
|
|
339
|
+
|
|
340
|
+
``sensitivity`` must be given: a sensitivity class (the report is refused
|
|
341
|
+
for a user it is hidden from) or None when it shows nothing of them.
|
|
342
|
+
``scope`` says how the report relates to record scope, per dimension
|
|
343
|
+
(see permissions.register_scoped_artifact); a report that does not say is
|
|
344
|
+
refused for a user restricted to assigned records. The handler applies
|
|
345
|
+
the row limits itself (permissions.scope_rows / scope_sql).
|
|
346
|
+
"""
|
|
347
|
+
if not _REPORT_NAME_RE.fullmatch(name):
|
|
348
|
+
raise ValueError(f"Invalid report name: {name!r} (lowercase letters, digits and hyphens)")
|
|
349
|
+
if sensitivity is _UNSET:
|
|
350
|
+
raise ValueError(f"register_report({name!r}): say sensitivity=<class> or sensitivity=None")
|
|
351
|
+
if minimum_role not in _ROLE_LEVEL:
|
|
352
|
+
raise ValueError(f"Invalid minimum report role: {minimum_role!r}")
|
|
353
|
+
from api.routers import reports as core_reports
|
|
354
|
+
taken = {route.path.rsplit("/", 1)[-1] for route in core_reports.router.routes
|
|
355
|
+
if "{" not in getattr(route, "path", "")}
|
|
356
|
+
if name in taken:
|
|
357
|
+
raise ValueError(f"Report name {name!r} is a core report")
|
|
358
|
+
if sensitivity is not None:
|
|
359
|
+
permissions.register_sensitive_artifact("report", name, sensitivity)
|
|
360
|
+
if scope:
|
|
361
|
+
permissions.register_scoped_artifact("report", name, **scope)
|
|
362
|
+
REGISTERED_REPORTS[name] = {"handler": handler, "description": description,
|
|
363
|
+
"filters": dict(filters or {}), "minimum_role": minimum_role}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def run_registered_report(name: str, filters: dict | None = None, user_info: dict | None = None):
|
|
367
|
+
meta = REGISTERED_REPORTS.get(name)
|
|
368
|
+
if not meta:
|
|
369
|
+
raise ValueError(f"Unknown report: {name}")
|
|
370
|
+
role = (user_info or {}).get("role")
|
|
371
|
+
if user_info is not None and _ROLE_LEVEL.get(role or "", 0) < _ROLE_LEVEL[meta["minimum_role"]]:
|
|
372
|
+
raise PermissionError(f"Report {name} requires {meta['minimum_role']} role or higher")
|
|
373
|
+
permissions.require_artifact("report", name)
|
|
374
|
+
filters = {key: value for key, value in (filters or {}).items() if value not in (None, "")}
|
|
375
|
+
unknown = sorted(set(filters) - set(meta["filters"]))
|
|
376
|
+
if unknown:
|
|
377
|
+
raise ValueError(f"Report {name} has no filter {', '.join(unknown)}. "
|
|
378
|
+
f"Filters: {', '.join(sorted(meta['filters'])) or 'none'}")
|
|
379
|
+
return meta["handler"](filters)
|
|
380
|
+
|
|
381
|
+
|
|
311
382
|
# --- Registered actions ----------------------------------------------------
|
|
312
383
|
#
|
|
313
384
|
# Plugins sometimes need one deliberate transition that is richer than CRUD
|
|
@@ -533,6 +533,24 @@ def load_restrictions(profile_name, record_scope=None):
|
|
|
533
533
|
return {"profile": profile_name, "hidden": expand_classes(classes), "permissions": permissions, "scope": scope}
|
|
534
534
|
|
|
535
535
|
|
|
536
|
+
def ensure_access_profile(name, *, description=None, hidden_classes=(), permissions=None):
|
|
537
|
+
"""Plugin seam: make sure an access profile exists, for a deployment that
|
|
538
|
+
ships its own (a "Field sales", a "Counter"). Creates it when missing and
|
|
539
|
+
returns True; an existing profile is left exactly as the admins have it.
|
|
540
|
+
Call it from a registered migration or at startup after the schema."""
|
|
541
|
+
from lambda_erp.database import get_db
|
|
542
|
+
from lambda_erp.utils import now
|
|
543
|
+
|
|
544
|
+
db = get_db()
|
|
545
|
+
if db.exists("Access Profile", name):
|
|
546
|
+
return False
|
|
547
|
+
classes, rules = validate_profile(list(hidden_classes), permissions)
|
|
548
|
+
db.insert("Access Profile", {"name": name, "description": description, "hidden_classes": json.dumps(classes),
|
|
549
|
+
"permissions": json.dumps(rules), "disabled": 0,
|
|
550
|
+
"creation": now(), "modified": now()})
|
|
551
|
+
return True
|
|
552
|
+
|
|
553
|
+
|
|
536
554
|
# -- checks -------------------------------------------------------------------
|
|
537
555
|
|
|
538
556
|
def _hidden(cls, restrictions):
|
|
@@ -25,6 +25,7 @@ The flow:
|
|
|
25
25
|
|
|
26
26
|
from lambda_erp.utils import _dict, flt, new_name, now, nowdate
|
|
27
27
|
from lambda_erp.database import get_db
|
|
28
|
+
from lambda_erp.hooks import run_hooks
|
|
28
29
|
from lambda_erp.exceptions import NegativeStockError, ValidationError
|
|
29
30
|
|
|
30
31
|
def make_sl_entries(sl_entries, allow_negative_stock=False):
|
|
@@ -51,6 +52,11 @@ def make_sl_entries(sl_entries, allow_negative_stock=False):
|
|
|
51
52
|
from lambda_erp.stock import serial as serial_numbers
|
|
52
53
|
serials = serial_numbers.resolve_entry_serials(sle)
|
|
53
54
|
serial_numbers.check_leaving_serials(sle, serials, batch_no, location)
|
|
55
|
+
# A deployment's own stock rule: sees the movement with its resolved
|
|
56
|
+
# batch, storage location and serial numbers before anything is
|
|
57
|
+
# posted; raising refuses it and rolls the document back.
|
|
58
|
+
run_hooks("Stock Ledger Entry:before_post", _dict({
|
|
59
|
+
**sle, "batch_no": batch_no or None, "location": location or None, "serial_numbers": list(serials)}))
|
|
54
60
|
|
|
55
61
|
# Create the SLE record
|
|
56
62
|
sle_doc = _dict(
|
|
@@ -89,6 +95,7 @@ def make_sl_entries(sl_entries, allow_negative_stock=False):
|
|
|
89
95
|
update_stock_balance_detail(sle_doc, batch_no, allow_negative_stock, location)
|
|
90
96
|
# Each serial-numbered unit moves with the entry (stock/serial.py).
|
|
91
97
|
serial_numbers.apply_entry_serials(sle_doc, serials, batch_no, location)
|
|
98
|
+
run_hooks("Stock Ledger Entry:after_post", sle_doc)
|
|
92
99
|
|
|
93
100
|
if not db._in_transaction:
|
|
94
101
|
db.commit()
|
|
@@ -236,6 +243,9 @@ def resolve_entry_batch(sle):
|
|
|
236
243
|
break
|
|
237
244
|
db.insert("Batch", _dict(name=name, batch_no=batch_no, item_code=item_code, expiry_date=expiry,
|
|
238
245
|
disabled=0, creation=now(), modified=now()))
|
|
246
|
+
# A deployment with its own batch attributes (columns it added to Batch)
|
|
247
|
+
# fills them here from the receiving entry.
|
|
248
|
+
run_hooks("Batch:created", db.get_all("Batch", filters={"name": name}, fields=["*"])[0], sle)
|
|
239
249
|
return batch_no
|
|
240
250
|
|
|
241
251
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|