lambda-erp 1.4.35__tar.gz → 1.4.38__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.
Files changed (146) hide show
  1. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/PKG-INFO +1 -1
  2. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/attachments.py +42 -1
  3. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/chat.py +1 -1
  4. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/llm_provider.py +14 -1
  5. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/price_resolution.py +34 -0
  6. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/consignment.py +3 -3
  7. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/pyproject.toml +1 -1
  8. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/.gitignore +0 -0
  9. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/LICENSE +0 -0
  10. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/README.md +0 -0
  11. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/__init__.py +0 -0
  12. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/auth.py +0 -0
  13. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/bootstrap.py +0 -0
  14. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/chat_links.py +0 -0
  15. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/demo_limits.py +0 -0
  16. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/deps.py +0 -0
  17. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/erp_context.py +0 -0
  18. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/errors.py +0 -0
  19. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/list_columns.py +0 -0
  20. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/list_values.py +0 -0
  21. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/mail.py +0 -0
  22. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/main.py +0 -0
  23. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/mcp_oauth.py +0 -0
  24. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/mentions.py +0 -0
  25. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/menu_layout.py +0 -0
  26. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/number_series.py +0 -0
  27. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/oauth.py +0 -0
  28. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/order_actions.py +0 -0
  29. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf.py +0 -0
  30. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf_contract.py +0 -0
  31. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf_exports.py +0 -0
  32. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf_fonts.py +0 -0
  33. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf_pages.py +0 -0
  34. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf_profiles.py +0 -0
  35. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pdf_templates.py +0 -0
  36. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/pricing_actions.py +0 -0
  37. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/providers.py +0 -0
  38. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/record_attachments.py +0 -0
  39. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/record_notes.py +0 -0
  40. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/remarks_md.py +0 -0
  41. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/__init__.py +0 -0
  42. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/accounting.py +0 -0
  43. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/actions.py +0 -0
  44. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/admin.py +0 -0
  45. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/analytics.py +0 -0
  46. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/availability.py +0 -0
  47. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/bank_reconciliation.py +0 -0
  48. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/bank_statements.py +0 -0
  49. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/chat_api.py +0 -0
  50. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/documents.py +0 -0
  51. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/masters.py +0 -0
  52. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/mcp.py +0 -0
  53. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/pdf_templates.py +0 -0
  54. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/proposals.py +0 -0
  55. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/reports.py +0 -0
  56. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/routers/setup.py +0 -0
  57. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/services.py +0 -0
  58. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/stock_actions.py +0 -0
  59. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/_proposal_totals.html +0 -0
  60. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/_record_base.html +0 -0
  61. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/delivery_note.html +0 -0
  62. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/document.html +0 -0
  63. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/proposal.html +0 -0
  64. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/record.html +0 -0
  65. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/templates/reservation.html +0 -0
  66. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/time_filters.py +0 -0
  67. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/tool_permissions.py +0 -0
  68. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/tool_results.py +0 -0
  69. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/api/write_context.py +0 -0
  70. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/docs/agents/README.md +0 -0
  71. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/frontend/LICENSE +0 -0
  72. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/frontend/README.md +0 -0
  73. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/frontend/src/api/client.ts +0 -0
  74. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/__init__.py +0 -0
  75. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/__init__.py +0 -0
  76. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/bank_account.py +0 -0
  77. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/bank_reconciliation.py +0 -0
  78. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/bank_statement_import.py +0 -0
  79. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/bank_transaction.py +0 -0
  80. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/budget.py +0 -0
  81. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/camt.py +0 -0
  82. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/chart_of_accounts.py +0 -0
  83. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/general_ledger.py +0 -0
  84. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/journal_entry.py +0 -0
  85. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/payment_entry.py +0 -0
  86. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/pos_invoice.py +0 -0
  87. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/purchase_invoice.py +0 -0
  88. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/revaluation.py +0 -0
  89. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/sales_invoice.py +0 -0
  90. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/settlement.py +0 -0
  91. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/__init__.py +0 -0
  92. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/engine.py +0 -0
  93. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/pack.py +0 -0
  94. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
  95. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/packs/ch.py +0 -0
  96. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
  97. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
  98. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
  99. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/packs/generic.py +0 -0
  100. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/profiles.py +0 -0
  101. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/setup/spine.py +0 -0
  102. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/accounting/subscription.py +0 -0
  103. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/addresses.py +0 -0
  104. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/assets/__init__.py +0 -0
  105. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/assets/asset.py +0 -0
  106. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/assets/lifecycle.py +0 -0
  107. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/assets/reservation.py +0 -0
  108. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/backlog.py +0 -0
  109. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/bundles.py +0 -0
  110. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/buying/__init__.py +0 -0
  111. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/buying/purchase_order.py +0 -0
  112. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/__init__.py +0 -0
  113. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/currency.py +0 -0
  114. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/defaults.py +0 -0
  115. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/item_price.py +0 -0
  116. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/item_prices.py +0 -0
  117. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/pricing_rule.py +0 -0
  118. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/tax_defaults.py +0 -0
  119. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/controllers/taxes_and_totals.py +0 -0
  120. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/customer_terms.py +0 -0
  121. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/database.py +0 -0
  122. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/exceptions.py +0 -0
  123. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/hooks.py +0 -0
  124. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/master_integrity.py +0 -0
  125. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/model.py +0 -0
  126. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/order_closing.py +0 -0
  127. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/permissions.py +0 -0
  128. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/selling/__init__.py +0 -0
  129. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/selling/proposal.py +0 -0
  130. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/selling/quotation.py +0 -0
  131. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/selling/sales_order.py +0 -0
  132. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/simulation.py +0 -0
  133. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/__init__.py +0 -0
  134. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/delivery_note.py +0 -0
  135. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/purchase_receipt.py +0 -0
  136. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/reservation.py +0 -0
  137. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/serial.py +0 -0
  138. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/stock_count.py +0 -0
  139. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/stock_entry.py +0 -0
  140. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/stock/stock_ledger.py +0 -0
  141. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/timestamps.py +0 -0
  142. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/units.py +0 -0
  143. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/utils.py +0 -0
  144. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/validation.py +0 -0
  145. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/lambda_erp/workflow.py +0 -0
  146. {lambda_erp-1.4.35 → lambda_erp-1.4.38}/terraform/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lambda-erp
