Commit Graph

58768 Commits

Author SHA1 Message Date
Mihir Kandoi
0f2284ec4f Merge pull request #57913 from frappe/mergify/bp/version-16-hotfix/pr-57911
fix: tolerate floating-point drift in sales team allocated percentage  (backport #57911)
2026-08-09 12:59:34 +05:30
Mihir Kandoi
c507d5f09b chore: resolve conflict 2026-08-09 12:49:07 +05:30
pandiyan
ee9026d62d test: sales team allocation totalling 100 in floating point
covers the case where the percentages are correct but the accumulated
sum is 100.00000000000001. two rows can never drift, since the second
reconstructs exactly as 100 - first, so the case needs three rows.

(cherry picked from commit 4afba94d1c)

# Conflicts:
#	erpnext/selling/doctype/sales_order/test_sales_order.py
2026-08-09 06:59:47 +00:00
pandiyan
39f15bb3e9 fix: tolerate floating-point drift in sales team allocated percentage
the total of allocated_percentage was compared to 100 with exact float
equality, so a correct allocation could be rejected when the sum drifts
in binary floating point (10.0 + 58.02 + 31.98 -> 100.00000000000001).

round the total to the field precision before comparing, in both
SellingController.calculate_contribution and Customer.validate.

(cherry picked from commit f7b2775829)
2026-08-09 06:59:47 +00:00
Mihir Kandoi
a97beb6d9b Merge pull request #57908 from frappe/mergify/bp/version-16-hotfix/pr-57832
fix: validate webform for project (backport #57832)
2026-08-09 09:53:23 +05:30
Mihir Kandoi
a7648ad291 Merge pull request #57905 from frappe/mergify/bp/version-16-hotfix/pr-57903
fix: condition check with empty object for falsy case (backport #57903)
2026-08-09 09:44:42 +05:30
nishkagosalia
8d98fe8187 fix: validate webform for project
(cherry picked from commit 126966d1db)
2026-08-09 04:12:32 +00:00
Suhas Bharadwaj
838fb8e8df fix: condition check with empty object for falsy case
(cherry picked from commit e0b9351d49)
2026-08-08 18:49:06 +00:00
mergify[bot]
6b45002abc fix: set restrict_globals=True in frappe.render_template (backport #57899) (#57902)
Co-authored-by: Diptanil Saha <diptanil@frappe.io>
2026-08-09 00:04:36 +05:30
rohitwaghchaure
ea5cbb116c feat: sync serial no status from stock ledger in Stock Qty vs Serial No Count report (version-16-hotfix) (#57864)
* feat: sync serial no status from stock ledger in Stock Qty vs Serial No Count report

* fix: pick last bundle move in SQL ordered by posting datetime and SLE creation

* fix: derive synced serial no status from stock ledger helper and validate sync args
2026-08-08 13:47:53 +00:00
Diptanil Saha
f0adbd2bd3 fix(journal_entry): validation message for blocked purchase invoice (#57896) 2026-08-08 13:36:05 +00:00
Mihir Kandoi
d3e0b1041b Merge pull request #57890 from mihir-kandoi/backport-57887-v16
fix: repost read stale sibling SLE rate for moving average returns (backport #57887)
2026-08-08 12:02:40 +05:30
Mihir Kandoi
43e1e70199 Merge pull request #57889 from frappe/mergify/bp/version-16-hotfix/pr-57886
fix: incorrect entry detection in Stock Ledger Invariant Check (backport #57886)
2026-08-08 11:14:13 +05:30
Mihir Kandoi
81f81fff32 fix: zero-rate repost fallback could still read sibling SLE
When the in-memory running rate is zero, the fallback went through
get_incoming_rate, whose previous-SLE lookup matches the same
posting_datetime and can land on a sibling line of the voucher being
replayed. Replace it with get_previous_sle_of_current_voucher excluding
the current voucher, keeping the get_valuation_rate chain when no
previous entry exists. get_incoming_rate is no longer used in this
module.
2026-08-08 11:12:02 +05:30
Mihir Kandoi
4571a8fa14 test: repost of multi-line moving average return is idempotent
Reposting a return that removes most of the stock across several lines
of the same item must keep every line at the running average and produce
identical results on a second repost. Before the fix the first repost
already drifted, seeding each line from a sibling row of the same
voucher.
2026-08-08 11:12:02 +05:30
Mihir Kandoi
ffa65b0c48 fix: repost read stale sibling SLE rate for moving average returns
During repost, a return line with recalculate_rate resolved its moving
average rate through get_incoming_rate -> get_previous_sle, which matches
posting_datetime <= and orders by creation desc. For a multi-line return
of the same item, every line shares one posting_datetime, so the query
landed on a sibling line of the same voucher whose stored valuation_rate
was still the previous repost run's output, not the rate before the
voucher.

Each repost run therefore re-seeded the voucher from its own prior
output. The error gain per run is (qty returned at the stale rate) /
(qty remaining after the return), so whenever a return removes most of
the stock the loop diverges instead of converging, alternating sign and
growing until stock_value overflows decimal(21,9) and the repost dies
with 'Out of range value for column stock_value'.

Use the in-memory running valuation rate that update_entries_after
already tracks for the warehouse at this point in the repost. It is the
authoritative pre-entry state, is immune to sibling rows, and makes the
repost idempotent. The database lookup is kept only as a fallback for a
zero in-memory rate, preserving the existing zero-rate fallback chain.
2026-08-08 11:12:02 +05:30
Mihir Kandoi
f7bae888cf fix: incorrect entry detection in Stock Ledger Invariant Check (#57886)
(cherry picked from commit b3f97cd389)
2026-08-08 05:32:11 +00:00
Mihir Kandoi
be0c505972 Merge pull request #57884 from frappe/mergify/bp/version-16-hotfix/pr-57873
fix: declare precision 9 on all conversion_factor fields (backport #57873)
2026-08-07 23:00:15 +05:30
Mihir Kandoi
dbfe7e199e fix: add type hints to conversion factor API 2026-08-07 22:47:17 +05:30
Mihir Kandoi
2cd8e39f04 chore: resolve conflict 2026-08-07 22:28:30 +05:30
Mihir Kandoi
206ed28924 fix: round computed conversion factors to field precision
The inverse (1 / value) and intermediate-UOM branches of
get_uom_conv_factor returned raw float quotients like
0.4535922921968971, bypassing the precision the docfields now declare.
Same for the client-side back-calculation from an edited stock qty.
Round both to the UOM Conversion Factor value precision.

(cherry picked from commit ca5a673409)
2026-08-07 16:51:40 +00:00
Mihir Kandoi
db49b03913 fix: declare precision 9 on all conversion_factor fields
The Float control parses values with the field precision, falling back
to the global float precision when the docfield declares none
(frappe ControlFloat.parse / get_precision). On a site with float
precision 2, a fetched UOM factor of 0.453592292 was written back to
the model as 0.45, silently corrupting every derived quantity by 0.8
percent. A ratio must not inherit display precision meant for
quantities, so declare the same precision 9 the UOM Conversion Factor
master already uses on every transaction-level conversion_factor
field.

(cherry picked from commit 69a35a12cb)

# Conflicts:
#	erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.json
#	erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
#	erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
#	erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json
#	erpnext/manufacturing/doctype/bom_secondary_item/bom_secondary_item.json
#	erpnext/selling/doctype/quotation_item/quotation_item.json
#	erpnext/selling/doctype/sales_order_item/sales_order_item.json
#	erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
#	erpnext/stock/doctype/packed_item/packed_item.json
#	erpnext/stock/doctype/pick_list_item/pick_list_item.json
#	erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
#	erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
#	erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json
#	erpnext/subcontracting/doctype/subcontracting_receipt_supplied_item/subcontracting_receipt_supplied_item.json
2026-08-07 16:51:40 +00:00
Shllokkk
83a0a1c687 Merge pull request #57882 from frappe/mergify/bp/version-16-hotfix/pr-57880
fix: guard reconciliation table deletes when tables are missing (backport #57880)
2026-08-07 20:50:10 +05:30
Shllokkk
21fbfa541d fix: guard reconciliation table deletes when tables are missing
(cherry picked from commit 8a2b2a2b68)
2026-08-07 14:35:21 +00:00
Mihir Kandoi
08af36d86e Merge pull request #57870 from frappe/mergify/bp/version-16-hotfix/pr-57866
fix: optimize product bundle item search (backport #57866)
2026-08-07 16:11:03 +05:30
Mihir Kandoi
693cade177 chore: resolve conflict 2026-08-07 16:07:36 +05:30
Krishna Shirsath
29349711e4 fix: optimize product bundle item search
(cherry picked from commit b3867f1428)

# Conflicts:
#	erpnext/selling/doctype/product_bundle/product_bundle.js
2026-08-07 10:33:43 +00:00
Diptanil Saha
eb7dfa1337 Merge pull request #57846 from diptanilsaha/backport/57825
refactor(accounts)!: rework Purchase Invoice hold actions and enforce them on Journal Entry (backport #57825)
2026-08-07 15:06:59 +05:30
Mihir Kandoi
e1473140cc Merge pull request #57852 from frappe/mergify/bp/version-16-hotfix/pr-57851
fix: round Production Plan mr_items quantity to field precision (backport #57851)
2026-08-07 03:24:10 +05:30
Mihir Kandoi
460fe9af3e chore: resolve conflict 2026-08-06 21:32:24 +05:30
Mihir Kandoi
9f8aa3cf1b test: remaining purchase qty is rounded to field precision
Covers the _add_remaining_purchase_request path: partial stock in
another warehouse is allocated as a transfer and the residual purchase
qty goes through the second rounding site.

(cherry picked from commit 75145cc72c)
2026-08-06 15:41:41 +00:00
Mihir Kandoi
9f9cb5c3b6 test: mr_items quantity is rounded to field precision
(cherry picked from commit f5157bf3c4)
2026-08-06 15:41:41 +00:00
Mihir Kandoi
2d056aee3d fix: round production plan mr_items quantity to field precision
The stock-UOM qty is rounded in _accumulate_so_items, but the purchase
UOM conversion divided it by the conversion factor without re-rounding,
storing values like 5738748.300863984 in mr_items.quantity. The raw
value flowed into Material Request qty and the raw materials CSV, and
make_material_request compares quantity to requested_qty with exact
float equality, so any rounding downstream left dust quantities.

(cherry picked from commit ffc515f046)
2026-08-06 15:41:40 +00:00
Mihir Kandoi
e1c1c5ed7e refactor: remove unreachable UOM conversion in production plan
The division by conversion_factor in _adjust_required_qty_for_uom sits
directly after frappe.throw inside the same block, so it can never run.
It has been dead since commit 2a8cd05b44 (#27278) re-indented it into
the throw branch; the actual purchase-UOM conversion happens in
_material_request_item_row via _mr_purchase_conversion_factor.

(cherry picked from commit 44260b469f)

# Conflicts:
#	erpnext/manufacturing/doctype/production_plan/services/material_request.py
2026-08-06 15:41:40 +00:00
diptanilsaha
0bb0f6d689 test(journal_entry): added test cases for blocked purchase invoices 2026-08-06 17:07:26 +05:30
diptanilsaha
04718e15c9 fix(journal_entry): validate blocked purchase invoices 2026-08-06 16:50:33 +05:30
diptanilsaha
c8125b8b5a refactor(purchase_invoice): expose invoice hold actions as document methods 2026-08-06 16:23:44 +05:30
rohitwaghchaure
aa70d9bbc3 fix: purchase return of batchwise valuation batch valued at original receipt rate instead of batch avg rate (version-16-hotfix) (#57836)
* fix: use current batch avg rate for outward returns of batchwise valuation batches

* fix: honor zero batch average and avoid duplicate batch classification query
2026-08-06 15:44:56 +05:30
Mihir Kandoi
626e35135f fix(stock): drop call to confirm_if_drafts_exist missing on v16 (#57833) 2026-08-06 08:08:45 +00:00
Henil Maru
0e26f9b1db fix(sales-invoice): respect Customize Form hidden setting on Update Stock (#57819)
frm.toggle_display("update_stock", ...) unconditionally forced the
field visible based only on has_subcontracted, overwriting whatever
Customize Form had set on every refresh. OR it with the field's
original (property-setter-driven) hidden value instead.

Backport of #57818.
2026-08-05 17:58:58 +05:30
rohitwaghchaure
243266f5ef feat: stock validations in Period Closing Voucher and snapshot-seeded batch valuation (backport #57811) (#57816)
* feat: validate stock value and stock closing entry before period closing

(cherry picked from commit 20450bd4ec)

* fix: do not accept scoped stock closing entries as period closing prerequisite

(cherry picked from commit 359a347be2)

* feat: seed batch valuation from stock closing balance and freeze closed-period stock

(cherry picked from commit 49a127d59c)
2026-08-05 17:20:53 +05:30
mergify[bot]
af3184c8b4 fix(stock): handle multi-item opening balance in Stock Ledger report (backport #57591) (#57796)
* fix(stock): handle multi-item opening balance in Stock Ledger report (#57591)

* fix(stock): handle multi-item opening balance in Stock

* test(stock): add unit test for multi-item Stock Ledger report

---------

Co-authored-by: Afsal Syed <afsalsyed12@gmail.com>
(cherry picked from commit 0dbe410414)

# Conflicts:
#	erpnext/stock/report/stock_ledger/test_stock_ledger_report.py

* fix(stock): resolve stock ledger backport conflicts

---------

Co-authored-by: Sudharsanan Ashok <135326972+Sudharsanan11@users.noreply.github.com>
Co-authored-by: Sudharsanan11 <sudharsananashok1975@gmail.com>
2026-08-05 13:15:40 +05:30
Jatin3128
eeb3cd238e fix(subscription): don't reactivate a cancelled subscription (backport #57774)
* fix(subscription): don't reactivate a cancelled subscription

Backport of #57774 to version-16-hotfix.

set_subscription_status() unconditionally set status to Active once
there was no outstanding invoice, even if the subscription had been
intentionally cancelled. Paying off an invoice issued before
cancellation (directly, or via the Payment Entry -> refresh hook)
flipped a Cancelled subscription back to Active while cancelation_date
stayed set.

process()'s cancel_at_period_end check compared posting_date against
getdate(self.end_date), and getdate(None) returns today, so an empty
end_date was silently treated as "cancel now" on every scheduler run.
Combined with the reactivation bug, this let a cancelled subscription
toggle Cancelled -> Active on each run and generate another invoice at
the next period boundary.

Fixes #57761

* test: fix flaky test_update_bom_cost_in_all_boms via valuation reset

Backport of #56796 to version-16-hotfix.

reset_item_valuation_rate() only reconciled warehouses where the item
currently has positive stock (actual_qty > 0). get_valuation_rate()
averages Sum(stock_value)/Sum(actual_qty) across all of an item's
bins, so a negative balance left over in another warehouse by a prior
test can cancel out the reset qty and collapse the average to 0,
failing the assertion with 0.0 != 10.0.

This branch never got #56796 (it predates the frappe.get_all
refactor of this helper and still uses raw SQL), so applying the same
fix here: reconcile every warehouse with a non-zero balance, not just
positive ones.

* fix(subscription): don't let period rollover defeat cancel_at_period_end

process() can advance current_invoice_end to the next period (via
update_subscription_period(), when generating the current period's
invoice) before the cancel_at_period_end check further down runs. For
a subscription with no end_date, that check now compared posting_date
against the already-rolled-forward current_invoice_end, which is
always in the future, so cancel_at_period_end was silently never
honored.

Snapshot current_invoice_end before any rollover and use that in the
check instead, so it still targets the period that just ended.

Found via review on the version-15-hotfix backport (#57780).

---------

Co-authored-by: test <test@test.com>
2026-08-05 12:23:31 +05:30
mergify[bot]
adfa6768c9 fix: incorrect batch-wise valuation rate for entries with same posting datetime (backport #57794) (#57797)
fix: incorrect batch-wise valuation rate for entries with same posting datetime (#57794)

* fix: incorrect batch-wise valuation rate for entries with same posting datetime

The tie-breaker in get_batch_no_ledgers compared the bundle's creation
against the SLE's creation. These are different timelines - a bundle can
be created (drafted) much before its SLE (created at submission). For
entries sharing a posting datetime (backdated / amended vouchers), this
mis-ordered the entries against the ledger's replay order (SLE creation),
causing double counting or omission of batch qty / value and runaway
outgoing rates that no repost could heal.

Now the tie is broken using the creation of the bundle's own SLE (same
timeline on both sides). When the valuation runs through the bundle
before its SLE exists, the entry is by definition last in its timestamp
group, so all same-timestamp entries already in the ledger precede it.



* test: batch-wise valuation ordering for same posting datetime entries

Covers both tie-breaking branches of get_batch_no_ledgers:
- submission (pre-insertion) branch: same-timestamp inward at a different
  rate plus a multi-row outward voucher (same item and warehouse), at
  submission and after a backdated repost
- existing-SLE branch: a bundle created after its sibling's SLE, the
  ordering must follow the SLE creation and not the bundle creation

Both tests fail with the previous parent.creation < sle.creation
tie-breaker and pass with the fix.



---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-05 11:06:14 +05:30
Diptanil Saha
970a3f403d Merge pull request #57798 from diptanilsaha/backport/16/57734
fix(payment reconciliation): correct supplier gain/loss posting (backport #57734)
2026-08-05 00:13:14 +05:30
Sudharsanan11
61154e22ed test(payment reconciliation): cover supplier exchange gain posting 2026-08-04 23:58:33 +05:30
diptanilsaha
dc907add40 fix(payment reconciliation): correct supplier gain/loss posting 2026-08-04 23:58:19 +05:30
Shllokkk
b5700831d8 Merge pull request #57791 from frappe/mergify/bp/version-16-hotfix/pr-57790
test: child warehouse account override in stock vs account value comparison (backport #57790)
2026-08-04 20:15:59 +05:30
Shllokkk
a703e7a462 test: child warehouse account override excluded in stock vs account value comparison
(cherry picked from commit ef7a3cb4c8)

# Conflicts:
#	erpnext/stock/report/stock_and_account_value_comparison/test_stock_and_account_value_comparison.py
2026-08-04 18:54:44 +05:30
Mihir Kandoi
abc76eb49d Merge pull request #57789 from frappe/mergify/bp/version-16-hotfix/pr-57757
fix(opportunity): add validation for positive item quantities (backport #57757)
2026-08-04 17:13:29 +05:30