test: Update tests
This commit is contained in:
parent
175a7baa60
commit
016ed951da
@ -97,29 +97,37 @@ class PaymentEntry(AccountsController):
|
||||
book_advance_payments_as_liability = frappe.get_value(
|
||||
"Company", {"company_name": self.company}, "book_advance_payments_as_liability"
|
||||
)
|
||||
|
||||
if not book_advance_payments_as_liability:
|
||||
return
|
||||
|
||||
account_type = frappe.get_value(
|
||||
"Account", {"name": self.party_account, "company": self.company}, "account_type"
|
||||
)
|
||||
|
||||
if (account_type == "Payable" and self.party_type == "Customer") or (
|
||||
account_type == "Receivable" and self.party_type == "Supplier"
|
||||
):
|
||||
return
|
||||
|
||||
if self.unallocated_amount == 0:
|
||||
for d in self.references:
|
||||
if d.reference_doctype in ["Sales Order", "Purchase Order"]:
|
||||
break
|
||||
else:
|
||||
return
|
||||
|
||||
liability_account = get_party_account(
|
||||
self.party_type, self.party, self.company, include_advance=True
|
||||
)[1]
|
||||
|
||||
self.set(self.party_account_field, liability_account)
|
||||
|
||||
msg = "Book Advance Payments as Liability option is chosen. Paid From account changed from {0} to {1}.".format(
|
||||
frappe.bold(self.party_account),
|
||||
frappe.bold(liability_account),
|
||||
)
|
||||
|
||||
frappe.msgprint(_(msg), alert=True)
|
||||
|
||||
def on_cancel(self):
|
||||
@ -921,12 +929,12 @@ class PaymentEntry(AccountsController):
|
||||
|
||||
self.set("remarks", "\n".join(remarks))
|
||||
|
||||
def build_gl_map(self, is_reconcile=True):
|
||||
def build_gl_map(self):
|
||||
if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"):
|
||||
self.setup_party_account_field()
|
||||
|
||||
gl_entries = []
|
||||
self.add_party_gl_entries(gl_entries, is_reconcile)
|
||||
self.add_party_gl_entries(gl_entries)
|
||||
self.add_bank_gl_entries(gl_entries)
|
||||
self.add_deductions_gl_entries(gl_entries)
|
||||
self.add_tax_gl_entries(gl_entries)
|
||||
@ -937,7 +945,7 @@ class PaymentEntry(AccountsController):
|
||||
gl_entries = process_gl_map(gl_entries)
|
||||
make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
|
||||
|
||||
def add_party_gl_entries(self, gl_entries, is_reconcile):
|
||||
def add_party_gl_entries(self, gl_entries):
|
||||
if self.party_account:
|
||||
if self.payment_type == "Receive":
|
||||
against_account = self.paid_to
|
||||
@ -957,7 +965,7 @@ class PaymentEntry(AccountsController):
|
||||
},
|
||||
item=self,
|
||||
)
|
||||
is_advance = self.get_advance_flag()
|
||||
is_advance = self.is_advance_entry()
|
||||
|
||||
for d in self.get("references"):
|
||||
gle = party_dict.copy()
|
||||
@ -967,30 +975,24 @@ class PaymentEntry(AccountsController):
|
||||
if (
|
||||
d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]
|
||||
and book_advance_payments_as_liability
|
||||
and (is_advance or is_reconcile)
|
||||
and is_advance
|
||||
):
|
||||
self.make_invoice_liability_entry(gl_entries, d)
|
||||
gle.update(
|
||||
{
|
||||
"against_voucher_type": "Payment Entry",
|
||||
"against_voucher": self.name,
|
||||
}
|
||||
)
|
||||
against_voucher_type = "Payment Entry"
|
||||
against_voucher = self.name
|
||||
else:
|
||||
against_voucher_type = d.reference_doctype
|
||||
against_voucher = d.reference_name
|
||||
|
||||
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
|
||||
gle.update(
|
||||
{
|
||||
dr_or_cr: allocated_amount_in_company_currency,
|
||||
dr_or_cr + "_in_account_currency": d.allocated_amount,
|
||||
"against_voucher_type": against_voucher_type,
|
||||
"against_voucher": against_voucher,
|
||||
}
|
||||
)
|
||||
if not gle.get("against_voucher_type"):
|
||||
gle.update(
|
||||
{
|
||||
"against_voucher_type": d.reference_doctype if is_advance else "Payment Entry",
|
||||
"against_voucher": d.reference_name if is_advance else self.name,
|
||||
}
|
||||
)
|
||||
gl_entries.append(gle)
|
||||
|
||||
if self.unallocated_amount:
|
||||
@ -1009,9 +1011,9 @@ class PaymentEntry(AccountsController):
|
||||
|
||||
gl_entries.append(gle)
|
||||
|
||||
def get_advance_flag(self):
|
||||
def is_advance_entry(self):
|
||||
for d in self.get("references"):
|
||||
if d.reference_doctype == "Sales Order":
|
||||
if d.reference_doctype in ("Sales Order", "Purchase Order"):
|
||||
return True
|
||||
if self.unallocated_amount > 0:
|
||||
return True
|
||||
|
@ -1698,12 +1698,16 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
||||
pi.submit()
|
||||
|
||||
self.assertEqual(pi.advances[0].allocated_amount, 500)
|
||||
|
||||
# Check GL Entry against payment doctype
|
||||
expected_gle = [
|
||||
["Creditors - _TC", 500, 1000, nowdate()],
|
||||
["Cash - _TC", 0.0, 500, nowdate()],
|
||||
["Creditors - _TC", 500, 0.0, nowdate()],
|
||||
["Creditors - _TC", 500, 0.0, nowdate()],
|
||||
["Debtors - _TC", 0.0, 500, nowdate()],
|
||||
["Stock Received But Not Billed - _TC", 1000, 0.0, nowdate()],
|
||||
]
|
||||
check_gl_entries(self, pi.name, expected_gle, nowdate())
|
||||
|
||||
check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry")
|
||||
self.assertEqual(pi.outstanding_amount, 500)
|
||||
|
||||
set_advance_flag(company="_Test Company", flag=0, default_account="")
|
||||
@ -1735,18 +1739,18 @@ def set_advance_flag(company, flag, default_account):
|
||||
)
|
||||
|
||||
|
||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date, voucher_type="Purchase Invoice"):
|
||||
gl = frappe.qb.DocType("GL Entry")
|
||||
q = (
|
||||
frappe.qb.from_(gl)
|
||||
.select(gl.account, gl.debit, gl.credit, gl.posting_date)
|
||||
.where(
|
||||
(gl.voucher_type == "Sales Invoice")
|
||||
(gl.voucher_type == voucher_type)
|
||||
& (gl.voucher_no == voucher_no)
|
||||
& (gl.posting_date >= posting_date)
|
||||
& (gl.is_cancelled == 0)
|
||||
)
|
||||
.orderby(gl.posting_date, gl.account)
|
||||
.orderby(gl.posting_date, gl.account, gl.creation)
|
||||
)
|
||||
gl_entries = q.run(as_dict=True)
|
||||
|
||||
|
@ -3312,7 +3312,6 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
def test_advance_entries_as_liability(self):
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
|
||||
from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute
|
||||
|
||||
set_advance_flag(company="_Test Company", flag=1, default_account="Creditors - _TC")
|
||||
|
||||
@ -3344,12 +3343,16 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
si.submit()
|
||||
|
||||
self.assertEqual(si.advances[0].allocated_amount, 500)
|
||||
|
||||
# Check GL Entry against payment doctype
|
||||
expected_gle = [
|
||||
["Cash - _TC", 1000, 0.0, nowdate()],
|
||||
["Creditors - _TC", 500, 0.0, nowdate()],
|
||||
["Debtors - _TC", 500, 500, nowdate()],
|
||||
["Sales - _TC", 0.0, 500, nowdate()],
|
||||
["Debtors - _TC", 0.0, 1000, nowdate()],
|
||||
["Debtors - _TC", 0.0, 500, nowdate()],
|
||||
]
|
||||
check_gl_entries(self, si.name, expected_gle, nowdate())
|
||||
|
||||
check_gl_entries(self, pe.name, expected_gle, nowdate(), voucher_type="Payment Entry")
|
||||
self.assertEqual(si.outstanding_amount, 0)
|
||||
|
||||
set_advance_flag(company="_Test Company", flag=0, default_account="")
|
||||
@ -3401,18 +3404,18 @@ def get_sales_invoice_for_e_invoice():
|
||||
return si
|
||||
|
||||
|
||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date, voucher_type="Sales Invoice"):
|
||||
gl = frappe.qb.DocType("GL Entry")
|
||||
q = (
|
||||
frappe.qb.from_(gl)
|
||||
.select(gl.account, gl.debit, gl.credit, gl.posting_date)
|
||||
.where(
|
||||
(gl.voucher_type == "Sales Invoice")
|
||||
(gl.voucher_type == voucher_type)
|
||||
& (gl.voucher_no == voucher_no)
|
||||
& (gl.posting_date >= posting_date)
|
||||
& (gl.is_cancelled == 0)
|
||||
)
|
||||
.orderby(gl.posting_date, gl.account)
|
||||
.orderby(gl.posting_date, gl.account, gl.creation)
|
||||
)
|
||||
gl_entries = q.run(as_dict=True)
|
||||
|
||||
|
@ -436,9 +436,7 @@ def add_cc(args=None):
|
||||
return cc.name
|
||||
|
||||
|
||||
def reconcile_against_document(
|
||||
args, skip_ref_details_update_for_pe=False, is_reconcile=True
|
||||
): # nosemgrep
|
||||
def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # nosemgrep
|
||||
"""
|
||||
Cancel PE or JV, Update against document, split if required and resubmit
|
||||
"""
|
||||
@ -474,7 +472,7 @@ def reconcile_against_document(
|
||||
doc.save(ignore_permissions=True)
|
||||
# re-submit advance entry
|
||||
doc = frappe.get_doc(entry.voucher_type, entry.voucher_no)
|
||||
gl_map = doc.build_gl_map(is_reconcile)
|
||||
gl_map = doc.build_gl_map()
|
||||
create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1)
|
||||
|
||||
# Only update outstanding for newly linked vouchers
|
||||
|
@ -1025,7 +1025,7 @@ class AccountsController(TransactionBase):
|
||||
)
|
||||
)
|
||||
|
||||
def update_against_document_in_jv(self, is_reconcile=True):
|
||||
def update_against_document_in_jv(self):
|
||||
"""
|
||||
Links invoice and advance voucher:
|
||||
1. cancel advance voucher
|
||||
@ -1082,7 +1082,7 @@ class AccountsController(TransactionBase):
|
||||
if lst:
|
||||
from erpnext.accounts.utils import reconcile_against_document
|
||||
|
||||
reconcile_against_document(lst, is_reconcile)
|
||||
reconcile_against_document(lst)
|
||||
|
||||
def on_cancel(self):
|
||||
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
|
||||
|
Loading…
x
Reference in New Issue
Block a user