mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-16 18:24:10 +00:00
refactor(stock): convert DN billed-amount SUM to get_all
update_billed_amount_based_on_so: raw "select sum(amount) ... where
dn_detail=%s and docstatus=1" -> frappe.get_all(fields=[{SUM: amount}]); the
bare aggregate needs no GROUP BY and the NULL-sum still resolves to 0. Same
result on MariaDB; valid under Postgres. Covered by the existing billing tests
in test_delivery_note.py.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -104,12 +104,12 @@ def update_billed_amount_based_on_so(so_detail: str, update_modified: bool = Tru
|
|||||||
billed_against_so -= billed_amt_against_dn
|
billed_against_so -= billed_amt_against_dn
|
||||||
else:
|
else:
|
||||||
# Get billed amount directly against Delivery Note
|
# Get billed amount directly against Delivery Note
|
||||||
billed_amt_against_dn = frappe.db.sql(
|
billed_amt_against_dn = frappe.get_all(
|
||||||
"""select sum(amount) from `tabSales Invoice Item`
|
"Sales Invoice Item",
|
||||||
where dn_detail=%s and docstatus=1""",
|
filters={"dn_detail": dnd.name, "docstatus": 1},
|
||||||
dnd.name,
|
fields=[{"SUM": "amount", "as": "amount"}],
|
||||||
)
|
)
|
||||||
billed_amt_against_dn = billed_amt_against_dn and billed_amt_against_dn[0][0] or 0
|
billed_amt_against_dn = billed_amt_against_dn[0].amount or 0 if billed_amt_against_dn else 0
|
||||||
|
|
||||||
# Distribute billed amount directly against SO between DNs based on FIFO
|
# Distribute billed amount directly against SO between DNs based on FIFO
|
||||||
if billed_against_so and billed_amt_against_dn < dnd.amount:
|
if billed_against_so and billed_amt_against_dn < dnd.amount:
|
||||||
|
|||||||
Reference in New Issue
Block a user