lambda-erp 1.4.15__tar.gz → 1.4.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/PKG-INFO +1 -1
  2. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/auth.py +8 -0
  3. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/chat.py +2 -0
  4. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/masters.py +1 -0
  5. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/services.py +4 -1
  6. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/price_resolution.py +1 -1
  7. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/pricing_rule.py +2 -2
  8. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/database.py +26 -0
  9. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/delivery_note.py +14 -15
  10. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/purchase_receipt.py +74 -15
  11. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/reservation.py +167 -17
  12. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/workflow.py +54 -33
  13. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/pyproject.toml +1 -1
  14. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/.gitignore +0 -0
  15. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/LICENSE +0 -0
  16. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/README.md +0 -0
  17. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/__init__.py +0 -0
  18. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/attachments.py +0 -0
  19. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/bootstrap.py +0 -0
  20. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/chat_links.py +0 -0
  21. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/demo_limits.py +0 -0
  22. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/deps.py +0 -0
  23. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/erp_context.py +0 -0
  24. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/errors.py +0 -0
  25. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/list_values.py +0 -0
  26. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/llm_provider.py +0 -0
  27. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/main.py +0 -0
  28. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/mcp_oauth.py +0 -0
  29. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/mentions.py +0 -0
  30. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/menu_layout.py +0 -0
  31. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/oauth.py +0 -0
  32. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf.py +0 -0
  33. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf_contract.py +0 -0
  34. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf_exports.py +0 -0
  35. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf_fonts.py +0 -0
  36. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf_pages.py +0 -0
  37. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf_profiles.py +0 -0
  38. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pdf_templates.py +0 -0
  39. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/pricing_actions.py +0 -0
  40. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/providers.py +0 -0
  41. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/record_notes.py +0 -0
  42. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/remarks_md.py +0 -0
  43. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/__init__.py +0 -0
  44. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/accounting.py +0 -0
  45. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/actions.py +0 -0
  46. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/admin.py +0 -0
  47. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/analytics.py +0 -0
  48. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/availability.py +0 -0
  49. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/bank_reconciliation.py +0 -0
  50. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/bank_statements.py +0 -0
  51. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/chat_api.py +0 -0
  52. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/documents.py +0 -0
  53. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/mcp.py +0 -0
  54. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/pdf_templates.py +0 -0
  55. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/proposals.py +0 -0
  56. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/reports.py +0 -0
  57. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/routers/setup.py +0 -0
  58. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/stock_actions.py +0 -0
  59. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/_proposal_totals.html +0 -0
  60. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/_record_base.html +0 -0
  61. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/delivery_note.html +0 -0
  62. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/document.html +0 -0
  63. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/proposal.html +0 -0
  64. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/record.html +0 -0
  65. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/templates/reservation.html +0 -0
  66. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/time_filters.py +0 -0
  67. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/tool_permissions.py +0 -0
  68. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/api/write_context.py +0 -0
  69. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/docs/agents/README.md +0 -0
  70. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/frontend/LICENSE +0 -0
  71. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/frontend/README.md +0 -0
  72. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/frontend/src/api/client.ts +0 -0
  73. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/__init__.py +0 -0
  74. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/__init__.py +0 -0
  75. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_account.py +0 -0
  76. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_reconciliation.py +0 -0
  77. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_statement_import.py +0 -0
  78. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/bank_transaction.py +0 -0
  79. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/budget.py +0 -0
  80. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/camt.py +0 -0
  81. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/chart_of_accounts.py +0 -0
  82. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/general_ledger.py +0 -0
  83. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/journal_entry.py +0 -0
  84. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/payment_entry.py +0 -0
  85. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/pos_invoice.py +0 -0
  86. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/purchase_invoice.py +0 -0
  87. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/revaluation.py +0 -0
  88. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/sales_invoice.py +0 -0
  89. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/settlement.py +0 -0
  90. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/__init__.py +0 -0
  91. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/engine.py +0 -0
  92. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/pack.py +0 -0
  93. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
  94. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/ch.py +0 -0
  95. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
  96. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
  97. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
  98. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/packs/generic.py +0 -0
  99. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/profiles.py +0 -0
  100. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/setup/spine.py +0 -0
  101. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/accounting/subscription.py +0 -0
  102. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/assets/__init__.py +0 -0
  103. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/assets/asset.py +0 -0
  104. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/assets/lifecycle.py +0 -0
  105. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/assets/reservation.py +0 -0
  106. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/backlog.py +0 -0
  107. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/buying/__init__.py +0 -0
  108. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/buying/purchase_order.py +0 -0
  109. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/__init__.py +0 -0
  110. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/currency.py +0 -0
  111. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/defaults.py +0 -0
  112. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/item_price.py +0 -0
  113. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/item_prices.py +0 -0
  114. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/controllers/taxes_and_totals.py +0 -0
  115. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/exceptions.py +0 -0
  116. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/hooks.py +0 -0
  117. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/master_integrity.py +0 -0
  118. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/model.py +0 -0
  119. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/permissions.py +0 -0
  120. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/selling/__init__.py +0 -0
  121. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/selling/proposal.py +0 -0
  122. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/selling/quotation.py +0 -0
  123. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/selling/sales_order.py +0 -0
  124. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/simulation.py +0 -0
  125. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/__init__.py +0 -0
  126. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/consignment.py +0 -0
  127. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/serial.py +0 -0
  128. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/stock_count.py +0 -0
  129. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/stock_entry.py +0 -0
  130. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/stock/stock_ledger.py +0 -0
  131. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/timestamps.py +0 -0
  132. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/utils.py +0 -0
  133. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/lambda_erp/validation.py +0 -0
  134. {lambda_erp-1.4.15 → lambda_erp-1.4.16}/terraform/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lambda-erp
