Skip to content

Commit 969013c

Browse files
authored
Merge pull request #3888 from karm1000/handle/is-return-in-ewaybill
fix: set `to state code` from billing address for returns
2 parents 040ff94 + 047df0e commit 969013c

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

india_compliance/gst_india/data/test_e_waybill.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,5 +1356,78 @@
13561356
"Status": "CAN",
13571357
"StatusDesc": "Cancelled"
13581358
}
1359+
},
1360+
"overseas_customer_domestic_shipping": {
1361+
"kwargs": {
1362+
"customer": "_Test Foreign Customer-1",
1363+
"customer_address": "_Test Foreign Customer-1-Billing",
1364+
"shipping_address_name": "_Test Foreign Customer-1-Shipping",
1365+
"vehicle_no": "GJ07DL9009",
1366+
"company_address": "_Test Indian Registered Company-Billing",
1367+
"is_in_state": 1
1368+
},
1369+
"request_data": {
1370+
"userGstin": "05AAACG2115R1ZN",
1371+
"supplyType": "O",
1372+
"subSupplyType": 1,
1373+
"docType": "INV",
1374+
"docNo": "test_invoice_no",
1375+
"docDate": "09/01/2026",
1376+
"transactionType": 2,
1377+
"fromTrdName": "_Test Indian Registered Company",
1378+
"fromGstin": "05AAACG2115R1ZN",
1379+
"fromAddr1": "Test Address - 1",
1380+
"fromPlace": "Test City",
1381+
"fromPincode": 380015,
1382+
"fromStateCode": 24,
1383+
"actFromStateCode": 24,
1384+
"toTrdName": "_Test Foreign Customer-1",
1385+
"toGstin": "URP",
1386+
"toAddr1": "Test Address - 13",
1387+
"toPlace": "Test City",
1388+
"toPincode": 380015,
1389+
"toStateCode": 24,
1390+
"actToStateCode": 24,
1391+
"totalValue": 100.0,
1392+
"cgstValue": 9.0,
1393+
"sgstValue": 9.0,
1394+
"igstValue": 0,
1395+
"cessValue": 0,
1396+
"cessNonAdvolValue": 0,
1397+
"otherValue": 0.0,
1398+
"totInvValue": 118.0,
1399+
"transMode": 1,
1400+
"transDistance": 10,
1401+
"transporterName": "Test Common Supplier",
1402+
"vehicleNo": "GJ07DL9009",
1403+
"vehicleType": "R",
1404+
"itemList": [
1405+
{
1406+
"itemNo": 1,
1407+
"productDesc": "Test Trading Goods 1",
1408+
"hsnCode": "61149090",
1409+
"qtyUnit": "NOS",
1410+
"quantity": 1.0,
1411+
"taxableAmount": 100.0,
1412+
"sgstRate": 9.0,
1413+
"cgstRate": 9.0,
1414+
"igstRate": 0,
1415+
"cessRate": 0,
1416+
"cessNonAdvol": 0
1417+
}
1418+
],
1419+
"mainHsnCode": "61149090"
1420+
},
1421+
"params": "action=GENEWAYBILL",
1422+
"response_data": {
1423+
"message": "E-Way Bill is generated successfully",
1424+
"result": {
1425+
"alert": "",
1426+
"ewayBillDate": "09/01/2026 12:00:00 PM",
1427+
"ewayBillNo": 391010000001,
1428+
"validUpto": "10/01/2026 11:59:00 PM"
1429+
},
1430+
"success": true
1431+
}
13591432
}
13601433
}

india_compliance/gst_india/utils/e_waybill.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,10 @@ def _get_sandbox_gstin(address, key):
17301730
self.bill_from.gstin = _get_sandbox_gstin(self.bill_from, 0)
17311731
self.bill_to.gstin = _get_sandbox_gstin(self.bill_to, 1)
17321732

1733-
to_state_code = int(self.transaction_details.pos_state_code)
1733+
if self.doc.get("is_return"):
1734+
to_state_code = self.bill_to.state_number
1735+
else:
1736+
to_state_code = int(self.transaction_details.pos_state_code)
17341737

17351738
data = {
17361739
"userGstin": self.transaction_details.company_gstin,

india_compliance/gst_india/utils/test_e_waybill.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,61 @@ def test_generate_e_waybill_with_cancelled_gstin_error_3029_standard(self):
13331333
"GSTIN -29AAACI1195H2ZH is inactive or cancelled", str(cm.exception)
13341334
)
13351335

1336+
@responses.activate
1337+
def test_e_waybill_overseas_customer_with_domestic_shipping(self):
1338+
"""Test e-waybill for overseas customer with domestic shipping address.
1339+
1340+
When an overseas customer has goods shipped within India the toStateCode should be set based on
1341+
the place of supply, not as 96-Other Countries.
1342+
"""
1343+
test_data = self.e_waybill_test_data.get("overseas_customer_domestic_shipping")
1344+
si = self.create_sales_invoice_for("overseas_customer_domestic_shipping")
1345+
1346+
e_waybill_data = EWaybillData(si).get_data()
1347+
1348+
self.assertEqual(
1349+
e_waybill_data.get("toStateCode"),
1350+
24,
1351+
"toStateCode should be set from place of supply (shipping address state)",
1352+
)
1353+
1354+
expected_request_data = test_data.get("request_data")
1355+
for key, value in e_waybill_data.items():
1356+
self.assertEqual(
1357+
expected_request_data.get(key), value, f"Mismatch for key '{key}'"
1358+
)
1359+
1360+
def test_e_waybill_for_inter_state_sales_return(self):
1361+
"""Test e-waybill generation for inter-state sales return.
1362+
1363+
For return documents (is_return=1) with inter-state transport,
1364+
the toStateCode should come from bill_to's state number.
1365+
"""
1366+
si = create_sales_invoice(
1367+
vehicle_no="GJ07DL9009",
1368+
company_address="_Test Indian Registered Company-Billing",
1369+
customer="_Test Registered Customer",
1370+
customer_address="_Test Registered Customer-Billing-3",
1371+
is_out_state=1,
1372+
)
1373+
1374+
credit_note = make_return_doc("Sales Invoice", si.name)
1375+
credit_note.vehicle_no = "GJ07DL9009"
1376+
credit_note.save()
1377+
credit_note.submit()
1378+
1379+
e_waybill_data = EWaybillData(credit_note).get_data()
1380+
1381+
# For inter-state return, toStateCode should be company's state (bill_to after swap)
1382+
self.assertEqual(
1383+
e_waybill_data.get("toStateCode"),
1384+
24,
1385+
"For inter-state returns, toStateCode should be from bill_to.state_number",
1386+
)
1387+
1388+
self.assertEqual(e_waybill_data.get("supplyType"), "I")
1389+
self.assertEqual(e_waybill_data.get("subSupplyType"), 7)
1390+
13361391
# helper functions
13371392
def _generate_e_waybill(
13381393
self, docname=None, doctype="Sales Invoice", test_data=None, force=False

0 commit comments

Comments
 (0)