Skip to content

Commit

Permalink
Merge pull request #1015 from 8848digital/account-tds-test-cases
Browse files Browse the repository at this point in the history
ref : done code code refactoring in the test_payment_entry test_purchase_invoice and test_tax_withholding_category
  • Loading branch information
tinadn authored Jan 14, 2025
2 parents 69a4cc4 + 26e952b commit 5eed582
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 77 deletions.
89 changes: 51 additions & 38 deletions erpnext/accounts/doctype/payment_entry/test_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,11 @@ def create_supplier(**args):
args = frappe._dict(args)

if frappe.db.exists("Supplier", args.supplier_name):
return frappe.get_doc("Supplier", args.supplier_name)
doc = frappe.get_doc("Supplier", args.supplier_name)
if doc.name == "_Test Supplier USD" and not frappe.db.exists("Party Account", {"parent": doc.name, "account": "_Test Payable USD - _TC"}):
doc.append("accounts", {"company": args.company, "account": "_Test Payable USD - _TC"})
frappe.db.commit()
return doc
doc = frappe.get_doc(
{
"doctype": "Supplier",
Expand All @@ -2215,12 +2219,11 @@ def create_supplier(**args):
'company': args.company,
'account': '_Test Payable USD - _TC' if args.default_currency == 'USD' else '_Test TDS Payable - _TC',
})

if not args.without_supplier_group:
doc.supplier_group = args.supplier_group or "Services"


doc.insert()
doc.save()
doc.insert(ignore_mandatory=True)
frappe.db.commit()
return doc

Expand Down Expand Up @@ -2260,7 +2263,7 @@ def create_account():

if account["parent"]:
doc.parent_account = account["parent"]

doc.insert(ignore_mandatory=True)
frappe.db.commit()

Expand Down Expand Up @@ -2295,40 +2298,50 @@ def create_records(supplier):


def make_test_item(item_name=None):
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.doctype.item.test_item import make_item
app_name = "india_compliance"
if not frappe.db.exists("Item", item_name or "Test Item with Tax"):
if app_name in frappe.get_installed_apps():
if not frappe.db.exists("GST HSN Code", '888890'):
frappe.get_doc({
"doctype": 'GST HSN Code',
"hsn_code": '888890',
"description": 'test'
}).insert()
frappe.db.commit()

item= make_item(
item_name or "Test Item with Tax",
{
"is_stock_item": 1,
"gst_hsn_code": "888890",
},
)

return item

if not frappe.db.exists("Item", item_name or "Test Item with Tax"):
app_name = "india_compliance"

if app_name in frappe.get_installed_apps():
if not frappe.db.exists("GST HSN Code", '888890'):
frappe.get_doc({
"doctype": 'GST HSN Code',
"hsn_code": '888890',
"description": 'test'
}).insert()
frappe.db.commit()

item= make_item(
item_name or "Test Item with Tax",
{
"is_stock_item": 1,
"gst_hsn_code": "888890",
},
)

return item

else:
item= make_item(
"Test TDS Item",
{
"is_stock_item": 1,
},
)
return item
else:
return frappe.get_doc("Item", item_name or "Test Item with Tax")
else:
item= make_item(
"Test TDS Item",
{
"is_stock_item": 1,
},
)
return item
else:
if app_name in frappe.get_installed_apps():
if not frappe.db.exists("GST HSN Code", '888890'):
frappe.get_doc({
"doctype": 'GST HSN Code',
"hsn_code": '888890',
"description": 'test'
}).insert()
item=frappe.get_doc("Item", item_name or "Test Item with Tax")
if not item.gst_hsn_code:
item.gst_hsn_code="888890"
item.save()
frappe.db.commit()
return item

def create_purchase_invoice(**args):
# return sales invoice doc object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ frappe.ui.form.on("Payment Request", "is_a_subscription", function (frm) {
});
}
});

19 changes: 3 additions & 16 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ class PaymentRequest(Document):
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from erpnext.accounts.doctype.subscription_plan_detail.subscription_plan_detail import SubscriptionPlanDetail
from frappe.types import DF

from erpnext.accounts.doctype.subscription_plan_detail.subscription_plan_detail import (
SubscriptionPlanDetail,
)