3
- Version: 1.4.35
3
+ Version: 1.4.38
4
4
  Summary: Core ERP logic - accounting, sales, purchasing, inventory
5
5
  Author: TORUS INVESTMENTS AG
6
6
  License-Expression: Apache-2.0
@@ -61,10 +61,15 @@ STRUCTURED_TOOL_MIME_TYPES = {
61
61
  # a one-line description, never the bytes.
62
62
  FONT_MIME_TYPES = {"font/ttf", "font/otf", "font/woff", "font/woff2"}
63
63
 
64
+ # E-mail files (.eml). The model gets the headers, the readable text and the
65
+ # list of attached files, never the raw MIME source with its encoded parts.
66
+ EMAIL_MIME_TYPES = {"message/rfc822"}
67
+ EMAIL_TEXT_LIMIT = 50_000
68
+
64
69
  ALLOWED_MIME_TYPES = {
65
70
  "image/png", "image/jpeg", "image/gif", "image/webp",
66
71
  "application/pdf",
67
- } | OFFICE_MIME_TYPES | TEXT_MIME_TYPES | STRUCTURED_TOOL_MIME_TYPES | FONT_MIME_TYPES
72
+ } | OFFICE_MIME_TYPES | TEXT_MIME_TYPES | STRUCTURED_TOOL_MIME_TYPES | FONT_MIME_TYPES | EMAIL_MIME_TYPES
68
73
 
69
74
  # Extension -> canonical mime, so a correctly-named file still uploads when the
70
75
  # browser/OS mislabels its type (Office files are frequently sent as
@@ -87,6 +92,7 @@ _EXT_TO_MIME = {
87
92
  "png": "image/png", "jpg": "image/jpeg", "jpeg": "image/jpeg",
88
93
  "gif": "image/gif", "webp": "image/webp",
89
94
  "ttf": "font/ttf", "otf": "font/otf", "woff": "font/woff", "woff2": "font/woff2",
95
+ "eml": "message/rfc822",
90
96
  }
91
97
  _MIME_TO_EXT = {m: e for e, m in _EXT_TO_MIME.items()}
92
98
 
@@ -435,6 +441,8 @@ def build_multimodal_content(attachment: dict) -> dict:
435
441
  return {"type": "text", "text": (
436
442
  f"[Font file: {filename} ({what}; id {attachment['id']}). To print a PDF template with it, "
437
443
  "call add_attachment_to_pdf_template with this attachment id.]")}
444
+ if mime in EMAIL_MIME_TYPES:
445
+ return {"type": "text", "text": email_summary(attachment)}
438
446
  if mime in TEXT_MIME_TYPES or mime.startswith("text/"):
439
447
  text = attachment["data"].decode("utf-8", errors="replace")
440
448
  return {"type": "text", "text": f"[File: {filename}]\n{text}"}
@@ -465,6 +473,39 @@ def build_multimodal_content(attachment: dict) -> dict:
465
473
  return {"type": "text", "text": f"[Unsupported attachment: {filename}]"}
466
474
 
467
475
 
