lambda-erp 1.4.17__tar.gz → 1.4.19__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 (137) hide show
  1. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/PKG-INFO +1 -1
  2. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/chat.py +10 -0
  3. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/main.py +4 -0
  4. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf_profiles.py +4 -0
  5. lambda_erp-1.4.19/api/record_attachments.py +230 -0
  6. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/masters.py +2 -0
  7. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/services.py +2 -0
  8. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/frontend/src/api/client.ts +24 -0
  9. lambda_erp-1.4.19/lambda_erp/bundles.py +167 -0
  10. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/database.py +65 -0
  11. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/model.py +6 -0
  12. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/permissions.py +2 -0
  13. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/pyproject.toml +1 -1
  14. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/.gitignore +0 -0
  15. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/LICENSE +0 -0
  16. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/README.md +0 -0
  17. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/__init__.py +0 -0
  18. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/attachments.py +0 -0
  19. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/auth.py +0 -0
  20. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/bootstrap.py +0 -0
  21. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/chat_links.py +0 -0
  22. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/demo_limits.py +0 -0
  23. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/deps.py +0 -0
  24. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/erp_context.py +0 -0
  25. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/errors.py +0 -0
  26. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/list_values.py +0 -0
  27. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/llm_provider.py +0 -0
  28. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/mcp_oauth.py +0 -0
  29. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/mentions.py +0 -0
  30. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/menu_layout.py +0 -0
  31. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/oauth.py +0 -0
  32. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf.py +0 -0
  33. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf_contract.py +0 -0
  34. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf_exports.py +0 -0
  35. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf_fonts.py +0 -0
  36. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf_pages.py +0 -0
  37. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pdf_templates.py +0 -0
  38. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/pricing_actions.py +0 -0
  39. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/providers.py +0 -0
  40. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/record_notes.py +0 -0
  41. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/remarks_md.py +0 -0
  42. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/__init__.py +0 -0
  43. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/accounting.py +0 -0
  44. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/actions.py +0 -0
  45. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/admin.py +0 -0
  46. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/analytics.py +0 -0
  47. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/availability.py +0 -0
  48. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/bank_reconciliation.py +0 -0
  49. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/bank_statements.py +0 -0
  50. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/chat_api.py +0 -0
  51. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/documents.py +0 -0
  52. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/mcp.py +0 -0
  53. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/pdf_templates.py +0 -0
  54. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/proposals.py +0 -0
  55. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/reports.py +0 -0
  56. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/routers/setup.py +0 -0
  57. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/stock_actions.py +0 -0
  58. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/_proposal_totals.html +0 -0
  59. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/_record_base.html +0 -0
  60. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/delivery_note.html +0 -0
  61. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/document.html +0 -0
  62. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/proposal.html +0 -0
  63. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/record.html +0 -0
  64. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/templates/reservation.html +0 -0
  65. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/time_filters.py +0 -0
  66. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/tool_permissions.py +0 -0
  67. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/api/write_context.py +0 -0
  68. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/docs/agents/README.md +0 -0
  69. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/frontend/LICENSE +0 -0
  70. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/frontend/README.md +0 -0
  71. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/__init__.py +0 -0
  72. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/__init__.py +0 -0
  73. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/bank_account.py +0 -0
  74. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/bank_reconciliation.py +0 -0
  75. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/bank_statement_import.py +0 -0
  76. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/bank_transaction.py +0 -0
  77. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/budget.py +0 -0
  78. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/camt.py +0 -0
  79. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/chart_of_accounts.py +0 -0
  80. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/general_ledger.py +0 -0
  81. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/journal_entry.py +0 -0
  82. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/payment_entry.py +0 -0
  83. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/pos_invoice.py +0 -0
  84. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/purchase_invoice.py +0 -0
  85. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/revaluation.py +0 -0
  86. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/sales_invoice.py +0 -0
  87. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/settlement.py +0 -0
  88. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/__init__.py +0 -0
  89. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/engine.py +0 -0
  90. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/pack.py +0 -0
  91. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
  92. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/packs/ch.py +0 -0
  93. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
  94. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
  95. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
  96. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/packs/generic.py +0 -0
  97. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/profiles.py +0 -0
  98. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/setup/spine.py +0 -0
  99. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/accounting/subscription.py +0 -0
  100. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/addresses.py +0 -0
  101. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/assets/__init__.py +0 -0
  102. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/assets/asset.py +0 -0
  103. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/assets/lifecycle.py +0 -0
  104. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/assets/reservation.py +0 -0
  105. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/backlog.py +0 -0
  106. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/buying/__init__.py +0 -0
  107. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/buying/purchase_order.py +0 -0
  108. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/__init__.py +0 -0
  109. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/currency.py +0 -0
  110. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/defaults.py +0 -0
  111. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/item_price.py +0 -0
  112. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/item_prices.py +0 -0
  113. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/price_resolution.py +0 -0
  114. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/pricing_rule.py +0 -0
  115. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/controllers/taxes_and_totals.py +0 -0
  116. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/exceptions.py +0 -0
  117. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/hooks.py +0 -0
  118. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/master_integrity.py +0 -0
  119. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/selling/__init__.py +0 -0
  120. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/selling/proposal.py +0 -0
  121. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/selling/quotation.py +0 -0
  122. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/selling/sales_order.py +0 -0
  123. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/simulation.py +0 -0
  124. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/__init__.py +0 -0
  125. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/consignment.py +0 -0
  126. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/delivery_note.py +0 -0
  127. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/purchase_receipt.py +0 -0
  128. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/reservation.py +0 -0
  129. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/serial.py +0 -0
  130. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/stock_count.py +0 -0
  131. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/stock_entry.py +0 -0
  132. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/stock/stock_ledger.py +0 -0
  133. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/timestamps.py +0 -0
  134. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/utils.py +0 -0
  135. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/validation.py +0 -0
  136. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/lambda_erp/workflow.py +0 -0
  137. {lambda_erp-1.4.17 → lambda_erp-1.4.19}/terraform/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lambda-erp