3
- Version: 1.4.15
3
+ Version: 1.4.16
4
4
  Summary: Core ERP logic - accounting, sales, purchasing, inventory
5
5
  Author: TORUS INVESTMENTS AG
6
6
  License-Expression: Apache-2.0
@@ -584,6 +584,14 @@ def _describe_restrictions(user):
584
584
  names = {route.path.rsplit("/", 1)[-1] for route in reports.router.routes
585
585
  if getattr(route, "path", "").startswith("/reports/") and "{" not in route.path}
586
586
  names |= set(services.REGISTERED_REPORTS)
587
+ # Fields hidden on document types the user can open, so a form does
588
+ # not show inputs for them: {slug: {"" | child key: [field, ...]}}.
589
+ hidden = {}
590
+ for slug, doctype in services.SLUG_TO_DOCTYPE.items():
591
+ plan = permissions.hidden_write_plan(doctype)
592
+ if plan and permissions.can(doctype, "read"):
593
+ hidden[slug] = {child: sorted(fields) for child, fields in plan.items()}
594
+ described["hidden_fields"] = hidden
587
595
  described["denied_reports"] = sorted(name for name in names if permissions.artifact_denied("report", name))
588
596
  return described
589
597
 
@@ -3009,6 +3009,8 @@ For a complete sales return (financial + stock): create and submit both a Credit
3009
3009
  - Order progress is derived from the submitted documents, per order line: delivered_qty (net of returns), returned_qty, billed_qty. Never set them. Open = qty − delivered_qty.
3010
3010
  - A delivery for less than ordered leaves the rest of the line open; convert the order again later for the remainder. Converters only ever propose what is left, and submit rechecks, so a repeated conversion cannot deliver or bill twice.
3011
3011
  - Deliver first, invoice after: convert the submitted **Delivery Note** to a Sales Invoice (convert_document doctype="delivery-note", target_doctype="Sales Invoice"). It bills what that delivery delivered and has not been billed, and does not move stock again. Converting the Sales Order to a Sales Invoice instead bills the ordered quantity regardless of delivery.
3012
+ - Receive first, invoice after works the same on the purchasing side: convert the submitted **Purchase Receipt** to a Purchase Invoice (convert_document doctype="purchase-receipt", target_doctype="Purchase Invoice"). It bills what was received and not billed, at the received price, and does not move stock again.
3013
+ - A Stock Reservation can name `batch_no` and / or `location` to hold exactly that stock; without them it holds a quantity in the warehouse and the batch is decided when picking.
3012
3014
  - "What is still open / on backorder / can go out now" → sales-backlog report. "Is it on order, and when does it come" → the same report's purchase order columns, or purchase-backlog.
3013
3015
  - When a supplier's order confirmation arrives, record its date with the `confirm_purchase_order` action.
3014
3016
 
@@ -221,6 +221,7 @@ def _normalize_master_data(data: dict) -> dict:
221
221
 