476
+ def email_summary(attachment: dict) -> str:
477
+ """Readable form of an .eml attachment: headers, text body and attached files."""
478
+ import html as html_module
479
+ import re
480
+ from email import policy
481
+ from email.parser import BytesParser
482
+
483
+ message = BytesParser(policy=policy.default).parsebytes(attachment["data"])
484
+ head = [f"{key}: {message[key]}" for key in ("From", "To", "Cc", "Date", "Subject", "Message-ID") if message[key]]
485
+ body = message.get_body(preferencelist=("plain", "html"))
486
+ text = ""
487
+ if body is not None:
488
+ try:
489
+ text = body.get_content()
490
+ except (LookupError, ValueError):
491
+ text = body.get_payload(decode=True).decode("utf-8", errors="replace") if body.get_payload(decode=True) else ""
492
+ if body.get_content_subtype() == "html":
493
+ text = re.sub(r"(?is)<(script|style)[^>]*>.*?</\1>", " ", text)
494
+ text = html_module.unescape(re.sub(r"(?s)<[^>]+>", " ", text))
495
+ text = re.sub(r"[ \t]+", " ", text)
496
+ files = []
497
+ for part in message.iter_attachments():
498
+ payload = part.get_payload(decode=True) or b""
499
+ files.append(f"- {part.get_filename() or '(ohne Namen)'} ({part.get_content_type()}, {len(payload)} Bytes"
500
+ + (", inline" if part.get_content_disposition() == "inline" else "") + ")")
501
+ text = text.strip()
502
+ if len(text) > EMAIL_TEXT_LIMIT:
503
+ text = text[:EMAIL_TEXT_LIMIT] + "\n[… gekürzt]"
504
+ return (f"[E-mail file: {attachment['filename']} (attachment id {attachment.get('id', '?')})]\n"
505
+ + "\n".join(head) + "\n\n" + (text or "(kein Text)")
506
+ + ("\n\nAttached files (not shown here):\n" + "\n".join(files) if files else ""))
507
+
508
+
468
509
  def list_session_attachments(session_id: str, user_id: str) -> list[dict]:
469
510
  """Return metadata (no data) for all attachments in a session."""
470
511
  db = get_db()
@@ -3307,7 +3307,7 @@ For a complete sales return (financial + stock): create and submit both a Credit
3307
3307
  - A line without a rate is priced when the document is saved: the Item Price of the document's price list (a row for this customer/supplier beats the list price; the highest min_qty reached; the narrower, then newer validity), else the item's standard rate. Then at most ONE Pricing Rule applies on top: highest priority, then the most specific match, then min_qty, validity and name.
3308
3308
  - Prices and rules are looked up for the document's date (`pricing_date` if set, else posting/transaction date). A price valid from next month does not apply to a document dated today.
3309
3309
  - Each line records where its price came from: `price_source` (Item Price, Standard Rate, Entered, Manual, None), `price_reference` (the Item Price) and `pricing_rule`. A rate the user changes on a saved line becomes Manual and is never repriced; converted lines keep the price of their source document.
3310
- - Use the `explain_price` action to answer "what would X cost for customer Y" and "why is this price what it is" — do not work prices out yourself. If a `price_missing` warning comes back, tell the user there is no price for that item instead of presenting 0.
3310
+ - Use the `explain_price` action to answer "what would X cost for customer Y" and "why is this price what it is" — do not work prices out yourself. For "why this price" name the applied rule AND every other rule in `rules_considered` that would also have matched, with its price and why it did not win (status, e.g. lower priority), so the user sees what was overridden. If a `price_missing` warning comes back, tell the user there is no price for that item instead of presenting 0.
3311
3311
  - Deployments may add their own rule keys (for example a price family or a purchasing group); get_document_fields / the rule's `apply_on` and `applicable_for` show what is in use.
3312
3312
 
3313
3313
  ### Reservations, availability and picking (FEFO)
@@ -78,13 +78,26 @@ def not_configured_message() -> str:
78
78
  return f"{settings.key_variable} is not configured"
79
79
 
80
80
 
81
+ def _client_timeout(timeout):
82
+ """The timeout in the type the installed OpenAI SDK expects.
83
+
84
+ Since openai 3.x the SDK runs on its own HTTP client (httpx2), and httpx2
85
+ 2.17 rejects an ``httpx.Timeout``. ``openai.Timeout`` is always the SDK's
86
+ own type, so convert instead of depending on which httpx the SDK uses.
87
+ """
88
+ import openai
89
+ if timeout is None or isinstance(timeout, (int, float, openai.Timeout)):
90
+ return timeout
91
+ return openai.Timeout(connect=timeout.connect, read=timeout.read, write=timeout.write, pool=timeout.pool)
92
+
93
+
81
94
  def client_kwargs(timeout: httpx.Timeout, erp_user: Optional[str] = None) -> dict:
82
95
  """Keyword arguments for ``OpenAI(...)`` with the configured provider."""
83
96
  settings = llm_settings()
84
97
  headers = {}
85
98
  if settings.provider == "lambda" and erp_user:
86
99
  headers[ERP_USER_HEADER] = str(erp_user)[:100]
87
- kwargs = {"api_key": settings.api_key, "timeout": timeout}
100
+ kwargs = {"api_key": settings.api_key, "timeout": _client_timeout(timeout)}
88
101
  if settings.base_url:
89
102
  kwargs["base_url"] = settings.base_url
90
103
  if headers:
@@ -306,6 +306,7 @@ def explain_document_line(doctype, name, line=1):
306
306
  manual = source == "Manual"
307
307
  carried = bool(flt(row.get("ignore_pricing_rule"))) and not manual
308
308
  from lambda_erp.controllers.item_price import pricing_date
309
+ considered = _considered_now(doctype, doc, row, rule)
309
310
  return {
310
311
  "doctype": doctype, "name": name, "line": row.get("name"), "item_code": row.get("item_code"),
311
312
  "qty": flt(row.get("qty")), "rate": flt(row.get("rate")), "price_list_rate": row.get("price_list_rate"),
@@ -313,5 +314,38 @@ def explain_document_line(doctype, name, line=1):
313
314
  "pricing_date": pricing_date(doc), "docstatus": doc.docstatus,
314
315
  "price_source": source, "price_reference": reference, "base": base, "pricing_rule": rule,
315
316
  "manual": manual, "rules_skipped": bool(flt(row.get("ignore_pricing_rule")) or flt(doc.get("ignore_pricing_rule"))),
317
+ # Every rule that matches this line today, with whether it won or why not (e.g. a
318
+ # family price overridden by an association price of higher priority).
319
+ "rules_considered": considered,
316
320
  "explanation": _summary(base, rule, row, manual=manual, carried=carried),
317
321
  }
322
+
323
+
324
+ def _considered_now(doctype, doc, row, stored_rule):
325
+ """The rules matching the line under today's rule set, each marked applied / lower priority / tied."""
326
+ from lambda_erp.controllers.item_price import pricing_date
327
+ buying = doctype in _BUYING
328
+ party = doc.get("supplier") if buying else doc.get("customer")
329
+ if not party or not row.get("item_code"):
330
+ return []
331
+ try:
332
+ now = explain_price(doctype, item_code=row["item_code"], qty=flt(row.get("qty")) or 1,
333
+ **({"supplier": party} if buying else {"customer": party}),
334
+ company=doc.get("company"), currency=doc.get("currency"), date=pricing_date(doc),
335
+ uom=row.get("uom") or None)
336
+ except ValidationError:
337
+ return []
338
+ applied = (stored_rule or {}).get("name")
339
+ top = max((r["priority"] for r in now["rules_considered"]), default=0)
340
+ result = []
341
+ for rule in now["rules_considered"]:
342
+ if rule["name"] == applied:
343
+ status = "angewendet"
344
+ elif rule["name"] in (now.get("tied_with") or []):
345
+ status = "gleichrangig"
346
+ elif rule["priority"] < top or applied:
347
+ status = "niedrigere Priorität"
348
+ else:
349
+ status = "nicht angewendet"
350
+ result.append({**rule, "status": status})
351
+ return result
@@ -181,10 +181,10 @@ class ConsignmentWithdrawal(Document):
181
181
  """Bill and withdraw once, through one Sales Invoice."""
182
182
  from lambda_erp.accounting.sales_invoice import SalesInvoice
183
183
 
184
+ # No remarks: they are the printed notes on the customer's invoice. The
185
+ # withdrawal keeps the link to its invoice (sales_invoice).
184
186
  invoice = SalesInvoice(
185
- customer=self.customer, company=self.company, posting_date=self.posting_date, update_stock=1,
186
- remarks=f"Consignment withdrawal {self.name}"
187
- + (f" ({self.external_reference})" if self._data.get("external_reference") else ""))
187
+ customer=self.customer, company=self.company, posting_date=self.posting_date, update_stock=1)
188
188
  for row in self.get("items"):
189
189
  line = _dict(item_code=row["item_code"], qty=flt(row["qty"]), warehouse=self.warehouse,
190
190
  batch_no=row.get("batch_no") or None, location=row.get("location") or None,
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lambda-erp"
3
- version = "1.4.35"
3
+ version = "1.4.38"
4
4
  description = "Core ERP logic - accounting, sales, purchasing, inventory"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
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