3
- Version: 1.4.17
3
+ Version: 1.4.19
4
4
  Summary: Core ERP logic - accounting, sales, purchasing, inventory
5
5
  Author: TORUS INVESTMENTS AG
6
6
  License-Expression: Apache-2.0
@@ -3034,6 +3034,16 @@ For a complete sales return (financial + stock): create and submit both a Credit
3034
3034
  - Never invent or guess a serial number. If the user has not given them, ask; to see what is in stock use search_masters master_type="serial-no" (filter item_code, warehouse) or the serial-trace report for one number.
3035
3035
  - Units from before the item was serial-tracked have no number: give them one with a Stock Entry of type "Serial Assignment" (item_code, qty, t_warehouse, serial_no).
3036
3036
 
3037
+ ### Attachments
3038
+ - Any document or master record can keep files (the customer's order e-mail or PDF, a signed slip, a certificate). They never change the record and are never printed. See what is there with the `list_record_attachments` action.
3039
+ - When the user uploads a file to the conversation and a record is created from it or it belongs to one, keep it with that record using `attach_chat_file` (record_type = the type slug, record_id = the record's name, attachment_id = the uploaded file's id). Do this for a customer's order that became a sales order without being asked twice; otherwise only when the user asks.
3040
+ - A Delivery Note has `tracking_reference` for the carrier's consignment number.
3041
+
3042
+ ### Item bundles
3043
+ - An **Item Bundle** (doctype `item-bundle`: item_code = the bundle, items = rows of item_code and qty per bundle) makes one item code stand for several items. The bundle's own item is not a stock item.
3044
+ - On quotations, sales orders, delivery notes and sales / POS invoices, put the bundle's item_code and qty on a line and save: the line is replaced by one line per item of the bundle, which are then ordinary lines. Do not give a bundle line a rate, discount or batch; do not expand a bundle by hand.
3045
+ - When the user names a set, look for it with list_documents doctype="item-bundle" (or the item) before listing single items yourself.
3046
+
3037
3047
  ### Addresses
3038
3048
  - A customer can have several addresses (master_type="address": customer, label, is_billing, is_shipping, is_default_billing, is_default_shipping, recipient_name, contact_person, address, zip_code, city, country, instructions). Search them with search_masters master_type="address" and the customer's name.
3039
3049
  - Quotation, Sales Order, Delivery Note and Sales Invoice carry `billing_address` and `shipping_address` (address record ids of that customer) and `billing_address_display` / `shipping_address_display` (the text that prints). Leave them out to get the customer's defaults; documents made from an order follow the order.
@@ -66,6 +66,8 @@ async def lifespan(app: FastAPI):
66
66
  initialize_mentions()
67
67
  from api.record_notes import initialize_record_notes
68
68
  initialize_record_notes()
69
+ from api.record_attachments import initialize_record_attachments
70
+ initialize_record_attachments()
69
71
  from api.stock_actions import initialize_stock_actions
70
72
  initialize_stock_actions()
71
73
  from api.pricing_actions import initialize_pricing_actions
@@ -155,6 +157,8 @@ app.include_router(auth_router, prefix="/api")
155
157
  app.include_router(oauth_router, prefix="/api")
156
158
  app.include_router(mcp_oauth_router)
157
159
  app.include_router(attachments_router, prefix="/api")
160
+ from api.record_attachments import router as record_attachments_router
161
+ app.include_router(record_attachments_router, prefix="/api")
158
162
  app.include_router(documents.router, prefix="/api")
159
163
  app.include_router(proposals.router, prefix="/api")
160
164
  app.include_router(pdf_templates_router.router, prefix="/api")
@@ -91,6 +91,10 @@ PROFILES.update({
91
91
  fields=('company', 'customer', 'warehouse', 'posting_date', 'external_reference', 'sales_invoice', 'remarks'),
92
92
  required=('customer', 'warehouse', 'posting_date', 'items'),
93
93
  tables=(PDFTable('items', ('item_code', 'item_name', 'qty', 'uom', 'batch_no'), ('item_code', 'qty'), True),)),
94
+ 'Item Bundle': PDFProfile('record', 'Item bundle',
95
+ fields=('item_code', 'bundle_name', 'description', 'disabled'),
96
+ required=('item_code', 'items'),
97
+ tables=(PDFTable('items', ('item_code', 'item_name', 'qty'), ('item_code', 'qty'), True),)),
94
98
  'Stock Reservation': PDFProfile('record', 'Stock reservation overview',
95
99
  fields=('item_code', 'warehouse', 'reserved_qty', 'sales_order', 'customer', 'status', 'remarks', 'reserved_by', 'company'),
96
100
  required=('item_code', 'warehouse', 'reserved_qty')),
@@ -0,0 +1,230 @@
1
+ """Files kept with a document or master record.
2
+
3
+ The customer's order as it arrived, a signed delivery slip, a certificate:
4
+ kept next to the record they belong to instead of in a folder. An attachment
5
+ never changes the record (no `modified` bump, allowed on submitted documents
6
+ too) and is never printed with it.
7
+
8
+ Whoever may read the record may list and download its files; adding and
9
+ removing them needs the manager role. The demo user gets neither.
10
+
11
+ REST:
12
+ GET /api/record-attachments?record_type=sales-order&record_id=SO-0001
13
+ POST /api/record-attachments (multipart: record_type, record_id, file, description)
14
+ GET /api/record-attachments/{id} (the file)
15
+ DELETE /api/record-attachments/{id}
16
+
17
+ Chat / MCP: actions list_record_attachments and attach_chat_file (keeps a
18
+ file that was uploaded to the conversation with a record).
19
+
20
+ See docs/attachments.md.
21
+ """
22
+ import hashlib
23
+ import os
24
+ import re
25
+ import uuid
26
+
27
+ from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile
28
+ from fastapi.responses import Response
29
+ from pydantic import Field
30
+
31
+ from api import mentions, services
32
+ from api.auth import get_current_user
33
+ from lambda_erp.database import get_db
34
+ from lambda_erp.utils import now
35
+
36
+ TABLE = "Record Attachment"
37
+ MAX_SIZE = 15 * 1024 * 1024
38
+ MAX_PER_RECORD = 50
39
+ # What may be kept: documents, images, mail, spreadsheets. Nothing a browser
40
+ # would run; files are always sent back as downloads.
41
+ ALLOWED = {
42
+ ".pdf": "application/pdf",
43
+ ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp",
44
+ ".tif": "image/tiff", ".tiff": "image/tiff",
45
+ ".eml": "message/rfc822", ".msg": "application/vnd.ms-outlook",
46
+ ".txt": "text/plain", ".csv": "text/csv",
47
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
48
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
49
+ ".xml": "application/xml",
50
+ }
51
+ _UNSAFE = re.compile(r"[^\w.\- ()\[\]]+", re.UNICODE)
52
+
53
+ router = APIRouter(prefix="/record-attachments", tags=["attachments"])
54
+
55
+
56
+ def _target(record_type):
57
+ doctype = services.SLUG_TO_DOCTYPE.get(record_type)
58
+ if doctype:
59
+ return doctype
60
+ master = services.MASTER_TABLES.get(record_type)
61
+ return master[0] if master else None
62
+
63
+
64
+ def _require_record(record_type, record_id, user, write=False):
65
+ """The record exists and the caller may read it (and, to write, is at
66
+ least a manager). Refusals do not say whether the record exists."""
67
+ from lambda_erp import permissions
68
+ from lambda_erp.exceptions import PermissionDenied
69
+
70
+ table = _target(record_type)
71
+ role = (user or {}).get("role")
72
+ if not table or role not in mentions.REAL_ROLES or not get_db().exists(table, record_id):
73
+ raise HTTPException(404, "Record is unavailable")
74
+ try:
75
+ with permissions.acting_as(user):
76
+ permissions.require_readable(table, record_id)
77
+ except PermissionDenied:
78
+ raise HTTPException(404, "Record is unavailable")
79
+ if write and role not in ("manager", "admin"):
80
+ raise HTTPException(403, "Adding or removing attachments requires the manager role")
81
+ return table
82
+
83
+
84
+ def safe_filename(filename):
85
+ name = os.path.basename(str(filename or "").replace("\\", "/")).strip()
86
+ name = _UNSAFE.sub("_", name).strip(". ")[:150]
87
+ return name or "attachment"
88
+
89
+
90
+ def _public(row):
91
+ return {"id": row["name"], "record_type": row["record_type"], "record_id": row["record_id"],
92
+ "filename": row["filename"], "content_type": row["content_type"], "size": row["size"],
93
+ "description": row.get("description"), "uploaded_by": row.get("uploaded_by_name") or row.get("uploaded_by"),
94
+ "created_at": row.get("creation"), "url": f"/api/record-attachments/{row['name']}"}
95
+
96
+
97
+ def list_attachments(record_type, record_id, user):
98
+ _require_record(record_type, record_id, user)
99
+ rows = get_db().sql(
100
+ f'SELECT name, record_type, record_id, filename, content_type, size, description, uploaded_by, '
101
+ f'uploaded_by_name, creation FROM "{TABLE}" WHERE record_type = ? AND record_id = ? ORDER BY creation, name',
102
+ [record_type, record_id])
103
+ return {"attachments": [_public(row) for row in rows]}
104
+
105
+
106
+ def add_attachment(record_type, record_id, filename, data, user, description=None):
107
+ """Keep a file with a record. Returns its public description."""
108
+ _require_record(record_type, record_id, user, write=True)
109
+ filename = safe_filename(filename)
110
+ extension = os.path.splitext(filename)[1].lower()
111
+ if extension not in ALLOWED:
112
+ raise HTTPException(415, f"{extension or 'This file type'} cannot be attached. "
113
+ f"Allowed: {', '.join(sorted(ALLOWED))}")
114
+ if not data:
115
+ raise HTTPException(400, "The file is empty")
116
+ if len(data) > MAX_SIZE:
117
+ raise HTTPException(413, f"The file is too large (at most {MAX_SIZE // (1024 * 1024)} MB)")
118
+ db = get_db()
119
+ count = db.sql(f'SELECT COUNT(*) AS n FROM "{TABLE}" WHERE record_type = ? AND record_id = ?',
120
+ [record_type, record_id])[0]["n"]
121
+ if count >= MAX_PER_RECORD:
122
+ raise HTTPException(409, f"A record holds at most {MAX_PER_RECORD} attachments")
123
+ name = uuid.uuid4().hex
124
+ db.sql(
125
+ f'INSERT INTO "{TABLE}" (name, record_type, record_id, filename, content_type, size, sha256, data, '
126
+ f'description, uploaded_by, uploaded_by_name, creation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
127
+ [name, record_type, record_id, filename, ALLOWED[extension], len(data), hashlib.sha256(data).hexdigest(),
128
+ data, (str(description).strip()[:500] or None) if description else None,
129
+ user.get("user_id") or user.get("name"), user.get("full_name") or user.get("email"), now()])
130
+ db.commit()
131
+ row = db.sql(f'SELECT name, record_type, record_id, filename, content_type, size, description, uploaded_by, '
132
+ f'uploaded_by_name, creation FROM "{TABLE}" WHERE name = ?', [name])[0]
133
+ return _public(row)
134
+
135
+
136
+ def _load(attachment_id, user, write=False):
137
+ rows = get_db().sql(f'SELECT * FROM "{TABLE}" WHERE name = ?', [attachment_id])
138
+ if not rows:
139
+ raise HTTPException(404, "Attachment not found")
140
+ _require_record(rows[0]["record_type"], rows[0]["record_id"], user, write=write)
141
+ return rows[0]
142
+
143
+
144
+ def delete_attachments_for(record_type, record_id):
145
+ """Drop a hard-deleted record's files."""
146
+ get_db().sql(f'DELETE FROM "{TABLE}" WHERE record_type = ? AND record_id = ?', [record_type, record_id])
147
+
148
+
149
+ # -- REST ---------------------------------------------------------------------
150
+
151
+ @router.get("")
152
+ def list_route(record_type: str, record_id: str, user: dict = Depends(get_current_user)):
153
+ return list_attachments(record_type, record_id, user)
154
+
155
+
156
+ @router.post("")
157
+ async def upload_route(record_type: str = Form(...), record_id: str = Form(...), file: UploadFile = File(...),
158
+ description: str | None = Form(None), user: dict = Depends(get_current_user)):
159
+ # Check access before reading the body into memory.
160
+ _require_record(record_type, record_id, user, write=True)
161
+ data = await file.read(MAX_SIZE + 1)
162
+ return add_attachment(record_type, record_id, file.filename, data, user, description)
163
+
164
+
165
+ @router.get("/{attachment_id}")
166
+ def download_route(attachment_id: str, user: dict = Depends(get_current_user)):
167
+ row = _load(attachment_id, user)
168
+ data = row["data"]
169
+ if isinstance(data, memoryview):
170
+ data = data.tobytes()
171
+ ascii_name = row["filename"].encode("ascii", "replace").decode().replace('"', "_")
172
+ return Response(content=bytes(data), media_type=row["content_type"], headers={
173
+ # Always a download, never rendered in the application's origin.
174
+ "Content-Disposition": f'attachment; filename="{ascii_name}"',
175
+ "X-Content-Type-Options": "nosniff",
176
+ "Cache-Control": "private, no-store",
177
+ })
178
+
179
+
180
+ @router.delete("/{attachment_id}")
181
+ def delete_route(attachment_id: str, user: dict = Depends(get_current_user)):
182
+ row = _load(attachment_id, user, write=True)
183
+ db = get_db()
184
+ db.sql(f'DELETE FROM "{TABLE}" WHERE name = ?', [row["name"]])
185
+ db.commit()
186
+ return {"ok": True}
187
+
188
+
189
+ # -- chat / MCP ---------------------------------------------------------------
190
+
191
+ class ListAttachments(mentions.Input):
192
+ record_type: str = Field(min_length=1, max_length=100)
193
+ record_id: str = Field(min_length=1, max_length=200)
194
+
195
+
196
+ class AttachChatFile(mentions.Input):
197
+ record_type: str = Field(min_length=1, max_length=100)
198
+ record_id: str = Field(min_length=1, max_length=200)
199
+ attachment_id: str = Field(min_length=1, max_length=100)
200
+ description: str | None = Field(default=None, max_length=500)
201
+
202
+
203
+ def _list_action(args, user):
204
+ data = ListAttachments.model_validate(args)
205
+ return list_attachments(data.record_type, data.record_id, user)
206
+
207
+
208
+ def _attach_chat_file(args, user):
209
+ data = AttachChatFile.model_validate(args)
210
+ from api.attachments import get_attachments_by_ids
211
+ found = get_attachments_by_ids([data.attachment_id], user.get("user_id") or user.get("name"))
212
+ if not found:
213
+ raise HTTPException(404, "That file was not uploaded to one of your conversations")
214
+ return add_attachment(data.record_type, data.record_id, found[0]["filename"], found[0]["data"], user,
215
+ data.description)
216
+
217
+
218
+ def initialize_record_attachments():
219
+ services.register_action(
220
+ "list_record_attachments", _list_action, minimum_role="viewer", pass_user=True,
221
+ parameters=ListAttachments.model_json_schema(),
222
+ description="List the files kept with one document or master record (name, type, size, who added it). "
223
+ "record_type is the document or master type slug (e.g. sales-order, item) and record_id its "
224
+ "name. The files themselves are downloaded in the application.")
225
+ services.register_action(
226
+ "attach_chat_file", _attach_chat_file, minimum_role="manager", pass_user=True,
227
+ parameters=AttachChatFile.model_json_schema(),
228
+ description="Keep a file the user uploaded to this conversation with a document or master record, e.g. "
229
+ "the customer's order e-mail or PDF with the sales order made from it. attachment_id is the "
230
+ "id of the uploaded file. It does not change the record and is never printed.")
@@ -908,8 +908,10 @@ def delete_master_record(master_type: str, name: str) -> dict:
908
908
  raise HTTPException(status_code=409, detail=f"Cannot delete {doctype} {name}: referenced by {reference}")
909
909
 
910
910
  from api.record_notes import delete_record_notes_for
911
+ from api.record_attachments import delete_attachments_for
911
912
  with db.atomic():
912
913
  delete_record_notes_for(master_type, name)
914
+ delete_attachments_for(master_type, name)
913
915
  db.delete(doctype, name=name)
914
916
  return {"ok": True, "status": "deleted"}
915
917
 
@@ -38,6 +38,7 @@ from lambda_erp.assets.reservation import Reservation
38
38
  from lambda_erp.stock.reservation import StockReservation
39
39
  from lambda_erp.stock.consignment import ConsignmentWithdrawal
40
40
  from lambda_erp.stock.stock_count import StockCount
41
+ from lambda_erp.bundles import ItemBundle
41
42
 
42
43
 
43
44
  # --- Doctype registries ---
@@ -73,6 +74,7 @@ DOCUMENT_CLASSES = {
73
74
  "Consignment Withdrawal": ConsignmentWithdrawal,
74
75
  # Counted quantities; submitting books the differences with a reason.
75
76
  "Stock Count": StockCount,
77
+ "Item Bundle": ItemBundle,
76
78
  }
77
79
 
78
80
  CONVERTERS = {
@@ -260,6 +260,16 @@ export interface FleetCalendarFeed {
260
260
 
261
261
  /** Narrows what a user's role allows: hidden classes of sensitive data and,
262
262
  * per document or master type, the actions that remain. */
263
+ export interface RecordAttachment {
264
+ id: string;
265
+ filename: string;
266
+ content_type: string;
267
+ size: number;
268
+ description?: string | null;
269
+ uploaded_by?: string | null;
270
+ created_at?: string | null;
271
+ }
272
+
263
273
  export interface AccessProfile {
264
274
  name: string;
265
275
  description?: string;
@@ -807,6 +817,20 @@ export const api = {
807
817
  ),
808
818
  authDeleteAccessProfile: (name: string) =>
809
819
  request<any>(`/auth/access-profiles/${encodeURIComponent(name)}`, { method: "DELETE" }),
820
+ // Files kept with a document or master record.
821
+ listRecordAttachments: (recordType: string, recordId: string) =>
822
+ request<{ attachments: RecordAttachment[] }>(`/record-attachments${qs({ record_type: recordType, record_id: recordId })}`),
823
+ uploadRecordAttachment: (recordType: string, recordId: string, file: File, description?: string) => {
824
+ const form = new FormData();
825
+ form.append("record_type", recordType);
826
+ form.append("record_id", recordId);
827
+ form.append("file", file);
828
+ if (description) form.append("description", description);
829
+ return multipartRequest<RecordAttachment>("/record-attachments", form);
830
+ },
831
+ deleteRecordAttachment: (id: string) =>
832
+ request<any>(`/record-attachments/${encodeURIComponent(id)}`, { method: "DELETE" }),
833
+ recordAttachmentUrl: (id: string) => `${BASE}/record-attachments/${encodeURIComponent(id)}`,
810
834
  authAssignRecordScope: (userName: string, record_scope: Record<string, string[]> | null) =>
811
835
  request<any>(`/auth/users/${encodeURIComponent(userName)}/record-scope`, {
812
836
  method: "PUT", body: JSON.stringify({ record_scope }),
@@ -0,0 +1,167 @@
1
+ """Item bundles: one item code that stands for several items.
2
+
3
+ A bundle is an item that is not stocked, sold or priced itself. Its Item
4
+ Bundle record lists the items it stands for, with a quantity each. Putting
5
+ the bundle on a line of a sales document replaces that line by one line per
6
+ component when the document is saved:
7
+
8
+ line SET-KNEE, qty 2
9
+ becomes IMPLANT-A, qty 2 (1 per set)
10
+ SCREW-4, qty 8 (4 per set)
11
+
12
+ From there the components are ordinary lines: each is priced, reserved,
13
+ picked by batch, delivered and invoiced on its own, and can be changed or
14
+ removed on the draft. What differs per customer (the tool for the left or
15
+ the right hand) is simply not part of the bundle and is added as a line.
16
+
17
+ Each line that came from a bundle keeps `bundle_item` and `bundle_qty` (the
18
+ bundle and how many of it were entered), so documents can say what was
19
+ ordered as a set.
20
+
21
+ See docs/bundles.md.
22
+ """
23
+ from lambda_erp.database import get_db
24
+ from lambda_erp.exceptions import ValidationError
25
+ from lambda_erp.model import Document
26
+ from lambda_erp.utils import _dict, flt
27
+
28
+ # Document types whose item lines expand bundles.
29
+ EXPANDING = {"Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"}
30
+ MAX_DEPTH = 5
31
+
32
+ # What a component line takes over from the bundle line; everything about the
33
+ # item itself (name, unit, price, batch) is its own.
34
+ CARRIED = ("warehouse", "delivery_date", "cost_center", "income_account", "location")
35
+ # What a bundle line may not carry: it has no price and no stock of its own.
36
+ REFUSED = ("rate", "price_list_rate", "discount_percentage", "discount_amount", "batch_no", "serial_no")
37
+
38
+
39
+ def register_bundle_document(doctype):
40
+ """Plugin seam: a further document type whose `items` lines expand
41
+ bundles (its line table needs bundle_item TEXT and bundle_qty REAL)."""
42
+ EXPANDING.add(doctype)
43
+
44
+
45
+ def bundle_of(item_code):
46
+ """The enabled Item Bundle record of an item code, or None."""
47
+ db = get_db()
48
+ if not item_code or not db._get_table_columns("Item Bundle"):
49
+ return None
50
+ rows = db.sql('SELECT name FROM "Item Bundle" WHERE item_code = ? AND COALESCE(disabled, 0) = 0 '
51
+ 'AND COALESCE(discarded, 0) = 0 LIMIT 1', [item_code])
52
+ return rows[0]["name"] if rows else None
53
+
54
+
55
+ def components(item_code, qty=1.0, _path=()):
56
+ """The items a bundle stands for, as [(item_code, qty)], bundles inside
57
+ bundles resolved. `qty` is how many of the bundle."""
58
+ name = bundle_of(item_code)
59
+ if not name:
60
+ return [(item_code, flt(qty))]
61
+ if item_code in _path or len(_path) >= MAX_DEPTH:
62
+ raise ValidationError(f"Item Bundle {item_code} contains itself: {' > '.join((*_path, item_code))}")
63
+ result = []
64
+ for row in get_db().get_all("Item Bundle Item", filters={"parent": name}, fields=["item_code", "qty"],
65
+ order_by="idx"):
66
+ result.extend(components(row["item_code"], flt(qty) * flt(row["qty"]), (*_path, item_code)))
67
+ return result
68
+
69
+
70
+ def expand_bundle_lines(doc):
71
+ """Replace every bundle line of a sales document by its component lines.
72
+ Called before the document validates, on every save and on submit; a
73
+ document without bundle lines is left exactly as it is."""
74
+ if doc.DOCTYPE not in EXPANDING:
75
+ return
76
+ lines = doc.get("items") or []
77
+ if not any(bundle_of(row.get("item_code")) for row in lines):
78
+ return
79
+ table = doc.CHILD_TABLES["items"][0]
80
+ stamps = "bundle_item" in get_db()._get_table_columns(table)
81
+ expanded = []
82
+ for position, row in enumerate(lines, 1):
83
+ code = row.get("item_code")
84
+ if not bundle_of(code):
85
+ expanded.append(row)
86
+ continue
87
+ qty = flt(row.get("qty"))
88
+ if not qty:
89
+ raise ValidationError(f"{doc.DOCTYPE} row {position}: bundle {code} needs a quantity")
90
+ priced = [field for field in REFUSED if row.get(field) not in (None, "", 0, 0.0)]
91
+ if priced:
92
+ raise ValidationError(
93
+ f"{doc.DOCTYPE} row {position}: {code} is a bundle and has no {', '.join(priced)} of its own. "
94
+ f"Leave it out; the items of the bundle are priced and picked as their own lines")
95
+ for item_code, item_qty in components(code, qty):
96
+ line = _dict({field: row.get(field) for field in CARRIED if row.get(field) not in (None, "")})
97
+ line.update(item_code=item_code, qty=item_qty)
98
+ if stamps:
99
+ line.update(bundle_item=code, bundle_qty=qty)
100
+ expanded.append(line)
101
+ doc._children["items"] = []
102
+ for line in expanded:
103
+ doc.append("items", line)
104
+
105
+
106
+ class ItemBundle(Document):
107
+ DOCTYPE = "Item Bundle"
108
+ CHILD_TABLES = {"items": ("Item Bundle Item", None)}
109
+ PREFIX = "BNDL"
110
+ REQUIRED_FIELDS = ("item_code", "items")
111
+ CHILD_REQUIREMENTS = {"items": {"required": ["item_code", "qty"]}}
112
+ CONDITIONAL_REQUIREMENTS = (
113
+ "item_code is the bundle: an item that is not a stock item and has no batch or serial tracking. "
114
+ "Create that item first; one bundle per item.",
115
+ "items lists what the bundle stands for, with the quantity per one bundle. A component can itself be a "
116
+ "bundle. The bundle cannot contain itself.",
117
+ "On quotations, sales orders, delivery notes and sales / POS invoices, a line with the bundle's item_code "
118
+ "is replaced by one line per component when the document is saved. A bundle has no price: the components "
119
+ "are priced as usual.",
120
+ "Changing a bundle changes what new lines expand to; lines on existing documents stay as they are.",
121
+ )
122
+ LINK_FIELDS = {"item_code": "Item"}
123
+ CHILD_LINK_FIELDS = {"items": {"item_code": "Item"}}
124
+
125
+ def validate(self):
126
+ db = get_db()
127
+ item = db.get_value("Item", self.item_code, ["item_name", "is_stock_item", "has_batch_no", "has_serial_no"])
128
+ if not item:
129
+ raise ValidationError(f"Item Bundle: item {self.item_code} does not exist")
130
+ if flt(item.get("is_stock_item")) or flt(item.get("has_batch_no")) or flt(item.get("has_serial_no")):
131
+ raise ValidationError(
132
+ f"Item Bundle: {self.item_code} is a stock item. A bundle is an item that is not stocked itself "
133
+ f"(is_stock_item = 0, no batch or serial tracking)")
134
+ if db.sql('SELECT 1 FROM "Stock Ledger Entry" WHERE item_code = ? LIMIT 1', [self.item_code]):
135
+ raise ValidationError(f"Item Bundle: {self.item_code} has stock movements and cannot become a bundle")
136
+ twin = db.sql('SELECT name FROM "Item Bundle" WHERE item_code = ? AND name <> ? '
137
+ 'AND COALESCE(discarded, 0) = 0 LIMIT 1', [self.item_code, self.name or ""])
138
+ if twin:
139
+ raise ValidationError(f"Item {self.item_code} already has bundle {twin[0]['name']}; change that one")
140
+ if not self._data.get("bundle_name"):
141
+ self._data["bundle_name"] = item.get("item_name") or self.item_code
142
+ rows = self.get("items") or []
143
+ if not rows:
144
+ raise ValidationError("Item Bundle: at least one item is required")
145
+ seen = set()
146
+ for idx, row in enumerate(rows, 1):
147
+ code = row.get("item_code")
148
+ if not code or not db.exists("Item", code):
149
+ raise ValidationError(f"Item Bundle row {idx}: item {code or ''} does not exist")
150
+ if code == self.item_code:
151
+ raise ValidationError(f"Item Bundle row {idx}: a bundle cannot contain itself")
152
+ if code in seen:
153
+ raise ValidationError(f"Item Bundle row {idx}: {code} is listed twice; give it one line with the total quantity")
154
+ seen.add(code)
155
+ try:
156
+ qty = float(row.get("qty"))
157
+ except (TypeError, ValueError):
158
+ raise ValidationError(f"Item Bundle row {idx}: Qty must be a number")
159
+ if not qty > 0 or qty != qty or qty == float("inf"):
160
+ raise ValidationError(f"Item Bundle row {idx}: Qty must be positive")
161
+ row["qty"] = qty
162
+ row["item_name"] = db.get_value("Item", code, "item_name")
163
+ # A component that is a bundle must not lead back here.
164
+ if bundle_of(code):
165
+ inner = [inner_code for inner_code, _ in components(code, 1, (self.item_code,))]
166
+ if self.item_code in inner:
167
+ raise ValidationError(f"Item Bundle row {idx}: {code} contains {self.item_code}")
@@ -3624,6 +3624,69 @@ def _m063_addresses(db: "Database") -> None:
3624
3624
  db.ensure_column(table, column, "TEXT")
3625
3625
 
3626
3626
 
3627
+ def _m064_item_bundles(db: "Database") -> None:
3628
+ """Item bundles: an item code that stands for several items and expands
3629
+ into their lines on sales documents (see docs/bundles.md). No item
3630
+ becomes a bundle by this migration."""
3631
+ db.conn.execute(db._ddl(
3632
+ """CREATE TABLE IF NOT EXISTS "Item Bundle" (
3633
+ name TEXT PRIMARY KEY,
3634
+ item_code TEXT NOT NULL,
3635
+ bundle_name TEXT,
3636
+ description TEXT,
3637
+ disabled INTEGER DEFAULT 0,
3638
+ status TEXT DEFAULT 'Draft',
3639
+ docstatus INTEGER DEFAULT 0,
3640
+ discarded INTEGER DEFAULT 0,
3641
+ creation TEXT,
3642
+ modified TEXT
3643
+ )"""))
3644
+ db.conn.execute(db._ddl(
3645
+ """CREATE TABLE IF NOT EXISTS "Item Bundle Item" (
3646
+ name TEXT PRIMARY KEY,
3647
+ parent TEXT NOT NULL,
3648
+ idx INTEGER DEFAULT 0,
3649
+ item_code TEXT,
3650
+ item_name TEXT,
3651
+ qty REAL DEFAULT 1
3652
+ )"""))
3653
+ db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_item_bundle_item_code" ON "Item Bundle" (item_code)'))
3654
+ db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_item_bundle_item_parent" ON "Item Bundle Item" (parent)'))
3655
+ db.conn.commit()
3656
+ for table in ("Item Bundle", "Item Bundle Item"):
3657
+ db._col_cache.pop(table, None)
3658
+ db._text_col_cache.pop(table, None)
3659
+ for table in ("Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "POS Invoice Item"):
3660
+ db.ensure_column(table, "bundle_item", "TEXT")
3661
+ db.ensure_column(table, "bundle_qty", "REAL")
3662
+
3663
+
3664
+ def _m065_record_attachments(db: "Database") -> None:
3665
+ """Files kept with a document or master record, and a tracking reference
3666
+ on delivery notes (see docs/attachments.md)."""
3667
+ db.conn.execute(db._ddl(
3668
+ """CREATE TABLE IF NOT EXISTS "Record Attachment" (
3669
+ name TEXT PRIMARY KEY,
3670
+ record_type TEXT NOT NULL,
3671
+ record_id TEXT NOT NULL,
3672
+ filename TEXT NOT NULL,
3673
+ content_type TEXT NOT NULL,
3674
+ size INTEGER NOT NULL,
3675
+ sha256 TEXT,
3676
+ data BLOB NOT NULL,
3677
+ description TEXT,
3678
+ uploaded_by TEXT,
3679
+ uploaded_by_name TEXT,
3680
+ creation TEXT
3681
+ )"""))
3682
+ db.conn.execute(db._ddl(
3683
+ 'CREATE INDEX IF NOT EXISTS "ix_record_attachment_record" ON "Record Attachment" (record_type, record_id)'))
3684
+ db.conn.commit()
3685
+ db._col_cache.pop("Record Attachment", None)
3686
+ db._text_col_cache.pop("Record Attachment", None)
3687
+ db.ensure_column("Delivery Note", "tracking_reference", "TEXT")
3688
+
3689
+
3627
3690
  def _m052_access_profiles(db: "Database") -> None:
3628
3691
  """Access profiles narrow what a user's role allows (lambda_erp.permissions).
3629
3692
  No profile is created and no user is assigned one: nothing changes for
@@ -3727,6 +3790,8 @@ Database.MIGRATIONS = [
3727
3790
  (61, "record_scope", _m061_record_scope),
3728
3791
  (62, "stock_document_pricing", _m062_stock_document_pricing),
3729
3792
  (63, "addresses", _m063_addresses),
3793
+ (64, "item_bundles", _m064_item_bundles),
3794
+ (65, "record_attachments", _m065_record_attachments),
3730
3795
  ]
3731
3796
 
3732
3797
 
@@ -346,6 +346,9 @@ class Document:
346
346
  from lambda_erp.controllers.item_prices import normalize_item_prices
347
347
  normalize_item_prices(self)
348
348
  self._normalize_timestamps(before_validate=True)
349
+ # A bundle line becomes the lines of its items before anything is priced.
350
+ from lambda_erp.bundles import expand_bundle_lines
351
+ expand_bundle_lines(self)
349
352
  from lambda_erp.addresses import resolve_document_addresses
350
353
  resolve_document_addresses(self)
351
354
  self.validate()
@@ -406,6 +409,9 @@ class Document:
406
409
  from lambda_erp.controllers.item_prices import normalize_item_prices
407
410
  normalize_item_prices(self)
408
411
  self._normalize_timestamps(before_validate=True)
412
+ # A bundle line becomes the lines of its items before anything is priced.
413
+ from lambda_erp.bundles import expand_bundle_lines
414
+ expand_bundle_lines(self)
409
415
  from lambda_erp.addresses import resolve_document_addresses
410
416
  resolve_document_addresses(self)
411
417
  self.validate()
@@ -267,6 +267,8 @@ def _core_record_scopes():
267
267
  register_record_scope(doctype, "customer", "customer", optional=True)
268
268
  register_record_scope("Address", "customer", "customer")
269
269
  register_record_scope("Address", "warehouse", unrelated=True)
270
+ for dimension in ("customer", "warehouse"):
271
+ register_record_scope("Item Bundle", dimension, unrelated=True)
270
272
  for doctype in ("Payment Entry", "Subscription", "Reservation"):
271
273
  register_record_scope(doctype, "customer", "party", when=("party_type", "Customer"))
272
274
  register_record_scope("Journal Entry", "customer", child="accounts", child_table="Journal Entry Account",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lambda-erp"
3
- version = "1.4.17"
3
+ version = "1.4.19"
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