forked from frappe/erpnext
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1356 from Bloomstack/bs-may-sprint-2
Merge branch bs-may-sprint-2 into pre-release
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import frappe | ||
|
||
def execute(): | ||
payment_references = frappe.get_all("Payment Entry Reference", filters={"docstatus": 1}, fields=["*"]) | ||
reference_documents = {} | ||
|
||
for payment_reference in payment_references: | ||
if payment_reference.reference_name in reference_documents: | ||
reference_documents[payment_reference.reference_name] += [payment_reference] | ||
else: | ||
reference_documents[payment_reference.reference_name] = [payment_reference] | ||
|
||
for key in reference_documents: | ||
if len(reference_documents[key]) > 1: | ||
reference_documents[key].sort(key=sort) | ||
|
||
set_outstanding(reference_documents[key]) | ||
|
||
def sort(e): | ||
return e["modified"] | ||
|
||
def set_outstanding(documents): | ||
total_amount = documents[0].total_amount | ||
|
||
for document in documents: | ||
total_amount -= document.allocated_amount | ||
frappe.db.set_value("Payment Entry Reference", document.name, "outstanding_amount", total_amount, update_modified=False) |