lambda-erp 1.4.14__tar.gz → 1.4.16__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.16}/PKG-INFO +1 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/auth.py +9 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/chat.py +13 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/analytics.py +37 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/masters.py +1 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/reports.py +31 -3
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/services.py +79 -5
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/price_resolution.py +1 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/pricing_rule.py +2 -2
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/database.py +26 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/permissions.py +18 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/delivery_note.py +14 -15
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/purchase_receipt.py +74 -15
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/reservation.py +167 -17
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/stock_ledger.py +10 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/workflow.py +54 -33
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/pyproject.toml +1 -1
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/.gitignore +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/LICENSE +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/README.md +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/attachments.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/chat_links.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/deps.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/erp_context.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/errors.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/list_values.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/main.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/mentions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/oauth.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/providers.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/record_notes.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/document.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/record.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/time_filters.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/api/write_context.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/frontend/README.md +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.14 → lambda_erp-1.4.16}/terraform/README.md +0 -0
|
@@ -583,6 +583,15 @@ 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)
|
|
587
|
+
# Fields hidden on document types the user can open, so a form does
|
|
588
|
+
# not show inputs for them: {slug: {"" | child key: [field, ...]}}.
|
|
589
|
+
hidden = {}
|
|
590
|
+
for slug, doctype in services.SLUG_TO_DOCTYPE.items():
|
|
591
|
+
plan = permissions.hidden_write_plan(doctype)
|
|
592
|
+
if plan and permissions.can(doctype, "read"):
|
|
593
|
+
hidden[slug] = {child: sorted(fields) for child, fields in plan.items()}
|
|
594
|
+
described["hidden_fields"] = hidden
|
|
586
595
|
described["denied_reports"] = sorted(name for name in names if permissions.artifact_denied("report", name))
|
|
587
596
|
return described
|
|
588
597
|
|
|
@@ -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
|
|
|
@@ -2999,6 +3009,8 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
2999
3009
|
- 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.
|
|
3000
3010
|
- 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.
|
|
3001
3011
|
- 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.
|
|
3012
|
+
- 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.
|
|
3013
|
+
- 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.
|
|
3002
3014
|
- "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.
|
|
3003
3015
|
- When a supplier's order confirmation arrives, record its date with the `confirm_purchase_order` action.
|
|
3004
3016
|
|
|
@@ -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
|
|
@@ -221,6 +221,7 @@ def _normalize_master_data(data: dict) -> dict:
|
|
|
221
221
|
|
|
222
222
|
MASTER_LINK_FIELDS = {
|
|
223
223
|
'customer': {'default_price_list': 'Price List'},
|
|
224
|
+
'supplier': {'default_price_list': 'Price List'},
|
|
224
225
|
'company': {'default_price_list': 'Price List'},
|
|
225
226
|
'item': {'default_warehouse': 'Warehouse'},
|
|
226
227
|
'warehouse': {'company': 'Company', 'account': 'Account', 'parent_warehouse': 'Warehouse',
|
|
@@ -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
|
+
|
|
@@ -23,7 +23,9 @@ from lambda_erp.stock.stock_entry import StockEntry
|
|
|
23
23
|
from lambda_erp.stock.delivery_note import (
|
|
24
24
|
DeliveryNote, make_delivery_note, make_delivery_return, make_sales_invoice_from_delivery_note,
|
|
25
25
|
)
|
|
26
|
-
from lambda_erp.stock.purchase_receipt import
|
|
26
|
+
from lambda_erp.stock.purchase_receipt import (
|
|
27
|
+
PurchaseReceipt, make_purchase_receipt, make_purchase_receipt_return, make_purchase_invoice_from_purchase_receipt,
|
|
28
|
+
)
|
|
27
29
|
from lambda_erp.accounting.pos_invoice import POSInvoice
|
|
28
30
|
from lambda_erp.controllers.pricing_rule import PricingRule
|
|
29
31
|
from lambda_erp.controllers.item_price import PriceList, ItemPrice
|
|
@@ -82,6 +84,7 @@ CONVERTERS = {
|
|
|
82
84
|
("Delivery Note", "Sales Invoice"): make_sales_invoice_from_delivery_note,
|
|
83
85
|
("Purchase Order", "Purchase Invoice"): make_purchase_invoice,
|
|
84
86
|
("Purchase Order", "Purchase Receipt"): make_purchase_receipt,
|
|
87
|
+
("Purchase Receipt", "Purchase Invoice"): make_purchase_invoice_from_purchase_receipt,
|
|
85
88
|
# Returns (same-to-same conversion creates a return document)
|
|
86
89
|
("Sales Invoice", "Sales Invoice"): make_sales_return,
|
|
87
90
|
("Purchase Invoice", "Purchase Invoice"): make_purchase_return,
|
|
@@ -198,14 +201,19 @@ def register_table(ddl: str) -> None:
|
|
|
198
201
|
_PLUGIN_TABLES.append(ddl)
|
|
199
202
|
|
|
200
203
|
|
|
201
|
-
def register_migration(migration_id: str, fn) -> None:
|
|
204
|
+
def register_migration(migration_id: str, fn, *, required: bool = False) -> None:
|
|
202
205
|
"""Register a one-shot migration run exactly once per database, recorded in
|
|
203
206
|
_PluginMigrations by `migration_id` (namespace it, e.g. "internal:0001_x").
|
|
204
207
|
`fn(db)` receives the DB; use db.ensure_column(...) for idempotent ALTERs
|
|
205
208
|
and plain db.sql(...) for backfills. Runs after registered tables exist, in
|
|
206
209
|
registration order. Must be idempotent and self-contained (single logical
|
|
207
|
-
unit — it commits on success).
|
|
208
|
-
|
|
210
|
+
unit — it commits on success).
|
|
211
|
+
|
|
212
|
+
A failing migration is rolled back and retried on the next start; the
|
|
213
|
+
server starts anyway. With ``required=True`` it stops the start instead,
|
|
214
|
+
and no later migration runs: use it for a migration the plugin's code
|
|
215
|
+
cannot work without (a column it reads, a table it writes)."""
|
|
216
|
+
_PLUGIN_MIGRATIONS.append((migration_id, fn, bool(required)))
|
|
209
217
|
|
|
210
218
|
|
|
211
219
|
def apply_plugin_schema() -> None:
|
|
@@ -230,7 +238,7 @@ def apply_plugin_schema() -> None:
|
|
|
230
238
|
db.conn.commit()
|
|
231
239
|
applied = {r["migration_id"] for r in db.sql('SELECT migration_id FROM "_PluginMigrations"')}
|
|
232
240
|
|
|
233
|
-
for migration_id, fn in _PLUGIN_MIGRATIONS:
|
|
241
|
+
for migration_id, fn, required in _PLUGIN_MIGRATIONS:
|
|
234
242
|
if migration_id in applied:
|
|
235
243
|
continue
|
|
236
244
|
try:
|
|
@@ -243,6 +251,11 @@ def apply_plugin_schema() -> None:
|
|
|
243
251
|
print(f"[plugin-migration] applied {migration_id}", flush=True)
|
|
244
252
|
except Exception as e:
|
|
245
253
|
db.conn.rollback()
|
|
254
|
+
if required:
|
|
255
|
+
print(f"[plugin-migration] FAILED {migration_id}: {e!r} — required, stopping startup", flush=True)
|
|
256
|
+
raise RuntimeError(
|
|
257
|
+
f"Required plugin migration {migration_id} failed: {e!r}. Nothing of it was applied; "
|
|
258
|
+
f"fix the cause and start again") from e
|
|
246
259
|
print(f"[plugin-migration] FAILED {migration_id}: {e!r} — will retry next boot", flush=True)
|
|
247
260
|
|
|
248
261
|
db._ensure_list_indexes()
|
|
@@ -308,6 +321,67 @@ def register_master(slug: str, table: str, name_field: str, *,
|
|
|
308
321
|
MASTER_REFERENCE_CHECKS[slug] = list(reference_checks)
|
|
309
322
|
|
|
310
323
|
|
|
324
|
+
# --- Registered reports ----------------------------------------------------
|
|
325
|
+
#
|
|
326
|
+
# A deployment's own report: registered once, served at
|
|
327
|
+
# GET /api/reports/registered/{name} and through the get_report chat / MCP
|
|
328
|
+
# tool, with the access rules applied before the handler runs.
|
|
329
|
+
|
|
330
|
+
REGISTERED_REPORTS: dict[str, dict] = {}
|
|
331
|
+
_REPORT_NAME_RE = re.compile(r"^[a-z][a-z0-9-]*$")
|
|
332
|
+
_UNSET = object()
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def register_report(name: str, handler, *, description: str, filters: dict | None = None,
|
|
336
|
+
sensitivity=_UNSET, scope: dict | None = None, minimum_role: str = "viewer") -> None:
|
|
337
|
+
"""Register a report across REST, chat and MCP.
|
|
338
|
+
|
|
339
|
+
``handler(filters: dict)`` returns a JSON-compatible dict, by convention
|
|
340
|
+
``{"rows": [...]}``. ``filters`` describes the accepted filter keys
|
|
341
|
+
({key: description}) for the chat prompt; unknown keys are refused.
|
|
342
|
+
|
|
343
|
+
``sensitivity`` must be given: a sensitivity class (the report is refused
|
|
344
|
+
for a user it is hidden from) or None when it shows nothing of them.
|
|
345
|
+
``scope`` says how the report relates to record scope, per dimension
|
|
346
|
+
(see permissions.register_scoped_artifact); a report that does not say is
|
|
347
|
+
refused for a user restricted to assigned records. The handler applies
|
|
348
|
+
the row limits itself (permissions.scope_rows / scope_sql).
|
|
349
|
+
"""
|
|
350
|
+
if not _REPORT_NAME_RE.fullmatch(name):
|
|
351
|
+
raise ValueError(f"Invalid report name: {name!r} (lowercase letters, digits and hyphens)")
|
|
352
|
+
if sensitivity is _UNSET:
|
|
353
|
+
raise ValueError(f"register_report({name!r}): say sensitivity=<class> or sensitivity=None")
|
|
354
|
+
if minimum_role not in _ROLE_LEVEL:
|
|
355
|
+
raise ValueError(f"Invalid minimum report role: {minimum_role!r}")
|
|
356
|
+
from api.routers import reports as core_reports
|
|
357
|
+
taken = {route.path.rsplit("/", 1)[-1] for route in core_reports.router.routes
|
|
358
|
+
if "{" not in getattr(route, "path", "")}
|
|
359
|
+
if name in taken:
|
|
360
|
+
raise ValueError(f"Report name {name!r} is a core report")
|
|
361
|
+
if sensitivity is not None:
|
|
362
|
+
permissions.register_sensitive_artifact("report", name, sensitivity)
|
|
363
|
+
if scope:
|
|
364
|
+
permissions.register_scoped_artifact("report", name, **scope)
|
|
365
|
+
REGISTERED_REPORTS[name] = {"handler": handler, "description": description,
|
|
366
|
+
"filters": dict(filters or {}), "minimum_role": minimum_role}
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def run_registered_report(name: str, filters: dict | None = None, user_info: dict | None = None):
|
|
370
|
+
meta = REGISTERED_REPORTS.get(name)
|
|
371
|
+
if not meta:
|
|
372
|
+
raise ValueError(f"Unknown report: {name}")
|
|
373
|
+
role = (user_info or {}).get("role")
|
|
374
|
+
if user_info is not None and _ROLE_LEVEL.get(role or "", 0) < _ROLE_LEVEL[meta["minimum_role"]]:
|
|
375
|
+
raise PermissionError(f"Report {name} requires {meta['minimum_role']} role or higher")
|
|
376
|
+
permissions.require_artifact("report", name)
|
|
377
|
+
filters = {key: value for key, value in (filters or {}).items() if value not in (None, "")}
|
|
378
|
+
unknown = sorted(set(filters) - set(meta["filters"]))
|
|
379
|
+
if unknown:
|
|
380
|
+
raise ValueError(f"Report {name} has no filter {', '.join(unknown)}. "
|
|
381
|
+
f"Filters: {', '.join(sorted(meta['filters'])) or 'none'}")
|
|
382
|
+
return meta["handler"](filters)
|
|
383
|
+
|
|
384
|
+
|
|
311
385
|
# --- Registered actions ----------------------------------------------------
|
|
312
386
|
#
|
|
313
387
|
# Plugins sometimes need one deliberate transition that is richer than CRUD
|
|
@@ -158,7 +158,7 @@ _CLASSES = {
|
|
|
158
158
|
"Purchase Order": ("lambda_erp.buying.purchase_order", "PurchaseOrder"),
|
|
159
159
|
"Purchase Invoice": ("lambda_erp.accounting.purchase_invoice", "PurchaseInvoice"),
|
|
160
160
|
}
|
|
161
|
-
_BUYING = ("Purchase Order", "Purchase Invoice")
|
|
161
|
+
_BUYING = ("Purchase Order", "Purchase Invoice", "Purchase Receipt")
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
def _document_class(doctype):
|
|
@@ -52,8 +52,8 @@ APPLICABLE_FOR = ("Customer", "Customer Group", "Territory", "Supplier", "Suppli
|
|
|
52
52
|
# schema, so relaxing that check — for a till that rings up anonymous sales —
|
|
53
53
|
# would make both flags false, match no rule, and silently price at base rate
|
|
54
54
|
# instead of raising. Trade side is a property of the document type; say so.
|
|
55
|
-
SELLING_DOCTYPES = {"Quotation", "Sales Order", "Sales Invoice", "POS Invoice"}
|
|
56
|
-
BUYING_DOCTYPES = {"Purchase Order", "Purchase Invoice"}
|
|
55
|
+
SELLING_DOCTYPES = {"Quotation", "Sales Order", "Sales Invoice", "POS Invoice", "Delivery Note"}
|
|
56
|
+
BUYING_DOCTYPES = {"Purchase Order", "Purchase Invoice", "Purchase Receipt"}
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
class PricingRule(Document):
|
|
@@ -3561,6 +3561,31 @@ def _m061_record_scope(db: "Database") -> None:
|
|
|
3561
3561
|
db.ensure_column("Report Draft", "access_stamp", "TEXT")
|
|
3562
3562
|
|
|
3563
3563
|
|
|
3564
|
+
def _m062_stock_document_pricing(db: "Database") -> None:
|
|
3565
|
+
"""Delivery notes and purchase receipts price their lines like orders and
|
|
3566
|
+
invoices do; a purchase invoice can bill a receipt line; a stock
|
|
3567
|
+
reservation can name a batch and a storage location.
|
|
3568
|
+
|
|
3569
|
+
Lines that exist keep their price: they are marked so that pricing rules
|
|
3570
|
+
do not run on them when a draft is saved again."""
|
|
3571
|
+
for doc_table, item_table in (("Delivery Note", "Delivery Note Item"), ("Purchase Receipt", "Purchase Receipt Item")):
|
|
3572
|
+
db.ensure_column(doc_table, "pricing_date", "TEXT")
|
|
3573
|
+
fresh = "ignore_pricing_rule" not in db._get_table_columns(item_table)
|
|
3574
|
+
db.ensure_column(item_table, "pricing_rule", "TEXT")
|
|
3575
|
+
db.ensure_column(item_table, "ignore_pricing_rule", "INTEGER DEFAULT 0")
|
|
3576
|
+
db.ensure_column(item_table, "price_source", "TEXT")
|
|
3577
|
+
db.ensure_column(item_table, "price_reference", "TEXT")
|
|
3578
|
+
if fresh:
|
|
3579
|
+
db.sql(f'UPDATE "{item_table}" SET ignore_pricing_rule = 1')
|
|
3580
|
+
db.ensure_column("Purchase Receipt Item", "billed_qty", "REAL DEFAULT 0")
|
|
3581
|
+
db.ensure_column("Purchase Invoice Item", "purchase_receipt", "TEXT")
|
|
3582
|
+
db.ensure_column("Purchase Invoice Item", "pr_detail", "TEXT")
|
|
3583
|
+
db.ensure_column("Stock Reservation", "batch_no", "TEXT")
|
|
3584
|
+
db.ensure_column("Stock Reservation", "location", "TEXT")
|
|
3585
|
+
# A supplier's own buying price list, as a customer has a selling one.
|
|
3586
|
+
db.ensure_column("Supplier", "default_price_list", "TEXT")
|
|
3587
|
+
|
|
3588
|
+
|
|
3564
3589
|
def _m052_access_profiles(db: "Database") -> None:
|
|
3565
3590
|
"""Access profiles narrow what a user's role allows (lambda_erp.permissions).
|
|
3566
3591
|
No profile is created and no user is assigned one: nothing changes for
|
|
@@ -3662,6 +3687,7 @@ Database.MIGRATIONS = [
|
|
|
3662
3687
|
(59, "batch_change_log", _m059_batch_change_log),
|
|
3663
3688
|
(60, "serial_numbers", _m060_serial_numbers),
|
|
3664
3689
|
(61, "record_scope", _m061_record_scope),
|
|
3690
|
+
(62, "stock_document_pricing", _m062_stock_document_pricing),
|
|
3665
3691
|
]
|
|
3666
3692
|
|
|
3667
3693
|
|
|
@@ -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):
|
|
@@ -14,7 +14,7 @@ from lambda_erp.model import Document
|
|
|
14
14
|
from lambda_erp.utils import _dict, flt, nowdate
|
|
15
15
|
from lambda_erp.database import get_db
|
|
16
16
|
from lambda_erp.controllers.taxes_and_totals import calculate_taxes_and_totals
|
|
17
|
-
from lambda_erp.controllers.defaults import set_default_currency
|
|
17
|
+
from lambda_erp.controllers.defaults import set_default_currency, derived_line_pricing_fields as agreed_line_price
|
|
18
18
|
from lambda_erp.exceptions import ValidationError
|
|
19
19
|
from lambda_erp.stock.stock_ledger import (
|
|
20
20
|
make_cancel_sl_entries,
|
|
@@ -60,12 +60,13 @@ class DeliveryNote(Document):
|
|
|
60
60
|
self.posting_date = nowdate()
|
|
61
61
|
|
|
62
62
|
self._set_customer_name()
|
|
63
|
+
# The price list is chosen by currency, so the currency comes first.
|
|
64
|
+
set_default_currency(self, "Customer", "customer")
|
|
63
65
|
self._set_item_defaults()
|
|
64
66
|
|
|
65
67
|
if self.is_return:
|
|
66
68
|
self._validate_return()
|
|
67
69
|
|
|
68
|
-
set_default_currency(self, "Customer", "customer")
|
|
69
70
|
calculate_taxes_and_totals(self)
|
|
70
71
|
self._set_status()
|
|
71
72
|
|
|
@@ -75,19 +76,13 @@ class DeliveryNote(Document):
|
|
|
75
76
|
self.customer_name = db.get_value("Customer", self.customer, "customer_name")
|
|
76
77
|
|
|
77
78
|
def _set_item_defaults(self):
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if item_data:
|
|
86
|
-
item["item_name"] = item_data.item_name
|
|
87
|
-
item["description"] = item.get("description") or item_data.description
|
|
88
|
-
item["uom"] = item.get("uom") or item_data.stock_uom
|
|
89
|
-
if item.get("rate") is None and item.get("price_list_rate") is None:
|
|
90
|
-
item["rate"] = flt(item_data.standard_rate)
|
|
79
|
+
# The same price resolution as orders and invoices: price list,
|
|
80
|
+
# customer-specific prices, then pricing rules. Lines that come from
|
|
81
|
+
# an order carry its price and are left alone.
|
|
82
|
+
from lambda_erp.controllers.item_price import set_item_defaults
|
|
83
|
+
from lambda_erp.controllers.pricing_rule import apply_pricing_rules
|
|
84
|
+
set_item_defaults(self, "Customer", "customer")
|
|
85
|
+
apply_pricing_rules(self)
|
|
91
86
|
|
|
92
87
|
def _validate_return(self):
|
|
93
88
|
from lambda_erp.workflow import validate_return
|
|
@@ -187,6 +182,8 @@ def make_delivery_note(sales_order_name):
|
|
|
187
182
|
# is a proposal on a draft; nothing is reserved or moved by it.
|
|
188
183
|
for pick in _proposed_picks(so, item, undelivered):
|
|
189
184
|
dn.append("items", _dict(
|
|
185
|
+
# The price was agreed in the source document: pricing rules do not run again.
|
|
186
|
+
**agreed_line_price(item),
|
|
190
187
|
item_code=item.get("item_code"),
|
|
191
188
|
item_name=item.get("item_name"),
|
|
192
189
|
description=item.get("description"),
|
|
@@ -234,6 +231,8 @@ def make_delivery_return(dn_name):
|
|
|
234
231
|
from lambda_erp.workflow import returnable_rows
|
|
235
232
|
for item in returnable_rows(original):
|
|
236
233
|
return_dn.append("items", _dict(
|
|
234
|
+
# The price was agreed in the source document: pricing rules do not run again.
|
|
235
|
+
**agreed_line_price(item),
|
|
237
236
|
item_code=item.get("item_code"),
|
|
238
237
|
item_name=item.get("item_name"),
|
|
239
238
|
description=item.get("description"),
|
|
@@ -14,7 +14,7 @@ from lambda_erp.model import Document
|
|
|
14
14
|
from lambda_erp.utils import _dict, flt, nowdate
|
|
15
15
|
from lambda_erp.database import get_db
|
|
16
16
|
from lambda_erp.controllers.taxes_and_totals import calculate_taxes_and_totals
|
|
17
|
-
from lambda_erp.controllers.defaults import set_default_currency
|
|
17
|
+
from lambda_erp.controllers.defaults import set_default_currency, derived_line_pricing_fields as agreed_line_price
|
|
18
18
|
from lambda_erp.exceptions import ValidationError
|
|
19
19
|
from lambda_erp.stock.stock_ledger import make_cancel_sl_entries, make_sl_entries, reverse_stock_sles, stock_account_for
|
|
20
20
|
from lambda_erp.accounting.general_ledger import make_gl_entries, make_reverse_gl_entries, to_base_currency
|
|
@@ -52,12 +52,13 @@ class PurchaseReceipt(Document):
|
|
|
52
52
|
self.posting_date = nowdate()
|
|
53
53
|
|
|
54
54
|
self._set_supplier_name()
|
|
55
|
+
# The price list is chosen by currency, so the currency comes first.
|
|
56
|
+
set_default_currency(self, "Supplier", "supplier")
|
|
55
57
|
self._set_item_defaults()
|
|
56
58
|
|
|
57
59
|
if self.is_return:
|
|
58
60
|
self._validate_return()
|
|
59
61
|
|
|
60
|
-
set_default_currency(self, "Supplier", "supplier")
|
|
61
62
|
calculate_taxes_and_totals(self)
|
|
62
63
|
self._set_status()
|
|
63
64
|
|
|
@@ -67,19 +68,13 @@ class PurchaseReceipt(Document):
|
|
|
67
68
|
self.supplier_name = db.get_value("Supplier", self.supplier, "supplier_name")
|
|
68
69
|
|
|
69
70
|
def _set_item_defaults(self):
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if item_data:
|
|
78
|
-
item["item_name"] = item_data.item_name
|
|
79
|
-
item["description"] = item.get("description") or item_data.description
|
|
80
|
-
item["uom"] = item.get("uom") or item_data.stock_uom
|
|
81
|
-
if item.get("rate") is None and item.get("price_list_rate") is None:
|
|
82
|
-
item["rate"] = flt(item_data.standard_rate)
|
|
71
|
+
# The same price resolution as orders and invoices: price list,
|
|
72
|
+
# supplier-specific prices, then pricing rules. Lines that come from
|
|
73
|
+
# an order carry its price and are left alone.
|
|
74
|
+
from lambda_erp.controllers.item_price import set_item_defaults
|
|
75
|
+
from lambda_erp.controllers.pricing_rule import apply_pricing_rules
|
|
76
|
+
set_item_defaults(self, "Supplier", "supplier")
|
|
77
|
+
apply_pricing_rules(self)
|
|
83
78
|
|
|
84
79
|
def _validate_return(self):
|
|
85
80
|
from lambda_erp.workflow import validate_return
|
|
@@ -262,6 +257,8 @@ def make_purchase_receipt(purchase_order_name):
|
|
|
262
257
|
if unreceived <= 0:
|
|
263
258
|
continue
|
|
264
259
|
pr.append("items", _dict(
|
|
260
|
+
# The price was agreed in the source document: pricing rules do not run again.
|
|
261
|
+
**agreed_line_price(item),
|
|
265
262
|
item_code=item.get("item_code"),
|
|
266
263
|
item_name=item.get("item_name"),
|
|
267
264
|
description=item.get("description"),
|
|
@@ -306,6 +303,8 @@ def make_purchase_receipt_return(prec_name):
|
|
|
306
303
|
from lambda_erp.workflow import returnable_rows
|
|
307
304
|
for item in returnable_rows(original):
|
|
308
305
|
return_pr.append("items", _dict(
|
|
306
|
+
# The price was agreed in the source document: pricing rules do not run again.
|
|
307
|
+
**agreed_line_price(item),
|
|
309
308
|
item_code=item.get("item_code"),
|
|
310
309
|
item_name=item.get("item_name"),
|
|
311
310
|
description=item.get("description"),
|
|
@@ -321,3 +320,63 @@ def make_purchase_receipt_return(prec_name):
|
|
|
321
320
|
))
|
|
322
321
|
|
|
323
322
|
return return_pr
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def make_purchase_invoice_from_purchase_receipt(receipt_name):
|
|
326
|
+
"""Bill what a purchase receipt received and has not been billed yet.
|
|
327
|
+
|
|
328
|
+
Receive first, invoice afterwards: the invoice lines point back to the
|
|
329
|
+
receipt lines (and to the order lines behind them), carry the received
|
|
330
|
+
price, and do not move stock again."""
|
|
331
|
+
from lambda_erp.accounting.purchase_invoice import PurchaseInvoice
|
|
332
|
+
from lambda_erp.controllers.defaults import derived_line_pricing_fields
|
|
333
|
+
|
|
334
|
+
receipt = PurchaseReceipt.load(receipt_name)
|
|
335
|
+
if receipt.docstatus != 1:
|
|
336
|
+
raise ValidationError("Purchase Receipt must be submitted before creating a Purchase Invoice")
|
|
337
|
+
if receipt.is_return:
|
|
338
|
+
raise ValidationError("A return to the supplier is credited from the original invoice, not invoiced")
|
|
339
|
+
|
|
340
|
+
invoice = PurchaseInvoice(
|
|
341
|
+
supplier=receipt.supplier,
|
|
342
|
+
supplier_name=receipt.supplier_name,
|
|
343
|
+
company=receipt.company,
|
|
344
|
+
currency=receipt.currency,
|
|
345
|
+
conversion_rate=receipt.conversion_rate,
|
|
346
|
+
posting_date=nowdate(),
|
|
347
|
+
update_stock=0,
|
|
348
|
+
)
|
|
349
|
+
for item in receipt.get("items"):
|
|
350
|
+
unbilled = flt(item.get("qty")) - flt(item.get("billed_qty"))
|
|
351
|
+
if unbilled <= 0:
|
|
352
|
+
continue
|
|
353
|
+
invoice.append("items", _dict(
|
|
354
|
+
**derived_line_pricing_fields(item),
|
|
355
|
+
item_code=item.get("item_code"),
|
|
356
|
+
item_name=item.get("item_name"),
|
|
357
|
+
description=item.get("description"),
|
|
358
|
+
qty=unbilled,
|
|
359
|
+
uom=item.get("uom"),
|
|
360
|
+
rate=item.get("rate"),
|
|
361
|
+
price_list_rate=item.get("price_list_rate"),
|
|
362
|
+
discount_percentage=item.get("discount_percentage"),
|
|
363
|
+
discount_amount=item.get("discount_amount"),
|
|
364
|
+
warehouse=item.get("warehouse"),
|
|
365
|
+
purchase_order=item.get("against_purchase_order"),
|
|
366
|
+
purchase_order_item=item.get("po_detail"),
|
|
367
|
+
purchase_receipt=receipt.name,
|
|
368
|
+
pr_detail=item.get("name"),
|
|
369
|
+
))
|
|
370
|
+
if not invoice.get("items"):
|
|
371
|
+
raise ValidationError(f"Purchase Receipt {receipt.name} is already billed in full")
|
|
372
|
+
for tax in receipt.get("taxes") or []:
|
|
373
|
+
invoice.append("taxes", _dict(
|
|
374
|
+
charge_type=tax.get("charge_type"),
|
|
375
|
+
account_head=tax.get("account_head"),
|
|
376
|
+
description=tax.get("description"),
|
|
377
|
+
rate=tax.get("rate"),
|
|
378
|
+
tax_amount=0,
|
|
379
|
+
included_in_print_rate=tax.get("included_in_print_rate"),
|
|
380
|
+
))
|
|
381
|
+
return invoice
|
|
382
|
+
|