account: DF.ReadOnly | None
amended_from: DF.Link | None
bank: DF.Link | None
Expand All @@ -65,7 +62,7 @@ class PaymentRequest(Document):
party_name: DF.Data | None
party_type: DF.Link | None
payment_account: DF.ReadOnly | None
payment_channel: DF.Literal["", "Email", "Phone", "Other"]
payment_channel: DF.Literal["", "Email", "Phone"]
payment_gateway: DF.ReadOnly | None
payment_gateway_account: DF.Link | None
payment_order: DF.Link | None
Expand All @@ -74,17 +71,7 @@ class PaymentRequest(Document):
print_format: DF.Literal[None]
reference_doctype: DF.Link | None
reference_name: DF.DynamicLink | None
status: DF.Literal[
"",
"Draft",
"Requested",
"Initiated",
"Partially Paid",
"Payment Ordered",
"Paid",
"Failed",
"Cancelled",
]
status: DF.Literal["", "Draft", "Requested", "Initiated", "Partially Paid", "Payment Ordered", "Paid", "Failed", "Cancelled"]
subject: DF.Data | None
subscription_plans: DF.Table[SubscriptionPlanDetail]
swift_number: DF.ReadOnly | None
Expand Down
106 changes: 85 additions & 21 deletions erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2468,16 +2468,35 @@ def test_tax_withholding_with_supplier_TC_ACC_023(self):
pi.tax_withholding_category="Test - TDS - 194C - Company"
pi.save()
pi.submit()

expected_result=[
['Creditors - _TC', 0.0, 90000.0, pi.posting_date],
['Creditors - _TC', 1800.0, 0.0, pi.posting_date],
['Stock Received But Not Billed - _TC', 90000.0, 0.0, pi.posting_date],
['_Test TDS Payable - _TC', 0.0, 1800.0, pi.posting_date]
]

check_gl_entries(self,voucher_no=pi.name,expected_gle=expected_result,posting_date=pi.posting_date,voucher_type="Purchase Invoice")
# self.assertEqual(gl_entries,expected_result)
gl_entries = frappe.db.sql(
"""select account, sum(debit) as debit, sum(credit) as credit , against_voucher
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
group by account,against_voucher""",
pi.name,
as_dict=1,
)

expected_result = [
{
"account": "Creditors - _TC",
"debit": 1800.0,
"credit": 90000.0,
"against_voucher": pi.name
},
{
"account": "Stock Received But Not Billed - _TC",
"debit": 90000.0,
"credit": 0.0,
"against_voucher": None
},
{
"account": "_Test TDS Payable - _TC",
"debit": 0.0,
"credit": 1800.0,
"against_voucher": None
}
]
self.assertEqual(gl_entries,expected_result)



Expand Down Expand Up @@ -2583,7 +2602,7 @@ def test_lower_tax_deduction_TC_ACC_025_and_TC_ACC_026(self):
["Creditors - _TC", 0.0, 50000.0, pi.posting_date],
["Creditors - _TC", 600.0, 0.0, pi.posting_date],
["Stock Received But Not Billed - _TC", 50000.0, 0.0, pi.posting_date],
["Test TDS Payable - _TC", 0.0, 600.0, pi.posting_date]
["_Test TDS Payable - _TC", 0.0, 600.0, pi.posting_date]
]

check_gl_entries(self, pi.name, expected_gle, pi.posting_date)
Expand Down Expand Up @@ -2613,6 +2632,8 @@ def test_currency_exchange_with_pi_TC_ACC_027(self):
pi.submit()

pe = get_payment_entry("Purchase Invoice", pi.name)
pe.payment_type= "Pay"
pe.paid_from = "Cash - _TC"
pe.target_exchange_rate = 60
pe.save()
pe.submit()
Expand Down Expand Up @@ -2673,6 +2694,7 @@ def test_advance_payment_TC_ACC_028(self):

records_for_pi('_Test Supplier USD')
supplier = frappe.get_doc('Supplier', '_Test Supplier USD')

if supplier:
pe = create_payment_entry(
party_type="Supplier",
Expand All @@ -2692,13 +2714,14 @@ def test_advance_payment_TC_ACC_028(self):
pe.append(
"taxes",
{
"account_head": "_Test TDS Payable - _TC",
"account_head": "Test TDS Payable - _TC",
"charge_type": "On Paid Amount",
"rate": 0,
"add_deduct_tax": "Deduct",
"description": "Cash",
},
)

pe.save()
pe.submit()

Expand Down Expand Up @@ -2758,6 +2781,8 @@ def test_advance_payment_TC_ACC_028(self):

_pe = get_payment_entry('Purchase Invoice', pi.name)
_pe.target_exchange_rate = 62
_pe.payment_type= "Pay"
_pe.paid_from = "Cash - _TC"
_pe.save()
_pe.submit()

Expand Down Expand Up @@ -2810,15 +2835,29 @@ def test_single_payment_request_for_purchase_invoice_TC_ACC_035(self):
dn=pi.name,
party_type="Supplier",
party=supplier.name,
grand_total=5000,
submit_doc=1,
return_doc=1,
)