222
222
  MASTER_LINK_FIELDS = {
223
223
  'customer': {'default_price_list': 'Price List'},
224
+ 'supplier': {'default_price_list': 'Price List'},
224
225
  'company': {'default_price_list': 'Price List'},
225
226
  'item': {'default_warehouse': 'Warehouse'},
226
227
  'warehouse': {'company': 'Company', 'account': 'Account', 'parent_warehouse': 'Warehouse',
@@ -23,7 +23,9 @@ from lambda_erp.stock.stock_entry import StockEntry
23
23
  from lambda_erp.stock.delivery_note import (
24
24
  DeliveryNote, make_delivery_note, make_delivery_return, make_sales_invoice_from_delivery_note,
25
25
  )
26
- from lambda_erp.stock.purchase_receipt import PurchaseReceipt, make_purchase_receipt, make_purchase_receipt_return
26
+ from lambda_erp.stock.purchase_receipt import (
27
+ PurchaseReceipt, make_purchase_receipt, make_purchase_receipt_return, make_purchase_invoice_from_purchase_receipt,
28
+ )
27
29
  from lambda_erp.accounting.pos_invoice import POSInvoice
28
30
  from lambda_erp.controllers.pricing_rule import PricingRule
29
31
  from lambda_erp.controllers.item_price import PriceList, ItemPrice
@@ -82,6 +84,7 @@ CONVERTERS = {
82
84
  ("Delivery Note", "Sales Invoice"): make_sales_invoice_from_delivery_note,
83
85
  ("Purchase Order", "Purchase Invoice"): make_purchase_invoice,
84
86
  ("Purchase Order", "Purchase Receipt"): make_purchase_receipt,
87
+ ("Purchase Receipt", "Purchase Invoice"): make_purchase_invoice_from_purchase_receipt,
85
88
  # Returns (same-to-same conversion creates a return document)
86
89
  ("Sales Invoice", "Sales Invoice"): make_sales_return,
87
90
  ("Purchase Invoice", "Purchase Invoice"): make_purchase_return,
@@ -158,7 +158,7 @@ _CLASSES = {
158
158
  "Purchase Order": ("lambda_erp.buying.purchase_order", "PurchaseOrder"),
159
159
  "Purchase Invoice": ("lambda_erp.accounting.purchase_invoice", "PurchaseInvoice"),
160
160
  }
161
- _BUYING = ("Purchase Order", "Purchase Invoice")
161
+ _BUYING = ("Purchase Order", "Purchase Invoice", "Purchase Receipt")
162
162
 
163
163
 
164
164
  def _document_class(doctype):
@@ -52,8 +52,8 @@ APPLICABLE_FOR = ("Customer", "Customer Group", "Territory", "Supplier", "Suppli
52
52
  # schema, so relaxing that check — for a till that rings up anonymous sales —
53
53
  # would make both flags false, match no rule, and silently price at base rate
54
54
  # instead of raising. Trade side is a property of the document type; say so.
55
- SELLING_DOCTYPES = {"Quotation", "Sales Order", "Sales Invoice", "POS Invoice"}
56
- BUYING_DOCTYPES = {"Purchase Order", "Purchase Invoice"}
55
+ SELLING_DOCTYPES = {"Quotation", "Sales Order", "Sales Invoice", "POS Invoice", "Delivery Note"}
56
+ BUYING_DOCTYPES = {"Purchase Order", "Purchase Invoice", "Purchase Receipt"}
57
57
 
58
58
 
59
59
  class PricingRule(Document):
@@ -3561,6 +3561,31 @@ def _m061_record_scope(db: "Database") -> None:
3561
3561
  db.ensure_column("Report Draft", "access_stamp", "TEXT")
3562
3562
 
3563
3563
 
3564
+ def _m062_stock_document_pricing(db: "Database") -> None:
3565
+ """Delivery notes and purchase receipts price their lines like orders and
3566
+ invoices do; a purchase invoice can bill a receipt line; a stock
3567
+ reservation can name a batch and a storage location.
3568
+
3569
+ Lines that exist keep their price: they are marked so that pricing rules
3570
+ do not run on them when a draft is saved again."""
3571
+ for doc_table, item_table in (("Delivery Note", "Delivery Note Item"), ("Purchase Receipt", "Purchase Receipt Item")):
3572
+ db.ensure_column(doc_table, "pricing_date", "TEXT")
3573
+ fresh = "ignore_pricing_rule" not in db._get_table_columns(item_table)
3574
+ db.ensure_column(item_table, "pricing_rule", "TEXT")
3575
+ db.ensure_column(item_table, "ignore_pricing_rule", "INTEGER DEFAULT 0")
3576
+ db.ensure_column(item_table, "price_source", "TEXT")
3577
+ db.ensure_column(item_table, "price_reference", "TEXT")
3578
+ if fresh:
3579
+ db.sql(f'UPDATE "{item_table}" SET ignore_pricing_rule = 1')
3580
+ db.ensure_column("Purchase Receipt Item", "billed_qty", "REAL DEFAULT 0")
3581
+ db.ensure_column("Purchase Invoice Item", "purchase_receipt", "TEXT")
3582
+ db.ensure_column("Purchase Invoice Item", "pr_detail", "TEXT")
3583
+ db.ensure_column("Stock Reservation", "batch_no", "TEXT")
3584
+ db.ensure_column("Stock Reservation", "location", "TEXT")
3585
+ # A supplier's own buying price list, as a customer has a selling one.
3586
+ db.ensure_column("Supplier", "default_price_list", "TEXT")
3587
+
3588
+
3564
3589
  def _m052_access_profiles(db: "Database") -> None:
3565
3590
  """Access profiles narrow what a user's role allows (lambda_erp.permissions).
3566
3591
  No profile is created and no user is assigned one: nothing changes for
@@ -3662,6 +3687,7 @@ Database.MIGRATIONS = [
3662
3687
  (59, "batch_change_log", _m059_batch_change_log),
3663
3688
  (60, "serial_numbers", _m060_serial_numbers),
3664
3689
  (61, "record_scope", _m061_record_scope),
3690
+ (62, "stock_document_pricing", _m062_stock_document_pricing),
3665
3691
  ]
3666
3692
 
3667
3693
 
@@ -14,7 +14,7 @@ from lambda_erp.model import Document
14
14
  from lambda_erp.utils import _dict, flt, nowdate
15
15
  from lambda_erp.database import get_db
16
16
  from lambda_erp.controllers.taxes_and_totals import calculate_taxes_and_totals
17
- from lambda_erp.controllers.defaults import set_default_currency
17
+ from lambda_erp.controllers.defaults import set_default_currency, derived_line_pricing_fields as agreed_line_price
18
18
  from lambda_erp.exceptions import ValidationError
19
19
  from lambda_erp.stock.stock_ledger import (
20
20
  make_cancel_sl_entries,
@@ -60,12 +60,13 @@ class DeliveryNote(Document):
60
60
  self.posting_date = nowdate()
61
61
 
62
62
  self._set_customer_name()
63
+ # The price list is chosen by currency, so the currency comes first.
64
+ set_default_currency(self, "Customer", "customer")
63
65
  self._set_item_defaults()
64
66
 
65
67
  if self.is_return:
66
68
  self._validate_return()
67
69
 
68
- set_default_currency(self, "Customer", "customer")
69
70
  calculate_taxes_and_totals(self)
70
71
  self._set_status()
71
72
 
@@ -75,19 +76,13 @@ class DeliveryNote(Document):
75
76
  self.customer_name = db.get_value("Customer", self.customer, "customer_name")
76
77
 
77
78
  def _set_item_defaults(self):
78
- db = get_db()
79
- for item in self.get("items"):
80
- if item.get("item_code") and not item.get("item_name"):
81
- item_data = db.get_value(
82
- "Item", item["item_code"],
83
- ["item_name", "description", "stock_uom", "standard_rate"]
84
- )
85
- if item_data:
86
- item["item_name"] = item_data.item_name
87
- item["description"] = item.get("description") or item_data.description
88
- item["uom"] = item.get("uom") or item_data.stock_uom
89
- if item.get("rate") is None and item.get("price_list_rate") is None:
90
- item["rate"] = flt(item_data.standard_rate)
79
+ # The same price resolution as orders and invoices: price list,
80
+ # customer-specific prices, then pricing rules. Lines that come from
81
+ # an order carry its price and are left alone.
82
+ from lambda_erp.controllers.item_price import set_item_defaults
83
+ from lambda_erp.controllers.pricing_rule import apply_pricing_rules
84
+ set_item_defaults(self, "Customer", "customer")
85
+ apply_pricing_rules(self)
91
86
 
92
87
  def _validate_return(self):
93
88
  from lambda_erp.workflow import validate_return
@@ -187,6 +182,8 @@ def make_delivery_note(sales_order_name):
187
182
  # is a proposal on a draft; nothing is reserved or moved by it.
188
183
  for pick in _proposed_picks(so, item, undelivered):
189
184
  dn.append("items", _dict(
185
+ # The price was agreed in the source document: pricing rules do not run again.
186
+ **agreed_line_price(item),
190
187
  item_code=item.get("item_code"),
191
188
  item_name=item.get("item_name"),
192
189
  description=item.get("description"),
@@ -234,6 +231,8 @@ def make_delivery_return(dn_name):
234
231
  from lambda_erp.workflow import returnable_rows
235
232
  for item in returnable_rows(original):
236
233
  return_dn.append("items", _dict(
234
+ # The price was agreed in the source document: pricing rules do not run again.
235
+ **agreed_line_price(item),
237
236
  item_code=item.get("item_code"),
238
237
  item_name=item.get("item_name"),
239
238
  description=item.get("description"),
@@ -14,7 +14,7 @@ from lambda_erp.model import Document
14
14
  from lambda_erp.utils import _dict, flt, nowdate
15
15
  from lambda_erp.database import get_db
16
16
  from lambda_erp.controllers.taxes_and_totals import calculate_taxes_and_totals
17
- from lambda_erp.controllers.defaults import set_default_currency
17
+ from lambda_erp.controllers.defaults import set_default_currency, derived_line_pricing_fields as agreed_line_price
18
18
  from lambda_erp.exceptions import ValidationError
19
19
  from lambda_erp.stock.stock_ledger import make_cancel_sl_entries, make_sl_entries, reverse_stock_sles, stock_account_for
20
20
  from lambda_erp.accounting.general_ledger import make_gl_entries, make_reverse_gl_entries, to_base_currency
@@ -52,12 +52,13 @@ class PurchaseReceipt(Document):
52
52
  self.posting_date = nowdate()
53
53
 
54
54
  self._set_supplier_name()
55
+ # The price list is chosen by currency, so the currency comes first.
56
+ set_default_currency(self, "Supplier", "supplier")
55
57
  self._set_item_defaults()
56
58
 
57
59
  if self.is_return:
58
60
  self._validate_return()
59
61
 
60
- set_default_currency(self, "Supplier", "supplier")
61
62
  calculate_taxes_and_totals(self)
62
63
  self._set_status()
63
64
 
@@ -67,19 +68,13 @@ class PurchaseReceipt(Document):
67
68
  self.supplier_name = db.get_value("Supplier", self.supplier, "supplier_name")
68
69
 
69
70
  def _set_item_defaults(self):
70
- db = get_db()
71
- for item in self.get("items"):
72
- if item.get("item_code") and not item.get("item_name"):
73
- item_data = db.get_value(
74
- "Item", item["item_code"],
75
- ["item_name", "description", "stock_uom", "standard_rate"]
76
- )
77
- if item_data:
78
- item["item_name"] = item_data.item_name
79
- item["description"] = item.get("description") or item_data.description
80
- item["uom"] = item.get("uom") or item_data.stock_uom
81
- if item.get("rate") is None and item.get("price_list_rate") is None:
82
- item["rate"] = flt(item_data.standard_rate)
71
+ # The same price resolution as orders and invoices: price list,
72
+ # supplier-specific prices, then pricing rules. Lines that come from
73
+ # an order carry its price and are left alone.
74
+ from lambda_erp.controllers.item_price import set_item_defaults
75
+ from lambda_erp.controllers.pricing_rule import apply_pricing_rules
76
+ set_item_defaults(self, "Supplier", "supplier")
77
+ apply_pricing_rules(self)
83
78
 
84
79
  def _validate_return(self):
85
80
  from lambda_erp.workflow import validate_return
@@ -262,6 +257,8 @@ def make_purchase_receipt(purchase_order_name):
262
257
  if unreceived <= 0:
263
258
  continue
264
259
  pr.append("items", _dict(
260
+ # The price was agreed in the source document: pricing rules do not run again.
261
+ **agreed_line_price(item),
265
262
  item_code=item.get("item_code"),
266
263
  item_name=item.get("item_name"),
267
264
  description=item.get("description"),
@@ -306,6 +303,8 @@ def make_purchase_receipt_return(prec_name):
306
303
  from lambda_erp.workflow import returnable_rows
307
304
  for item in returnable_rows(original):
308
305
  return_pr.append("items", _dict(
306
+ # The price was agreed in the source document: pricing rules do not run again.
307
+ **agreed_line_price(item),
309
308
  item_code=item.get("item_code"),
310
309
  item_name=item.get("item_name"),
311
310
  description=item.get("description"),
@@ -321,3 +320,63 @@ def make_purchase_receipt_return(prec_name):
321
320
  ))
322
321
 
323
322
  return return_pr
323
+
324
+
325
+ def make_purchase_invoice_from_purchase_receipt(receipt_name):
326
+ """Bill what a purchase receipt received and has not been billed yet.
327
+
328
+ Receive first, invoice afterwards: the invoice lines point back to the
329
+ receipt lines (and to the order lines behind them), carry the received
330
+ price, and do not move stock again."""
331
+ from lambda_erp.accounting.purchase_invoice import PurchaseInvoice
332
+ from lambda_erp.controllers.defaults import derived_line_pricing_fields
333
+
334
+ receipt = PurchaseReceipt.load(receipt_name)
335
+ if receipt.docstatus != 1:
336
+ raise ValidationError("Purchase Receipt must be submitted before creating a Purchase Invoice")
337
+ if receipt.is_return:
338
+ raise ValidationError("A return to the supplier is credited from the original invoice, not invoiced")
339
+
340
+ invoice = PurchaseInvoice(
341
+ supplier=receipt.supplier,
342
+ supplier_name=receipt.supplier_name,
343
+ company=receipt.company,
344
+ currency=receipt.currency,
345
+ conversion_rate=receipt.conversion_rate,
346
+ posting_date=nowdate(),
347
+ update_stock=0,
348
+ )
349
+ for item in receipt.get("items"):
350
+ unbilled = flt(item.get("qty")) - flt(item.get("billed_qty"))
351
+ if unbilled <= 0:
352
+ continue
353
+ invoice.append("items", _dict(
354
+ **derived_line_pricing_fields(item),
355
+ item_code=item.get("item_code"),
356
+ item_name=item.get("item_name"),
357
+ description=item.get("description"),
358
+ qty=unbilled,
359
+ uom=item.get("uom"),
360
+ rate=item.get("rate"),
361
+ price_list_rate=item.get("price_list_rate"),
362
+ discount_percentage=item.get("discount_percentage"),
363
+ discount_amount=item.get("discount_amount"),
364
+ warehouse=item.get("warehouse"),
365
+ purchase_order=item.get("against_purchase_order"),
366
+ purchase_order_item=item.get("po_detail"),
367
+ purchase_receipt=receipt.name,
368
+ pr_detail=item.get("name"),
369
+ ))
370
+ if not invoice.get("items"):
371
+ raise ValidationError(f"Purchase Receipt {receipt.name} is already billed in full")
372
+ for tax in receipt.get("taxes") or []:
373
+ invoice.append("taxes", _dict(
374
+ charge_type=tax.get("charge_type"),
375
+ account_head=tax.get("account_head"),
376
+ description=tax.get("description"),
377
+ rate=tax.get("rate"),
378
+ tax_amount=0,
379
+ included_in_print_rate=tax.get("included_in_print_rate"),
380
+ ))
381
+ return invoice
382
+
@@ -14,6 +14,11 @@ A reservation is hard: no stock movement may take what is reserved for
14
14
  someone else. What is still open on an order-linked reservation is derived
15
15
  from the order line's delivered quantity, never counted separately.
16
16
 
17
+ A reservation holds a quantity in a warehouse. It can also name a batch
18
+ and / or a storage location: then that stock is held, and nobody else can
19
+ take it out of that batch or place, even when the warehouse as a whole
20
+ still has enough.
21
+
17
22
  Picking follows FEFO (first expired, first out). That is a physical picking
18
23
  strategy; it has nothing to do with valuation, which stays moving average.
19
24
 
@@ -125,10 +130,73 @@ def open_reserved(item_code, warehouse, *, exclude=None, exclude_order_item=None
125
130
  return flt(get_db().sql(sql, params)[0]["qty"])
126
131
 
127
132
 
133
+ def _pin_filter(batch_no="", location=""):
134
+ sql, params = "", []
135
+ if batch_no:
136
+ sql += " AND r.batch_no = ?"
137
+ params.append(batch_no)
138
+ if location:
139
+ sql += " AND r.location = ?"
140
+ params.append(location)
141
+ return sql, params
142
+
143
+
144
+ def pinned_reserved(item_code, warehouse, batch_no="", location="", *, exclude=None, exclude_order_item=None):
145
+ """Open quantity of the reservations that name this batch and / or this
146
+ storage location (a reservation naming both counts for each)."""
147
+ if not batch_no and not location:
148
+ return 0.0
149
+ pin, pin_params = _pin_filter(batch_no, location)
150
+ sql = (f"SELECT COALESCE(SUM({_OPEN_QTY}), 0) AS qty {_OPEN_FROM} AND r.item_code = ? AND r.warehouse = ?" + pin)
151
+ params = [item_code, warehouse, *pin_params]
152
+ if exclude:
153
+ sql += " AND r.name <> ?"
154
+ params.append(exclude)
155
+ if exclude_order_item:
156
+ sql += " AND (r.sales_order_item IS NULL OR r.sales_order_item <> ?)"
157
+ params.append(exclude_order_item)
158
+ return flt(get_db().sql(sql, params)[0]["qty"])
159
+
160
+
161
+ def place_stock(item_code, warehouse, batch_no="", location=""):
162
+ """What lies in a batch and / or a storage location of a warehouse."""
163
+ sql = 'SELECT COALESCE(SUM(actual_qty), 0) AS qty FROM "Stock Balance Detail" WHERE item_code = ? AND warehouse = ?'
164
+ params = [item_code, warehouse]
165
+ if batch_no:
166
+ sql += " AND batch_no = ?"
167
+ params.append(batch_no)
168
+ if location:
169
+ sql += " AND location = ?"
170
+ params.append(location)
171
+ return flt(get_db().sql(sql, params)[0]["qty"])
172
+
173
+
174
+ def _pins(item_code, warehouse):
175
+ """The (batch, location) combinations open reservations of an item in a
176
+ warehouse name, as the three kinds of place that have to stay covered."""
177
+ places = set()
178
+ for row in get_db().sql(
179
+ f"SELECT DISTINCT r.batch_no, r.location {_OPEN_FROM} AND r.item_code = ? AND r.warehouse = ? "
180
+ "AND (COALESCE(r.batch_no, '') <> '' OR COALESCE(r.location, '') <> '')", [item_code, warehouse]):
181
+ batch, location = str(row["batch_no"] or ""), str(row["location"] or "")
182
+ if batch:
183
+ places.add((batch, ""))
184
+ if location:
185
+ places.add(("", location))
186
+ if batch and location:
187
+ places.add((batch, location))
188
+ return places
189
+
190
+
191
+ def _place_label(batch_no, location):
192
+ return " ".join(part for part in (f"batch {batch_no}" if batch_no else "",
193
+ f"storage location {location}" if location else "") if part)
194
+
195
+
128
196
  def reservations_for(item_code, warehouse):
129
197
  """Open reservations of an item in a warehouse, for messages."""
130
198
  return get_db().sql(
131
- f"SELECT r.name, r.sales_order, r.customer, {_OPEN_QTY} AS open_qty {_OPEN_FROM} "
199
+ f"SELECT r.name, r.sales_order, r.customer, r.batch_no, r.location, {_OPEN_QTY} AS open_qty {_OPEN_FROM} "
132
200
  "AND r.item_code = ? AND r.warehouse = ? ORDER BY r.creation, r.name", [item_code, warehouse])
133
201
 
134
202
 
@@ -147,6 +215,9 @@ class StockReservation(Document):
147
215
  "total reserved for the line, at most its ordered qty). What is still open follows the line's delivered "
148
216
  "quantity automatically. Use the reserve_sales_order action to reserve a whole order.",
149
217
  "Without a sales order, remarks must say what the stock is set aside for.",
218
+ "Optionally name batch_no and / or location (a storage location of the warehouse): then exactly that stock "
219
+ "is held and nobody else can take it from that batch or place. One reservation holds one batch; an order "
220
+ "line that needs two batches is split into two lines.",
150
221
  "Submit/cancel are unsupported. To give stock back, update status to Released. "
151
222
  "Partially Delivered, Delivered and Cancelled are set by the system.",
152
223
  )
@@ -161,7 +232,8 @@ class StockReservation(Document):
161
232
  def validate(self):
162
233
  db = get_db()
163
234
  stored = db.get_value(self.DOCTYPE, self.name, ["status", "reserved_qty", "item_code", "warehouse",
164
- "sales_order_item"]) if self._persisted else None
235
+ "sales_order_item", "batch_no", "location"]) \
236
+ if self._persisted else None
165
237
  try:
166
238
  qty = float(self._data.get("reserved_qty"))
167
239
  except (TypeError, ValueError):
@@ -178,6 +250,7 @@ class StockReservation(Document):
178
250
  raise ValidationError("Stock Reservation: Warehouse must be a warehouse that holds stock")
179
251
  if not self._data.get("company"):
180
252
  self._data["company"] = warehouse.get("company")
253
+ batch_no, location = self._validate_place(db)
181
254
 
182
255
  requested = self._data.get("status") or RESERVED
183
256
  previous = (stored or {}).get("status")
@@ -205,10 +278,24 @@ class StockReservation(Document):
205
278
  if self._data["status"] in OPEN_STATUSES:
206
279
  mine = max(0.0, qty - delivered) if self._data.get("sales_order_item") else qty
207
280
  before = 0.0
208
- if stored and stored.get("status") in OPEN_STATUSES and stored.get("item_code") == self.item_code \
209
- and stored.get("warehouse") == self.warehouse:
281
+ same_stock = bool(stored) and stored.get("status") in OPEN_STATUSES \
282
+ and stored.get("item_code") == self.item_code and stored.get("warehouse") == self.warehouse
283
+ if same_stock:
210
284
  before = max(0.0, flt(stored.get("reserved_qty")) - delivered) \
211
285
  if stored.get("sales_order_item") else flt(stored.get("reserved_qty"))
286
+ same_place = same_stock and (str(stored.get("batch_no") or ""), str(stored.get("location") or "")) \
287
+ == (batch_no, location)
288
+ if (batch_no or location) and (mine > before + EPSILON or not same_place):
289
+ # The named batch / place must hold it, next to what others hold there.
290
+ _lock_item(self.item_code)
291
+ for batch, place in {(batch_no, ""), ("", location), (batch_no, location)} - {("", "")}:
292
+ there = place_stock(self.item_code, self.warehouse, batch, place)
293
+ others = pinned_reserved(self.item_code, self.warehouse, batch, place,
294
+ exclude=self.name if self._persisted else None)
295
+ if mine > there - others + EPSILON:
296
+ raise ValidationError(
297
+ f"Cannot reserve {mine:g} of {self.item_code} in {_place_label(batch, place)} of "
298
+ f"warehouse {self.warehouse}: {there:g} in stock there, {others:g} of it reserved for others")
212
299
  if mine > before + EPSILON:
213
300
  # Only what is new has to be available: a reservation that
214
301
  # already holds its stock can always be saved again.
@@ -228,6 +315,29 @@ class StockReservation(Document):
228
315
  principal = current_principal() or {}
229
316
  self._data["reserved_by"] = principal.get("user_id") or principal.get("name")
230
317
 
318
+ def _validate_place(self, db):
319
+ """The batch and storage location a reservation names, checked."""
320
+ batch_no = str(self._data.get("batch_no") or "").strip()
321
+ location = str(self._data.get("location") or "").strip()
322
+ self._data["batch_no"], self._data["location"] = batch_no or None, location or None
323
+ if self._data.get("status") in (RELEASED, CANCELLED, DELIVERED):
324
+ return batch_no, location
325
+ if batch_no:
326
+ batch = db.get_value("Batch", {"item_code": self.item_code, "batch_no": batch_no},
327
+ ["name", "expiry_date", "blocked"])
328
+ if not batch:
329
+ raise ValidationError(f"Stock Reservation: {self.item_code} has no batch {batch_no}")
330
+ state = batch_state(batch)
331
+ if state:
332
+ raise ValidationError(f"Stock Reservation: batch {batch_no} of {self.item_code} is {state} "
333
+ f"and cannot be reserved")
334
+ if location:
335
+ from lambda_erp.stock.stock_ledger import get_storage_location
336
+ if not get_storage_location(self.warehouse, location):
337
+ raise ValidationError(
338
+ f"Stock Reservation: warehouse {self.warehouse} has no storage location {location}")
339
+ return batch_no, location
340
+
231
341
  def _validate_order_line(self, db):
232
342
  line_name = self._data.get("sales_order_item")
233
343
  if not line_name or not self._data.get("sales_order"):
@@ -358,8 +468,15 @@ def _touched_pairs(doc):
358
468
 
359
469
 
360
470
  def _coverage(item_code, warehouse):
471
+ """How much more than the reserved quantity is there: for the warehouse
472
+ as a whole (key None) and for every batch / storage location that a
473
+ reservation names."""
361
474
  buckets = stock_buckets(item_code, warehouse)
362
- return buckets.physical_qty - buckets.blocked_qty - buckets.reserved_qty
475
+ cover = {None: buckets.physical_qty - buckets.blocked_qty - buckets.reserved_qty}
476
+ for batch_no, location in _pins(item_code, warehouse):
477
+ cover[(batch_no, location)] = (place_stock(item_code, warehouse, batch_no, location)
478
+ - pinned_reserved(item_code, warehouse, batch_no, location))
479
+ return cover
363
480
 
364
481
 
365
482
  def begin_guard(doc):
@@ -388,17 +505,24 @@ def finish_guard(doc, guard, *, cancelling=False):
388
505
  the whole document back."""
389
506
  if not guard:
390
507
  return
391
- for (item_code, warehouse), before in guard.items():
392
- after = _coverage(item_code, warehouse)
393
- if after < -EPSILON and after < before - EPSILON:
394
- holders = ", ".join(
395
- f"{row['sales_order'] or row['name']} ({flt(row['open_qty']):g})"
396
- for row in reservations_for(item_code, warehouse) if flt(row["open_qty"]) > EPSILON)
397
- action = "cancel" if cancelling else "post"
398
- raise ValidationError(
399
- f"Cannot {action} {doc.DOCTYPE} {doc.name}: it would take {item_code} in warehouse {warehouse} "
400
- f"that is reserved ({-after:g} short). Reserved for: {holders}. "
401
- f"Deliver against those orders, or release a reservation first")
508
+ for (item_code, warehouse), covered in guard.items():
509
+ now_covered = _coverage(item_code, warehouse)
510
+ for place, after in now_covered.items():
511
+ # A place nobody had named before starts from what is there now.
512
+ before = covered.get(place, 0.0)
513
+ if after < -EPSILON and after < before - EPSILON:
514
+ where = f" ({_place_label(*place)})" if place else ""
515
+ holders = ", ".join(
516
+ f"{row['sales_order'] or row['name']} ({flt(row['open_qty']):g})"
517
+ for row in reservations_for(item_code, warehouse)
518
+ if flt(row["open_qty"]) > EPSILON and (
519
+ not place or ((not place[0] or (row["batch_no"] or "") == place[0])
520
+ and (not place[1] or (row["location"] or "") == place[1]))))
521
+ action = "cancel" if cancelling else "post"
522
+ raise ValidationError(
523
+ f"Cannot {action} {doc.DOCTYPE} {doc.name}: it would take {item_code} in warehouse {warehouse}"
524
+ f"{where} that is reserved ({-after:g} short). Reserved for: {holders}. "
525
+ f"Deliver against those orders, or release a reservation first")
402
526
 
403
527
 
404
528
  # -- shelf life ---------------------------------------------------------------
@@ -529,11 +653,37 @@ def suggest_picks(item_code, warehouse, qty, *, customer=None, on_date=None, sal
529
653
  else buckets.reserved_qty
530
654
  limit = max(0.0, buckets.physical_qty - buckets.blocked_qty - others)
531
655
  remaining = min(qty, limit)
656
+ # Batches and storage locations that reservations name: what others hold
657
+ # there is not offered, and the order line's own named stock comes first.
658
+ own = db.sql('SELECT batch_no, location FROM "Stock Reservation" WHERE sales_order_item = ? '
659
+ "AND status IN ('Reserved', 'Partially Delivered') AND COALESCE(discarded, 0) = 0",
660
+ [sales_order_item]) if sales_order_item else []
661
+ own_batch, own_location = (str(own[0]["batch_no"] or ""), str(own[0]["location"] or "")) if own else ("", "")
662
+ if own_batch or own_location:
663
+ candidates.sort(key=lambda c: not ((not own_batch or (c["batch_no"] or "") == own_batch)
664
+ and (not own_location or (c["location"] or "") == own_location)))
665
+ free = {}
666
+
667
+ def room(batch_no, location):
668
+ """What others leave free in a batch / storage location, shrinking as picks are taken."""
669
+ key = (batch_no, location)
670
+ if key not in free:
671
+ free[key] = (place_stock(item_code, warehouse, batch_no, location)
672
+ - pinned_reserved(item_code, warehouse, batch_no, location,
673
+ exclude_order_item=sales_order_item))
674
+ return free[key]
675
+
532
676
  picks = []
533
677
  for candidate in candidates:
534
678
  if remaining <= EPSILON:
535
679
  break
536
- take = min(remaining, candidate["available_qty"])
680
+ batch, place = candidate["batch_no"] or "", candidate["location"] or ""
681
+ places = [key for key in ((batch, ""), ("", place), (batch, place)) if key != ("", "")]
682
+ take = min([remaining, candidate["available_qty"], *(max(0.0, room(*key)) for key in places)])
683
+ if take <= EPSILON:
684
+ continue
685
+ for key in set(places):
686
+ free[key] -= take
537
687
  pick = {"batch_no": candidate["batch_no"], "location": candidate["location"],
538
688
  "expiry_date": candidate["expiry_date"], "days_left": candidate["days_left"],
539
689
  "qty": take, "needs_exception": candidate["needs_exception"]}