lambda-erp 1.4.20__tar.gz → 1.4.22__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 (139) hide show
  1. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/PKG-INFO +3 -1
  2. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/README.md +2 -0
  3. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/chat.py +7 -0
  4. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf.py +19 -0
  5. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf_profiles.py +3 -0
  6. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf_templates.py +1 -0
  7. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/services.py +9 -35
  8. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/delivery_note.html +1 -1
  9. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/document.html +4 -3
  10. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/pos_invoice.py +2 -1
  11. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/purchase_invoice.py +2 -1
  12. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/sales_invoice.py +2 -1
  13. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/subscription.py +3 -0
  14. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/buying/purchase_order.py +2 -1
  15. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/item_price.py +38 -8
  16. lambda_erp-1.4.22/lambda_erp/controllers/tax_defaults.py +67 -0
  17. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/taxes_and_totals.py +143 -141
  18. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/database.py +30 -0
  19. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/permissions.py +20 -0
  20. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/selling/quotation.py +6 -3
  21. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/selling/sales_order.py +2 -1
  22. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/consignment.py +3 -0
  23. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/delivery_note.py +6 -3
  24. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/purchase_receipt.py +6 -3
  25. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/stock_entry.py +4 -0
  26. lambda_erp-1.4.22/lambda_erp/units.py +191 -0
  27. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/utils.py +40 -2
  28. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/pyproject.toml +1 -1
  29. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/.gitignore +0 -0
  30. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/LICENSE +0 -0
  31. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/__init__.py +0 -0
  32. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/attachments.py +0 -0
  33. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/auth.py +0 -0
  34. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/bootstrap.py +0 -0
  35. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/chat_links.py +0 -0
  36. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/demo_limits.py +0 -0
  37. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/deps.py +0 -0
  38. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/erp_context.py +0 -0
  39. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/errors.py +0 -0
  40. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/list_values.py +0 -0
  41. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/llm_provider.py +0 -0
  42. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/main.py +0 -0
  43. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/mcp_oauth.py +0 -0
  44. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/mentions.py +0 -0
  45. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/menu_layout.py +0 -0
  46. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/oauth.py +0 -0
  47. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf_contract.py +0 -0
  48. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf_exports.py +0 -0
  49. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf_fonts.py +0 -0
  50. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pdf_pages.py +0 -0
  51. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/pricing_actions.py +0 -0
  52. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/providers.py +0 -0
  53. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/record_attachments.py +0 -0
  54. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/record_notes.py +0 -0
  55. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/remarks_md.py +0 -0
  56. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/__init__.py +0 -0
  57. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/accounting.py +0 -0
  58. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/actions.py +0 -0
  59. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/admin.py +0 -0
  60. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/analytics.py +0 -0
  61. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/availability.py +0 -0
  62. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/bank_reconciliation.py +0 -0
  63. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/bank_statements.py +0 -0
  64. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/chat_api.py +0 -0
  65. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/documents.py +0 -0
  66. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/masters.py +0 -0
  67. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/mcp.py +0 -0
  68. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/pdf_templates.py +0 -0
  69. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/proposals.py +0 -0
  70. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/reports.py +0 -0
  71. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/routers/setup.py +0 -0
  72. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/stock_actions.py +0 -0
  73. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/_proposal_totals.html +0 -0
  74. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/_record_base.html +0 -0
  75. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/proposal.html +0 -0
  76. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/record.html +0 -0
  77. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/templates/reservation.html +0 -0
  78. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/time_filters.py +0 -0
  79. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/tool_permissions.py +0 -0
  80. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/api/write_context.py +0 -0
  81. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/docs/agents/README.md +0 -0
  82. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/frontend/LICENSE +0 -0
  83. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/frontend/README.md +0 -0
  84. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/frontend/src/api/client.ts +0 -0
  85. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/__init__.py +0 -0
  86. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/__init__.py +0 -0
  87. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/bank_account.py +0 -0
  88. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/bank_reconciliation.py +0 -0
  89. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/bank_statement_import.py +0 -0
  90. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/bank_transaction.py +0 -0
  91. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/budget.py +0 -0
  92. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/camt.py +0 -0
  93. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/chart_of_accounts.py +0 -0
  94. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/general_ledger.py +0 -0
  95. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/journal_entry.py +0 -0
  96. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/payment_entry.py +0 -0
  97. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/revaluation.py +0 -0
  98. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/settlement.py +0 -0
  99. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/__init__.py +0 -0
  100. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/engine.py +0 -0
  101. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/pack.py +0 -0
  102. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
  103. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/packs/ch.py +0 -0
  104. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
  105. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
  106. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
  107. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/packs/generic.py +0 -0
  108. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/profiles.py +0 -0
  109. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/accounting/setup/spine.py +0 -0
  110. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/addresses.py +0 -0
  111. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/assets/__init__.py +0 -0
  112. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/assets/asset.py +0 -0
  113. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/assets/lifecycle.py +0 -0
  114. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/assets/reservation.py +0 -0
  115. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/backlog.py +0 -0
  116. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/bundles.py +0 -0
  117. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/buying/__init__.py +0 -0
  118. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/__init__.py +0 -0
  119. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/currency.py +0 -0
  120. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/defaults.py +0 -0
  121. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/item_prices.py +0 -0
  122. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/price_resolution.py +0 -0
  123. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/controllers/pricing_rule.py +0 -0
  124. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/exceptions.py +0 -0
  125. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/hooks.py +0 -0
  126. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/master_integrity.py +0 -0
  127. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/model.py +0 -0
  128. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/selling/__init__.py +0 -0
  129. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/selling/proposal.py +0 -0
  130. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/simulation.py +0 -0
  131. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/__init__.py +0 -0
  132. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/reservation.py +0 -0
  133. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/serial.py +0 -0
  134. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/stock_count.py +0 -0
  135. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/stock/stock_ledger.py +0 -0
  136. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/timestamps.py +0 -0
  137. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/validation.py +0 -0
  138. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/lambda_erp/workflow.py +0 -0
  139. {lambda_erp-1.4.20 → lambda_erp-1.4.22}/terraform/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lambda-erp
