refactor: single fetch and unlinking logic for JE and PE
This commit is contained in:
parent
285963acdb
commit
de910ab152
@ -6,6 +6,9 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
|
"account",
|
||||||
|
"party_type",
|
||||||
|
"party",
|
||||||
"reference_doctype",
|
"reference_doctype",
|
||||||
"reference_name",
|
"reference_name",
|
||||||
"allocated_amount",
|
"allocated_amount",
|
||||||
@ -39,12 +42,27 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Reference Type",
|
"label": "Reference Type",
|
||||||
"options": "DocType"
|
"options": "DocType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "account",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Account"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party_type",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Party Type"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "party",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Party"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-08-24 14:48:10.018574",
|
"modified": "2023-08-30 10:58:45.322668",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Unreconcile Payment Entries",
|
"name": "Unreconcile Payment Entries",
|
||||||
|
|||||||
@ -20,38 +20,26 @@ class UnreconcilePayments(Document):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_allocations_from_payment(self):
|
def get_allocations_from_payment(self):
|
||||||
allocated_references = []
|
allocated_references = []
|
||||||
if self.voucher_type == "Payment Entry":
|
ple = qb.DocType("Payment Ledger Entry")
|
||||||
per = qb.DocType("Payment Entry Reference")
|
allocated_references = (
|
||||||
allocated_references = (
|
qb.from_(ple)
|
||||||
qb.from_(per)
|
.select(
|
||||||
.select(
|
ple.account,
|
||||||
per.reference_doctype, per.reference_name, Sum(per.allocated_amount).as_("allocated_amount")
|
ple.party_type,
|
||||||
)
|
ple.party,
|
||||||
.where((per.docstatus == 1) & (per.parent == self.voucher_no))
|
ple.against_voucher_type.as_("reference_doctype"),
|
||||||
.groupby(per.reference_name)
|
ple.against_voucher_no.as_("reference_name"),
|
||||||
.run(as_dict=True)
|
Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"),
|
||||||
)
|
)
|
||||||
elif self.voucher_type == "Journal Entry":
|
.where(
|
||||||
# for journals, using payment ledger to fetch allocation.
|
(ple.docstatus == 1)
|
||||||
# this way we can avoid vaildating account type and reference details individually on child table
|
& (ple.voucher_type == self.voucher_type)
|
||||||
|
& (ple.voucher_no == self.voucher_no)
|
||||||
ple = qb.DocType("Payment Ledger Entry")
|
& (ple.voucher_no != ple.against_voucher_no)
|
||||||
allocated_references = (
|
|
||||||
qb.from_(ple)
|
|
||||||
.select(
|
|
||||||
ple.against_voucher_type.as_("reference_doctype"),
|
|
||||||
ple.against_voucher_no.as_("reference_name"),
|
|
||||||
Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"),
|
|
||||||
)
|
|
||||||
.where(
|
|
||||||
(ple.docstatus == 1)
|
|
||||||
& (ple.voucher_type == self.voucher_type)
|
|
||||||
& (ple.voucher_no == self.voucher_no)
|
|
||||||
& (ple.voucher_no != ple.against_voucher_no)
|
|
||||||
)
|
|
||||||
.groupby(ple.against_voucher_type, ple.against_voucher_no)
|
|
||||||
.run(as_dict=True)
|
|
||||||
)
|
)
|
||||||
|
.groupby(ple.against_voucher_type, ple.against_voucher_no)
|
||||||
|
.run(as_dict=True)
|
||||||
|
)
|
||||||
|
|
||||||
return allocated_references
|
return allocated_references
|
||||||
|
|
||||||
@ -65,19 +53,11 @@ class UnreconcilePayments(Document):
|
|||||||
# todo: add more granular unlinking
|
# todo: add more granular unlinking
|
||||||
# different amounts for same invoice should be individually unlinkable
|
# different amounts for same invoice should be individually unlinkable
|
||||||
|
|
||||||
payment_type, paid_from, paid_to, party_type, party = frappe.db.get_all(
|
|
||||||
self.voucher_type,
|
|
||||||
filters={"name": self.voucher_no},
|
|
||||||
fields=["payment_type", "paid_from", "paid_to", "party_type", "party"],
|
|
||||||
as_list=1,
|
|
||||||
)[0]
|
|
||||||
account = paid_from if payment_type == "Receive" else paid_to
|
|
||||||
|
|
||||||
for alloc in self.allocations:
|
for alloc in self.allocations:
|
||||||
doc = frappe.get_doc(alloc.reference_doctype, alloc.reference_name)
|
doc = frappe.get_doc(alloc.reference_doctype, alloc.reference_name)
|
||||||
unlink_ref_doc_from_payment_entries(doc)
|
unlink_ref_doc_from_payment_entries(doc)
|
||||||
update_voucher_outstanding(
|
update_voucher_outstanding(
|
||||||
alloc.reference_doctype, alloc.reference_name, account, party_type, party
|
alloc.reference_doctype, alloc.reference_name, alloc.account, alloc.party_type, alloc.party
|
||||||
)
|
)
|
||||||
frappe.db.set_value("Unreconcile Payment Entries", alloc.name, "unlinked", True)
|
frappe.db.set_value("Unreconcile Payment Entries", alloc.name, "unlinked", True)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user