pe=pr.create_payment_entry()
pe=pr.create_payment_entry(submit=False)
pe.payment_type= "Pay"
pe.paid_from = "Cash - _TC"
pe.save()
pe.submit()
pr.load_from_db()
self.assertEqual(pr.status, "Paid")
pe.load_from_db()
expected_gle = [
['Cash - _TC', 0.0, 5000.0, pe.posting_date],
['Creditors - _TC', 5000.0, 0.0, pe.posting_date]
]
check_gl_entries(
doc=self,
voucher_no=pe.name,
expected_gle=expected_gle,
voucher_type="Payment Entry",
posting_date=pe.posting_date
)
pi.load_from_db()
self.assertEqual(pi.status, "Paid")
def test_multi_payment_request_for_purchase_invoice_TC_ACC_036(self):
Expand Down Expand Up @@ -2854,13 +2893,25 @@ def test_multi_payment_request_for_purchase_invoice_TC_ACC_036(self):
pr.grand_total = pr.grand_total / 2
pr.save()
pr.submit()
pe=pr.create_payment_entry()
pe=pr.create_payment_entry(submit=False)
pe.payment_type= "Pay"
pe.paid_from = "Cash - _TC"
pe.save()
pe.submit()
pr.load_from_db()
self.assertEqual(pr.status, "Paid")
pe.load_from_db()

expected_gle = [
['Cash - _TC', 0.0, 2500.0, pe.posting_date],
['Creditors - _TC', 2500.0, 0.0, pe.posting_date]
]
check_gl_entries(
doc=self,
voucher_no=pe.name,
expected_gle=expected_gle,
voucher_type="Payment Entry",
posting_date=pe.posting_date
)
pi.load_from_db()
self.assertEqual(pi.status, "Partly Paid")
_pr = make_payment_request(
Expand All @@ -2871,13 +2922,26 @@ def test_multi_payment_request_for_purchase_invoice_TC_ACC_036(self):
return_doc=1,
submit_doc=1,
)
_pe=_pr.create_payment_entry()
_pe=_pr.create_payment_entry(submit=False)
_pe.payment_type= "Pay"
_pe.paid_from = "Cash - _TC"
_pe.save()
_pe.submit()
_pr.load_from_db()
self.assertEqual(_pr.status, "Paid")
pi.load_from_db()
self.assertEqual(pi.status, "Paid")
_pe.load_from_db()
expected_gle = [
['Cash - _TC', 0.0, 2500.0, _pe.posting_date],
['Creditors - _TC', 2500.0, 0.0, _pe.posting_date]
]
check_gl_entries(
doc=self,
voucher_no=_pe.name,
expected_gle=expected_gle,
voucher_type="Payment Entry",
posting_date=_pe.posting_date
)

def test_invoice_status_on_payment_entry_submit_TC_B_035_and_TC_B_037(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
from erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment import payment_reconciliation_record_on_unreconcile,create_unreconcile_doc_for_selection
Expand Down Expand Up @@ -3216,7 +3280,7 @@ def test_standalone_pi_is_partly_paid_TC_B_090(self):

pi_status = frappe.db.get_value("Purchase Invoice", pi.name, "status")
self.assertEqual(pi_status, "Partly Paid")

def set_advance_flag(company, flag, default_account):
frappe.db.set_value(
"Company",
Expand Down Expand Up @@ -3253,7 +3317,6 @@ def check_gl_entries(
for col in additional_columns:
query = query.select(gl[col])
gl_entries = query.run(as_dict=True)

for i, gle in enumerate(gl_entries):
doc.assertEqual(expected_gle[i][0], gle.account)
doc.assertEqual(expected_gle[i][1], gle.debit)
Expand Down Expand Up @@ -3489,6 +3552,7 @@ def update_ldc_details(supplier):
setattr(supplier,'custom_lower_tds_deduction_applicable','Yes')
if not supplier.pan:
setattr(supplier,'pan','DAJPC4150P')
supplier.flags.ignore_mandatory = True
supplier.save()
frappe.db.commit()

Expand Down
6 changes: 5 additions & 1 deletion erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4315,7 +4315,11 @@ def test_jv_records_creation_diff_ex_rate_TC_ACC_029(self):
si.save()
si.submit()

pe = get_payment_entry("Sales Invoice", si.name)
pe = get_payment_entry("Sales Invoice", si.name)
pe.payment_type == "Receive"
pe.mode_of_payment = "Cash"
pe.paid_from="_Test Receivable USD - _TC"
pe.paid_to = "Cash - _TC"
pe.source_exchange_rate = 60
pe.save()
pe.submit()
Expand Down
Loading

0 comments on commit 5eed582

Please sign in to comment.