3
- Version: 1.4.20
3
+ Version: 1.4.22
4
4
  Summary: Core ERP logic - accounting, sales, purchasing, inventory
5
5
  Author: TORUS INVESTMENTS AG
6
6
  License-Expression: Apache-2.0
@@ -34,6 +34,8 @@ Description-Content-Type: text/markdown
34
34
 
35
35
  Lambda ERP is a simpler ERP: create invoices, check inventory, answer accounting questions, and change reports by asking for what you need in plain language.
36
36
 
37
+ Developed by [Lambda](https://lambda.dev/erp).
38
+
37
39
  https://github.com/user-attachments/assets/1b2749ef-10e7-42f5-9cce-df5628292667
38
40
 
39
41
  <p align="center">
@@ -4,6 +4,8 @@
4
4
 
5
5
  Lambda ERP is a simpler ERP: create invoices, check inventory, answer accounting questions, and change reports by asking for what you need in plain language.
6
6
 
7
+ Developed by [Lambda](https://lambda.dev/erp).
8
+
7
9
  https://github.com/user-attachments/assets/1b2749ef-10e7-42f5-9cce-df5628292667
8
10
 
9
11
  <p align="center">
@@ -3060,6 +3060,13 @@ For a complete sales return (financial + stock): create and submit both a Credit
3060
3060
  - 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.
3061
3061
  - When the user names a set, look for it with list_documents doctype="item-bundle" (or the item) before listing single items yourself.
3062
3062
 
3063
+ ### Units of measure (ordering in a pack, stocking in pieces)
3064
+ - An item is stocked in its `stock_uom`. An **Item Unit** (doctype `item-unit`: item_code, uom, conversion_factor = stock units per unit, e.g. Karton = 100) gives it a further unit. List an item's units with list_documents doctype="item-unit" filtered by item_code.
3065
+ - To enter a line in such a unit, send `qty` and `rate` in that unit and name it in `uom` (qty 2, uom "Karton", rate 290). On save the line is stored per stock unit (qty 200, rate 2.90) and keeps `order_uom`, `conversion_factor` and `order_qty` (2). Amounts are unchanged: 2 x 290 = 200 x 2.90.
3066
+ - On a stored line `qty`, `rate`, delivered/billed quantities and every stock figure are in the stock unit; `order_qty` + `order_uom` say what was ordered. Tell the user both when they differ ("2 Karton = 200 Stk"). Never multiply or divide by the factor yourself before sending a line: either send the entered unit in `uom`, or send stock units.
3067
+ - A unit the item does not have is refused. Do not guess a factor from a product name or from "VE"/"Pack": ask, or have an Item Unit created first.
3068
+ - An Item Price with `uom` set is a price per that unit (290 per Karton) and is used for lines entered in it; a price without `uom` is per stock unit.
3069
+
3063
3070
  ### Addresses
3064
3071
  - 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.
3065
3072
  - 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.
@@ -110,6 +110,25 @@ def add_line_deductions(items):
110
110
  item["discount_total"], item["discount_label"] = deduction["amount"], deduction["label"]
111
111
  else:
112
112
  item["discount_total"] = 0
113
+ add_order_unit(item)
114
+
115
+
116
+ def add_order_unit(item):
117
+ """A line ordered in a further unit of the item (lambda_erp/units.py) is
118
+ stored per stock unit. For printing it also gets the price per ordered
119
+ unit: item.order_rate (and item.order_gross_rate before a deduction), next
120
+ to item.order_qty and item.order_uom. item.ordered_in_unit says whether
121
+ the line has them."""
122
+ try:
123
+ factor = float(item.get("conversion_factor") or 0)
124
+ except (TypeError, ValueError):
125
+ factor = 0
126
+ ordered = bool(item.get("order_uom")) and factor > 0
127
+ item["ordered_in_unit"] = ordered
128
+ if ordered:
129
+ item["order_rate"] = round(float(item.get("rate") or 0) * factor, 2)
130
+ if item.get("gross_rate") is not None:
131
+ item["order_gross_rate"] = round(float(item.get("gross_rate") or 0) * factor, 2)
113
132
 
114
133
 
115
134
  def fill_text_placeholders(text, doc, party_name=None, company_name=None) -> str:
@@ -107,6 +107,9 @@ PROFILES.update({
107
107
  'Price List': PDFProfile('record', 'Price list overview',
108
108
  fields=('price_list_name', 'currency', 'selling', 'buying', 'enabled'),
109
109
  required=('price_list_name', 'currency')),
110
+ 'Item Unit': PDFProfile('record', 'Item unit',
111
+ fields=('item_code', 'uom', 'conversion_factor', 'enabled'),
112
+ required=('item_code', 'uom', 'conversion_factor')),
110
113
  'Item Price': PDFProfile('record', 'Item price overview',
111
114
  fields=('item_code', 'price_list', 'customer', 'supplier', 'uom', 'min_qty', 'rate', 'valid_from', 'valid_upto', 'enabled'),
112
115
  required=('item_code', 'price_list', 'rate')),
@@ -697,6 +697,7 @@ _REFERENCES = {
697
697
  "commercial": """- doc: the document (name, transaction_date or posting_date, valid_till / due_date / delivery_date, customer or supplier and their _name, currency, net_total, total_taxes_and_charges, grand_total, outstanding_amount (invoices), is_return (credit note), remarks, status, docstatus, ...)
698
698
  <<PARTY>>- currency, meta_fields (list of {label, value})
699
699
  - items: list of {idx, item_code, item_name, description, qty, uom, rate, amount, discount_percentage, frequency}
700
+ A line ordered in a further unit of the item (2 Karton of 100) is stored per stock unit: qty 200, uom Stk, rate 2.90. Then item.ordered_in_unit is true and item.order_qty (2), item.order_uom (Karton), item.conversion_factor (100) and item.order_rate (290.00, the price per ordered unit) say what was ordered. Print order_qty + order_uom and order_rate for such a line (the stock quantity may go below); item.amount is the same either way. Never print item.rate with two decimals for it: 12.99 a carton is 0.1299 a piece.
700
701
  A line can carry a deduction (e.g. "Abzüglich bereits verrechnet"): then item.discount_total > 0 (the deduction for the whole line), item.discount_label is its text, and item.gross_rate / item.gross_amount are the full price. Print the full price on the line and a sub-line with the label and −discount_total; item.amount is the net (gross_amount − discount_total). A layout that ignores it prints only the net amount (and gets a warning).
701
702
  - taxes: list of {description, rate, tax_amount, total}
702
703
  <<TEXTS>>- recurring_summary: per billing period [{frequency, label, net_total, grand_total, ...}]; show_frequency: whether any line recurs
@@ -39,6 +39,7 @@ 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
41
  from lambda_erp.bundles import ItemBundle
42
+ from lambda_erp.units import ItemUnit
42
43
 
43
44
 
44
45
  # --- Doctype registries ---
@@ -75,6 +76,8 @@ DOCUMENT_CLASSES = {
75
76
  # Counted quantities; submitting books the differences with a reason.
76
77
  "Stock Count": StockCount,
77
78
  "Item Bundle": ItemBundle,
79
+ # A further unit of an item (carton of 100) that lines may be entered in.
80
+ "Item Unit": ItemUnit,
78
81
  }
79
82
 
80
83
  CONVERTERS = {
@@ -536,15 +539,6 @@ def get_document_class(doctype_slug: str):
536
539
  return doctype, DOCUMENT_CLASSES[doctype]
537
540
 
538
541
 
539
- # Which Company default a doc's `taxes` table draws from — keyed by the taxes
540
- # child doctype, so any doc that has a taxes table is covered without a hardcoded
541
- # doctype list. Selling -> sales default, buying -> purchase default.
542
- _TAX_CHILD_DEFAULT_FIELD = {
543
- "Sales Taxes and Charges": "default_sales_tax_template",
544
- "Purchase Taxes and Charges": "default_purchase_tax_template",
545
- }
546
-
547
-
548
542
  def _default_tax_rows(cls, data: dict) -> list | None:
549
543
  """`taxes[]` rows to seed a new document from its company's default Tax
550
544
  Template, or None to leave taxes untouched.
@@ -552,34 +546,14 @@ def _default_tax_rows(cls, data: dict) -> list | None:
552
546
  Applied ONLY when the caller omits `taxes` entirely — the exact case the chat
553
547
  model kept hitting (it forgets to add MWST). An explicit `taxes: []` is left
554
548
  alone, so a deliberately tax-free doc (export, reverse-charge, exempt) is
555
- expressed by passing an empty list. The document's own tax calc then computes
556
- `tax_amount` from the rate, so this only seeds charge_type/account/rate.
549
+ expressed by passing an empty list. The rule itself lives in the core
550
+ (lambda_erp.controllers.tax_defaults), which also applies it to invoices
551
+ the core writes on its own.
557
552
  """
558
- taxes_child = cls.CHILD_TABLES.get("taxes")
559
- if not taxes_child or "taxes" in data:
560
- return None
561
- field = _TAX_CHILD_DEFAULT_FIELD.get(taxes_child[0])
562
- company = data.get("company")
563
- if not field or not company:
564
- return None
565
- db = get_db()
566
- template = db.get_value("Company", company, field)
567
- if not template:
553
+ if "taxes" in data:
568
554
  return None
569
- details = db.get_all("Tax Template Detail", filters={"parent": template},
570
- fields=["*"], order_by="idx")
571
- if not details:
572
- return None
573
- return [
574
- {
575
- "charge_type": d.get("charge_type") or "On Net Total",
576
- "account_head": d.get("account_head"),
577
- "rate": d.get("rate") or 0,
578
- "description": d.get("description") or template,
579
- "add_deduct_tax": "Add",
580
- }
581
- for d in details
582
- ]
555
+ from lambda_erp.controllers.tax_defaults import default_tax_rows
556
+ return default_tax_rows(cls, data.get("company"))
583
557
 
584
558
 
585
559
  def document_field_metadata(doctype_slug: str) -> dict:
@@ -158,7 +158,7 @@
158
158
  <td>{{ item.item_name or item.description or "" }}{% if item.item_name and item.description and item.description != item.item_name %}<br><span style="color: #555">{{ item.description }}</span>{% endif %}</td>
159
159
  <td>{{ item.warehouse_name or item.warehouse or "" }}</td>
160
160
  <td class="num">{{ "%g"|format(item.qty or 0) }}</td>
161
- <td>{{ item.uom or "" }}</td>
161
+ <td>{{ item.uom or "" }}{% if item.order_uom and item.conversion_factor %}<br><span style="color: #555; font-size: 85%">= {{ "%g"|format(item.order_qty or 0) }} {{ item.order_uom }}</span>{% endif %}</td>
162
162
  </tr>
163
163
  {% endfor %}
164
164
  </tbody>
@@ -154,9 +154,10 @@
154
154
  <td style="font-weight: 600">{{ item.item_code or "" }}</td>
155
155
  <td>{{ item.item_name or item.description or "" }}{% if item.frequency %}<br>{{ item.frequency }}{% endif %}</td>
156
156
  {% if show_warehouse %}<td>{{ item.warehouse or "" }}</td>{% endif %}
157
- <td class="num">{{ item.qty }}</td>
157
+ {# A line ordered in a further unit prints that unit and its price; the stock quantity below. #}
158
+ <td class="num">{% if item.ordered_in_unit %}{{ "%g"|format(item.order_qty or 0) }} {{ item.order_uom }}<br><span style="color: #555; font-size: 85%">= {{ "%g"|format(item.qty or 0) }} {{ item.uom or "" }}</span>{% else %}{{ item.qty }}{% endif %}</td>
158
159
  {% if item.discount_total %}
159
- <td class="num">{{ "%.2f"|format(item.gross_rate) }}</td>
160
+ <td class="num">{{ "%.2f"|format(item.order_gross_rate if item.ordered_in_unit else item.gross_rate) }}</td>
160
161
  <td class="num">{{ "%.2f"|format(item.gross_amount) }}</td>
161
162
  </tr>
162
163
  <tr class="deduction">
@@ -168,7 +169,7 @@
168
169
  <td></td>
169
170
  <td class="num">&minus;{{ "%.2f"|format(item.discount_total) }}</td>
170
171
  {% else %}
171
- <td class="num">{{ "%.2f"|format(item.rate or 0) }}</td>
172
+ <td class="num">{{ "%.2f"|format(item.order_rate if item.ordered_in_unit else (item.rate or 0)) }}</td>
172
173
  <td class="num">{{ "%.2f"|format(item.amount) }}</td>
173
174
  {% endif %}
174
175
  </tr>
@@ -336,7 +336,8 @@ def make_pos_return(posi_name):
336
336
  item_name=item.get("item_name"),
337
337
  description=item.get("description"),
338
338
  qty=-flt(item.get("qty")),
339
- uom=item.get("uom"),
339
+ uom=item.get("uom"), order_uom=item.get("order_uom"),
340
+ conversion_factor=item.get("conversion_factor"),
340
341
  rate=flt(item.get("rate")),
341
342
  income_account=item.get("income_account"),
342
343
  cost_center=item.get("cost_center"),
@@ -469,7 +469,8 @@ def make_purchase_return(pinv_name):
469
469
  item_name=item.get("item_name"),
470
470
  description=item.get("description"),
471
471
  qty=-flt(item.get("qty")),
472
- uom=item.get("uom"),
472
+ uom=item.get("uom"), order_uom=item.get("order_uom"),
473
+ conversion_factor=item.get("conversion_factor"),
473
474
  rate=flt(item.get("rate")),
474
475
  expense_account=item.get("expense_account"),
475
476
  cost_center=item.get("cost_center"),
@@ -457,7 +457,8 @@ def make_sales_return(sinv_name):
457
457
  item_name=item.get("item_name"),
458
458
  description=item.get("description"),
459
459
  qty=-flt(item.get("qty")),
460
- uom=item.get("uom"),
460
+ uom=item.get("uom"), order_uom=item.get("order_uom"),
461
+ conversion_factor=item.get("conversion_factor"),
461
462
  rate=flt(item.get("rate")),
462
463
  income_account=item.get("income_account"),
463
464
  cost_center=item.get("cost_center"),
@@ -183,5 +183,8 @@ class Subscription(Document):
183
183
  rate=flt(plan.get("rate", 0)),
184
184
  ))
185
185
 
186
+ # A subscription names no taxes of its own: the company's default applies.
187
+ from lambda_erp.controllers.tax_defaults import apply_default_taxes
188
+ apply_default_taxes(invoice)
186
189
  invoice.save()
187
190
  return invoice
@@ -118,7 +118,8 @@ def make_purchase_invoice(purchase_order_name):
118
118
  item_name=item.get("item_name"),
119
119
  description=item.get("description"),
120
120
  qty=unbilled,
121
- uom=item.get("uom"),
121
+ uom=item.get("uom"), order_uom=item.get("order_uom"),
122
+ conversion_factor=item.get("conversion_factor"),
122
123
  rate=item.get("rate"),
123
124
  warehouse=item.get("warehouse"),
124
125
  purchase_order=po.name,
@@ -28,6 +28,7 @@ import math
28
28
  from lambda_erp.model import Document
29
29
  from lambda_erp.utils import flt, getdate, nowdate
30
30
  from lambda_erp.database import get_db
31
+ from lambda_erp import units
31
32
  from lambda_erp.exceptions import ValidationError
32
33
 
33
34
 
@@ -244,7 +245,9 @@ def set_item_defaults(doc, party_type=None, party_field=None, *, set_description
244
245
  stamps = "price_source" in db._get_table_columns(doc.CHILD_TABLES["items"][0]) \
245
246
  if "items" in getattr(doc, "CHILD_TABLES", {}) else False
246
247
 
247
- for item in doc.get("items") or []:
248
+ unit_columns = units.has_unit_columns(doc)
249
+
250
+ for position, item in enumerate(doc.get("items") or [], 1):
248
251
  item_code = item.get("item_code")
249
252
  if not item_code:
250
253
  continue
@@ -255,6 +258,15 @@ def set_item_defaults(doc, party_type=None, party_field=None, *, set_description
255
258
  if not item_data:
256
259
  continue
257
260
 
261
+ # A line entered in one of the item's further units (2 Karton) is
262
+ # converted to the stock unit here, before it is priced; see units.py.
263
+ factor = entered_uom = entered_qty = None
264
+ if unit_columns:
265
+ factor = units.pending_factor(item, item_data.stock_uom, f"{doc.DOCTYPE} row {position}")
266
+ if factor:
267
+ entered_uom = str(item.get("uom")).strip()
268
+ entered_qty = units.convert_line(item, item_data.stock_uom, factor)
269
+
258
270
  if not item.get("item_name"):
259
271
  item["item_name"] = item_data.item_name
260
272
  if set_description:
@@ -262,13 +274,28 @@ def set_item_defaults(doc, party_type=None, party_field=None, *, set_description
262
274
  item["uom"] = item.get("uom") or item_data.stock_uom
263
275
 
264
276
  if item.get("rate") is None and item.get("price_list_rate") is None:
265
- row = find_item_price(
266
- item_code, price_list,
267
- qty=flt(item.get("qty", 0)),
268
- party_field=party_field, party=party,
269
- uom=item.get("uom") or item_data.stock_uom,
270
- date=date,
271
- )
277
+ # A price quoted for the entered unit (290.00 per Karton) comes
278
+ # first and is taken per stock unit; else the price per stock
279
+ # unit, with volume breaks counted in stock units.
280
+ row = unit_row = None
281
+ if factor:
282
+ unit_row = find_item_price(
283
+ item_code, price_list, qty=entered_qty,
284
+ party_field=party_field, party=party, uom=entered_uom, date=date)
285
+ if unit_row is not None and unit_row.get("uom") != entered_uom:
286
+ unit_row = None
287
+ row = unit_row
288
+ if row is None:
289
+ row = find_item_price(
290
+ item_code, price_list,
291
+ qty=flt(item.get("qty", 0)),
292
+ party_field=party_field, party=party,
293
+ uom=item.get("uom") or item_data.stock_uom,
294
+ date=date,
295
+ )
296
+ if unit_row is not None:
297
+ row = dict(row)
298
+ row["rate"] = flt(row["rate"]) / factor
272
299
  # Where the base price came from is kept on the line
273
300
  # (price_source / price_reference), see price_resolution.py.
274
301
  if row is None:
@@ -282,3 +309,6 @@ def set_item_defaults(doc, party_type=None, party_field=None, *, set_description
282
309
  item["price_source"], item["price_reference"] = source, reference
283
310
  from lambda_erp.controllers import price_resolution
284
311
  price_resolution.trace_base(item, source, reference, price_list, row)
312
+
313
+ if unit_columns:
314
+ units.stamp_order_qty(item)
@@ -0,0 +1,67 @@
1
+ """The company's default taxes for a new document.
2
+
3
+ A company names a default sales and a default purchase Tax Template. A new
4
+ document that says nothing about taxes gets the rows of the template for its
5
+ side, whoever creates it: the document service (form, REST, chat, MCP) or the
6
+ core itself when it writes an invoice (consignment withdrawal, subscription).
7
+
8
+ taxes not given the company's default rows, if it has a template
9
+ taxes given as [] deliberately no tax (export, exempt): left empty
10
+ taxes given kept as they are, nothing added
11
+
12
+ The rows are copied into the document. From then on they are the document's
13
+ own: a later change of the template or of the company default reaches new
14
+ documents only.
15
+ """
16
+ from lambda_erp.database import get_db
17
+
18
+ # The taxes child table decides the side, so every document type with a
19
+ # taxes table is covered without a list of types.
20
+ TEMPLATE_FIELDS = {
21
+ "Sales Taxes and Charges": "default_sales_tax_template",
22
+ "Purchase Taxes and Charges": "default_purchase_tax_template",
23
+ }
24
+
25
+
26
+ def default_tax_rows(document_class, company):
27
+ """The tax rows a new document of this class takes from its company's
28
+ default Tax Template, or None when the class has no taxes, the company
29
+ names no template for its side, or the template is empty."""
30
+ taxes_child = getattr(document_class, "CHILD_TABLES", {}).get("taxes")
31
+ field = TEMPLATE_FIELDS.get(taxes_child[0]) if taxes_child else None
32
+ if not field or not company:
33
+ return None
34
+ db = get_db()
35
+ template = db.get_value("Company", company, field)
36
+ if not template:
37
+ return None
38
+ # A template of another company is not this company's default.
39
+ owner = db.get_value("Tax Template", template, "company")
40
+ if owner and owner != company:
41
+ return None
42
+ details = db.get_all("Tax Template Detail", filters={"parent": template}, fields=["*"], order_by="idx")
43
+ if not details:
44
+ return None
45
+ return [{
46
+ "charge_type": detail.get("charge_type") or "On Net Total",
47
+ "account_head": detail.get("account_head"),
48
+ "rate": detail.get("rate") or 0,
49
+ "description": detail.get("description") or template,
50
+ "add_deduct_tax": "Add",
51
+ } for detail in details]
52
+
53
+
54
+ def apply_default_taxes(doc):
55
+ """Give a document the core has just built, and that carries no tax rows,
56
+ its company's default taxes. For invoices written from something that has
57
+ no taxes of its own; a document made from another one copies that one's
58
+ rows instead. Returns True when rows were added."""
59
+ if doc.get("taxes"):
60
+ return False
61
+ rows = default_tax_rows(type(doc), doc.get("company"))
62
+ if not rows:
63
+ return False
64
+ from lambda_erp.utils import _dict
65
+ for row in rows:
66
+ doc.append("taxes", _dict(row))
67
+ return True