Skip to content

Commit de93efb

Browse files
fix: Added test cases for ewb json creation
1 parent 6856033 commit de93efb

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data
1919
from erpnext.stock.doctype.item.test_item import create_item
2020
from six import iteritems
21+
from erpnext.regional.india.utils import get_ewb_data
22+
2123
class TestSalesInvoice(unittest.TestCase):
2224
def make(self):
2325
w = frappe.copy_doc(test_records[0])
@@ -1611,6 +1613,110 @@ def check_gl_entries(self, voucher_no, expected_gle, posting_date):
16111613
self.assertEqual(expected_gle[i][2], gle.credit)
16121614
self.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
16131615

1616+
def test_eway_bill_json(self):
1617+
if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'):
1618+
address = frappe.get_doc({
1619+
"address_line1": "_Test Address Line 1",
1620+
"address_title": "_Test Address for Eway bill",
1621+
"address_type": "Billing",
1622+
"city": "_Test City",
1623+
"state": "Test State",
1624+
"country": "India",
1625+
"doctype": "Address",
1626+
"is_primary_address": 1,
1627+
"phone": "+91 0000000000",
1628+
"gstin": "27AAECE4835E1ZR",
1629+
"gst_state": "Maharashtra",
1630+
"gst_state_number": "27",
1631+
"pincode": "401108"
1632+
}).insert()
1633+
1634+
address.append("links", {
1635+
"link_doctype": "Company",
1636+
"link_name": "_Test Company"
1637+
})
1638+
1639+
address.save()
1640+
1641+
if not frappe.db.exists('Address', '_Test Customer-Address for Eway bill-Shipping'):
1642+
address = frappe.get_doc({
1643+
"address_line1": "_Test Address Line 1",
1644+
"address_title": "_Test Customer-Address for Eway bill",
1645+
"address_type": "Shipping",
1646+
"city": "_Test City",
1647+
"state": "Test State",
1648+
"country": "India",
1649+
"doctype": "Address",
1650+
"is_primary_address": 1,
1651+
"phone": "+91 0000000000",
1652+
"gst_state": "Maharashtra",
1653+
"gst_state_number": "27",
1654+
"pincode": "410038"
1655+
}).insert()
1656+
1657+
address.append("links", {
1658+
"link_doctype": "Customer",
1659+
"link_name": "_Test Customer"
1660+
})
1661+
1662+
address.save()
1663+
1664+
gst_settings = frappe.get_doc("GST Settings")
1665+
1666+
gst_account = frappe.get_all(
1667+
"GST Account",
1668+
fields=["cgst_account", "sgst_account", "igst_account"],
1669+
filters = {"company": "_Test Company"})
1670+
1671+
if not gst_account:
1672+
gst_settings.append("gst_accounts", {
1673+
"company": "_Test Company",
1674+
"cgst_account": "CGST - _TC",
1675+
"sgst_account": "SGST - _TC",
1676+
"igst_account": "IGST - _TC",
1677+
})
1678+
1679+
gst_settings.save()
1680+
1681+
si = create_sales_invoice(do_not_save =1, rate = '60000')
1682+
1683+
si.distance = 2000
1684+
si.company_address = "_Test Address for Eway bill-Billing"
1685+
si.customer_address = "_Test Customer-Address for Eway bill-Shipping"
1686+
si.vehicle_no = "KA12KA1234"
1687+
1688+
si.append("taxes", {
1689+
"charge_type": "On Net Total",
1690+
"account_head": "CGST - _TC",
1691+
"cost_center": "Main - _TC",
1692+
"description": "CGST @ 9.0",
1693+
"rate": 9
1694+
})
1695+
1696+
si.append("taxes", {
1697+
"charge_type": "On Net Total",
1698+
"account_head": "SGST - _TC",
1699+
"cost_center": "Main - _TC",
1700+
"description": "SGST @ 9.0",
1701+
"rate": 9
1702+
})
1703+
1704+
si.submit()
1705+
1706+
data = get_ewb_data("Sales Invoice", si.name)
1707+
1708+
self.assertEqual(data['version'], '1.0.1118')
1709+
self.assertEqual(data['billLists'][0]['fromGstin'], '27AAECE4835E1ZR')
1710+
self.assertEqual(data['billLists'][0]['fromTrdName'], '_Test Company')
1711+
self.assertEqual(data['billLists'][0]['toTrdName'], '_Test Customer')
1712+
self.assertEqual(data['billLists'][0]['vehicleType'], 'R')
1713+
self.assertEqual(data['billLists'][0]['totalValue'], 60000)
1714+
self.assertEqual(data['billLists'][0]['cgstValue'], 5400)
1715+
self.assertEqual(data['billLists'][0]['sgstValue'], 5400)
1716+
self.assertEqual(data['billLists'][0]['vehicleNo'], 'KA12KA1234')
1717+
self.assertEqual(data['billLists'][0]['itemList'][0]['taxableAmount'], 60000)
1718+
1719+
16141720
def create_sales_invoice(**args):
16151721
si = frappe.new_doc("Sales Invoice")
16161722
args = frappe._dict(args)

0 commit comments

Comments
 (0)