lambda-erp 1.4.17__tar.gz → 1.4.18__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 (136) hide show
  1. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/PKG-INFO +1 -1
  2. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/chat.py +5 -0
  3. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf_profiles.py +4 -0
  4. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/services.py +2 -0
  5. lambda_erp-1.4.18/lambda_erp/bundles.py +167 -0
  6. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/database.py +38 -0
  7. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/model.py +6 -0
  8. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/permissions.py +2 -0
  9. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/pyproject.toml +1 -1
  10. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/.gitignore +0 -0
  11. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/LICENSE +0 -0
  12. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/README.md +0 -0
  13. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/__init__.py +0 -0
  14. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/attachments.py +0 -0
  15. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/auth.py +0 -0
  16. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/bootstrap.py +0 -0
  17. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/chat_links.py +0 -0
  18. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/demo_limits.py +0 -0
  19. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/deps.py +0 -0
  20. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/erp_context.py +0 -0
  21. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/errors.py +0 -0
  22. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/list_values.py +0 -0
  23. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/llm_provider.py +0 -0
  24. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/main.py +0 -0
  25. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/mcp_oauth.py +0 -0
  26. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/mentions.py +0 -0
  27. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/menu_layout.py +0 -0
  28. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/oauth.py +0 -0
  29. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf.py +0 -0
  30. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf_contract.py +0 -0
  31. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf_exports.py +0 -0
  32. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf_fonts.py +0 -0
  33. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf_pages.py +0 -0
  34. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pdf_templates.py +0 -0
  35. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/pricing_actions.py +0 -0
  36. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/providers.py +0 -0
  37. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/record_notes.py +0 -0
  38. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/remarks_md.py +0 -0
  39. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/__init__.py +0 -0
  40. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/accounting.py +0 -0
  41. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/actions.py +0 -0
  42. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/admin.py +0 -0
  43. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/analytics.py +0 -0
  44. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/availability.py +0 -0
  45. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/bank_reconciliation.py +0 -0
  46. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/bank_statements.py +0 -0
  47. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/chat_api.py +0 -0
  48. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/documents.py +0 -0
  49. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/masters.py +0 -0
  50. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/mcp.py +0 -0
  51. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/pdf_templates.py +0 -0
  52. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/proposals.py +0 -0
  53. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/reports.py +0 -0
  54. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/routers/setup.py +0 -0
  55. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/stock_actions.py +0 -0
  56. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/_proposal_totals.html +0 -0
  57. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/_record_base.html +0 -0
  58. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/delivery_note.html +0 -0
  59. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/document.html +0 -0
  60. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/proposal.html +0 -0
  61. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/record.html +0 -0
  62. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/templates/reservation.html +0 -0
  63. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/time_filters.py +0 -0
  64. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/tool_permissions.py +0 -0
  65. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/api/write_context.py +0 -0
  66. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/docs/agents/README.md +0 -0
  67. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/frontend/LICENSE +0 -0
  68. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/frontend/README.md +0 -0
  69. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/frontend/src/api/client.ts +0 -0
  70. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/__init__.py +0 -0
  71. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/__init__.py +0 -0
  72. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_account.py +0 -0
  73. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_reconciliation.py +0 -0
  74. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_statement_import.py +0 -0
  75. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_transaction.py +0 -0
  76. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/budget.py +0 -0
  77. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/camt.py +0 -0
  78. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/chart_of_accounts.py +0 -0
  79. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/general_ledger.py +0 -0
  80. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/journal_entry.py +0 -0
  81. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/payment_entry.py +0 -0
  82. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/pos_invoice.py +0 -0
  83. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/purchase_invoice.py +0 -0
  84. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/revaluation.py +0 -0
  85. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/sales_invoice.py +0 -0
  86. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/settlement.py +0 -0
  87. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/__init__.py +0 -0
  88. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/engine.py +0 -0
  89. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/pack.py +0 -0
  90. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
  91. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/ch.py +0 -0
  92. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
  93. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
  94. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
  95. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/generic.py +0 -0
  96. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/profiles.py +0 -0
  97. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/spine.py +0 -0
  98. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/accounting/subscription.py +0 -0
  99. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/addresses.py +0 -0
  100. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/assets/__init__.py +0 -0
  101. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/assets/asset.py +0 -0
  102. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/assets/lifecycle.py +0 -0
  103. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/assets/reservation.py +0 -0
  104. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/backlog.py +0 -0
  105. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/buying/__init__.py +0 -0
  106. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/buying/purchase_order.py +0 -0
  107. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/__init__.py +0 -0
  108. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/currency.py +0 -0
  109. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/defaults.py +0 -0
  110. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/item_price.py +0 -0
  111. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/item_prices.py +0 -0
  112. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/price_resolution.py +0 -0
  113. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/pricing_rule.py +0 -0
  114. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/controllers/taxes_and_totals.py +0 -0
  115. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/exceptions.py +0 -0
  116. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/hooks.py +0 -0
  117. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/master_integrity.py +0 -0
  118. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/selling/__init__.py +0 -0
  119. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/selling/proposal.py +0 -0
  120. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/selling/quotation.py +0 -0
  121. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/selling/sales_order.py +0 -0
  122. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/simulation.py +0 -0
  123. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/__init__.py +0 -0
  124. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/consignment.py +0 -0
  125. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/delivery_note.py +0 -0
  126. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/purchase_receipt.py +0 -0
  127. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/reservation.py +0 -0
  128. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/serial.py +0 -0
  129. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/stock_count.py +0 -0
  130. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/stock_entry.py +0 -0
  131. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/stock/stock_ledger.py +0 -0
  132. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/timestamps.py +0 -0
  133. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/utils.py +0 -0
  134. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/validation.py +0 -0
  135. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/lambda_erp/workflow.py +0 -0
  136. {lambda_erp-1.4.17 → lambda_erp-1.4.18}/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.18
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,11 @@ 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
+ ### Item bundles
3038
+ - 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.
3039
+ - 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.
3040
+ - When the user names a set, look for it with list_documents doctype="item-bundle" (or the item) before listing single items yourself.
3041
+
3037
3042
  ### Addresses
3038
3043
  - 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
3044
  - 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.
@@ -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')),
@@ -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 = {
@@ -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,43 @@ 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
+
3627
3664
  def _m052_access_profiles(db: "Database") -> None:
3628
3665
  """Access profiles narrow what a user's role allows (lambda_erp.permissions).
3629
3666
  No profile is created and no user is assigned one: nothing changes for
@@ -3727,6 +3764,7 @@ Database.MIGRATIONS = [
3727
3764
  (61, "record_scope", _m061_record_scope),
3728
3765
  (62, "stock_document_pricing", _m062_stock_document_pricing),
3729
3766
  (63, "addresses", _m063_addresses),
3767
+ (64, "item_bundles", _m064_item_bundles),
3730
3768
  ]
3731
3769
 
3732
3770
 
@@ -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.18"
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