refactor: 'make_advance_gl_entries' method
make_advance_gl_entries -> add_advance_gl_entries -> add_advance_gl_for_reference 'make_advance_gl_entries' - main method thats builds and post GL entries for all or one specific reference based on parameters 'add_advance_gl_entries' - build GL map for all or one specific reference. Return an array of dict. 'add_advance_gl_for_reference' - utility function to build gl entries. returns dict. (cherry picked from commit 5fc19dab54a2672ec131dbf97974b2bde277aa76)
This commit is contained in:
parent
58d04e1f42
commit
a1bdd69ffd
@ -1126,53 +1126,31 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
gl_entries.append(gle)
|
gl_entries.append(gle)
|
||||||
|
|
||||||
def make_advance_gl_entries(self, against_voucher_type=None, against_voucher=None, cancel=0):
|
def make_advance_gl_entries(
|
||||||
|
self, entry: object | dict = None, cancel: bool = 0, update_outstanding: str = "Yes"
|
||||||
|
):
|
||||||
|
gl_entries = []
|
||||||
|
self.add_advance_gl_entries(gl_entries, entry)
|
||||||
|
|
||||||
|
if cancel:
|
||||||
|
make_reverse_gl_entries(gl_entries, partial_cancel=True)
|
||||||
|
else:
|
||||||
|
make_gl_entries(gl_entries, update_outstanding=update_outstanding)
|
||||||
|
|
||||||
|
def add_advance_gl_entries(self, gl_entries: list, entry: object | dict | None):
|
||||||
|
"""
|
||||||
|
If 'entry' is passed, GL enties only for that reference is added.
|
||||||
|
"""
|
||||||
if self.book_advance_payments_in_separate_party_account:
|
if self.book_advance_payments_in_separate_party_account:
|
||||||
gl_entries = []
|
references = [x for x in self.get("references")]
|
||||||
for d in self.get("references"):
|
if entry:
|
||||||
if d.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Journal Entry"):
|
references = [x for x in self.get("references") if x.name == entry.name]
|
||||||
if not (against_voucher_type and against_voucher) or (
|
|
||||||
d.reference_doctype == against_voucher_type and d.reference_name == against_voucher
|
|
||||||
):
|
|
||||||
self.make_invoice_liability_entry(gl_entries, d)
|
|
||||||
|
|
||||||
if cancel:
|
for ref in references:
|
||||||
for entry in gl_entries:
|
if ref.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Journal Entry"):
|
||||||
frappe.db.set_value(
|
self.add_advance_gl_for_reference(gl_entries, ref)
|
||||||
"GL Entry",
|
|
||||||
{
|
|
||||||
"voucher_no": self.name,
|
|
||||||
"voucher_type": self.doctype,
|
|
||||||
"voucher_detail_no": entry.voucher_detail_no,
|
|
||||||
"against_voucher_type": entry.against_voucher_type,
|
|
||||||
"against_voucher": entry.against_voucher,
|
|
||||||
},
|
|
||||||
"is_cancelled",
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
|
|
||||||
make_reverse_gl_entries(gl_entries=gl_entries, partial_cancel=True)
|
def add_advance_gl_for_reference(self, gl_entries, invoice):
|
||||||
return
|
|
||||||
|
|
||||||
# same reference added to payment entry
|
|
||||||
for gl_entry in gl_entries.copy():
|
|
||||||
if frappe.db.exists(
|
|
||||||
"GL Entry",
|
|
||||||
{
|
|
||||||
"account": gl_entry.account,
|
|
||||||
"voucher_type": gl_entry.voucher_type,
|
|
||||||
"voucher_no": gl_entry.voucher_no,
|
|
||||||
"voucher_detail_no": gl_entry.voucher_detail_no,
|
|
||||||
"debit": gl_entry.debit,
|
|
||||||
"credit": gl_entry.credit,
|
|
||||||
"is_cancelled": 0,
|
|
||||||
},
|
|
||||||
):
|
|
||||||
gl_entries.remove(gl_entry)
|
|
||||||
|
|
||||||
make_gl_entries(gl_entries)
|
|
||||||
|
|
||||||
def make_invoice_liability_entry(self, gl_entries, invoice):
|
|
||||||
args_dict = {
|
args_dict = {
|
||||||
"party_type": self.party_type,
|
"party_type": self.party_type,
|
||||||
"party": self.party,
|
"party": self.party,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user