| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from freezegun import freeze_time |
| 4 |
|
| 5 |
from odoo import _ |
| 6 |
from odoo.addons.l10n_in.tests.common import L10nInTestInvoicingCommon |
| 7 |
from odoo.tests import tagged |
| 8 |
|
| 9 |
|
| 10 |
@tagged("post_install_l10n", "post_install", "-at_install") |
| 11 |
class TestEwaybillJson(L10nInTestInvoicingCommon): |
| 12 |
|
| 13 |
@classmethod |
| 14 |
def setUpClass(cls): |
| 15 |
super().setUpClass() |
| 16 |
cls.invoice = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_with_cess) |
| 17 |
cls.invoice.write({ |
| 18 |
"invoice_line_ids": [(1, l_id, {"discount": 10}) for l_id in cls.invoice.invoice_line_ids.ids] |
| 19 |
}) |
| 20 |
cls.invoice.action_post() |
| 21 |
cls.invoice_full_discount = cls.init_invoice("out_invoice", post=False, products=cls.product_a) |
| 22 |
cls.invoice_full_discount.write({ |
| 23 |
"invoice_line_ids": [(1, l_id, {"discount": 100}) for l_id in cls.invoice_full_discount.invoice_line_ids.ids]}) |
| 24 |
cls.invoice_full_discount.action_post() |
| 25 |
cls.invoice_zero_qty = cls.init_invoice("out_invoice", post=False, products=cls.product_a) |
| 26 |
cls.invoice_zero_qty.write({ |
| 27 |
"invoice_line_ids": [(1, l_id, {"quantity": 0}) for l_id in cls.invoice_zero_qty.invoice_line_ids.ids]}) |
| 28 |
cls.invoice_zero_qty.action_post() |
| 29 |
|
| 30 |
def test_edi_json(self): |
| 31 |
default_ewaybill_vals = { |
| 32 |
'distance': 20, |
| 33 |
'type_id': self.env.ref("l10n_in_ewaybill.type_tax_invoice_sub_type_supply").id, |
| 34 |
'mode': "1", |
| 35 |
'vehicle_no': "GJ11AA1234", |
| 36 |
'vehicle_type': "R", |
| 37 |
} |
| 38 |
Ewaybill = self.env['l10n.in.ewaybill'] |
| 39 |
ewaybill_invoice = Ewaybill.create({ |
| 40 |
'account_move_id': self.invoice.id, |
| 41 |
**default_ewaybill_vals |
| 42 |
}) |
| 43 |
ewaybill_invoice_full_discount = Ewaybill.create({ |
| 44 |
'account_move_id': self.invoice_full_discount.id, |
| 45 |
**default_ewaybill_vals |
| 46 |
}) |
| 47 |
ewaybill_invoice_zero_qty = Ewaybill.create({ |
| 48 |
'account_move_id': self.invoice_zero_qty.id, |
| 49 |
**default_ewaybill_vals |
| 50 |
}) |
| 51 |
json_value = ewaybill_invoice._ewaybill_generate_direct_json() |
| 52 |
expected = { |
| 53 |
"supplyType": "O", |
| 54 |
"docType": "INV", |
| 55 |
"subSupplyType": "1", |
| 56 |
"transactionType": 1, |
| 57 |
"transDistance": "20", |
| 58 |
"transMode": "1", |
| 59 |
"vehicleNo": "GJ11AA1234", |
| 60 |
"vehicleType": "R", |
| 61 |
"docNo": "INV/18-19/0001", |
| 62 |
"docDate": "01/01/2019", |
| 63 |
"fromGstin": "24AAGCC7144L6ZE", |
| 64 |
"fromTrdName": "Default Company", |
| 65 |
"fromAddr1": "Khodiyar Chowk", |
| 66 |
"fromAddr2": "Sala Number 3", |
| 67 |
"fromPlace": "Amreli", |
| 68 |
"fromPincode": 365220, |
| 69 |
"fromStateCode": 24, |
| 70 |
"actFromStateCode": 24, |
| 71 |
"toGstin": "24ABCPM8965E1ZE", |
| 72 |
"toTrdName": "Partner Intra State", |
| 73 |
"toAddr1": "Karansinhji Rd", |
| 74 |
"toAddr2": "Karanpara", |
| 75 |
"toPlace": "Rajkot", |
| 76 |
"toPincode": 360001, |
| 77 |
"actToStateCode": 24, |
| 78 |
"toStateCode": 24, |
| 79 |
"itemList": [ |
| 80 |
{ |
| 81 |
"productName": "product_a", |
| 82 |
"hsnCode": "111111", |
| 83 |
"productDesc": "product_a", |
| 84 |
"quantity": 1.0, |
| 85 |
"qtyUnit": "UNT", |
| 86 |
"taxableAmount": 900.0, |
| 87 |
"cgstRate": 2.5, |
| 88 |
"sgstRate": 2.5 |
| 89 |
}, |
| 90 |
{ |
| 91 |
"productName": "product_with_cess", |
| 92 |
"hsnCode": "333333", |
| 93 |
"productDesc": "product_with_cess", |
| 94 |
"quantity": 1.0, |
| 95 |
"qtyUnit": "UNT", |
| 96 |
"taxableAmount": 900.0, |
| 97 |
"cgstRate": 6.0, |
| 98 |
"sgstRate": 6.0, |
| 99 |
"cessRate": 5.0 |
| 100 |
} |
| 101 |
], |
| 102 |
"totalValue": 1800.0, |
| 103 |
"cgstValue": 76.5, |
| 104 |
"sgstValue": 76.5, |
| 105 |
"igstValue": 0.0, |
| 106 |
"cessValue": 45.0, |
| 107 |
"cessNonAdvolValue": 1.59, |
| 108 |
"otherValue": 0.0, |
| 109 |
"totInvValue": 1999.59 |
| 110 |
} |
| 111 |
self.assertDictEqual(json_value, expected, "Indian EDI send json value is not matched") |
| 112 |
|
| 113 |
# =================================== Different UOM Test =========================================== |
| 114 |
self.invoice.button_draft() |
| 115 |
self.invoice.invoice_line_ids.product_uom_id = self.env.ref('uom.product_uom_dozen') |
| 116 |
self.invoice.action_post() |
| 117 |
json_value = ewaybill_invoice._ewaybill_generate_direct_json() |
| 118 |
self.assertListEqual( |
| 119 |
json_value['itemList'], |
| 120 |
[ |
| 121 |
{ |
| 122 |
"productName": "product_a", |
| 123 |
"hsnCode": "111111", |
| 124 |
"productDesc": "product_a", |
| 125 |
"quantity": 1.0, |
| 126 |
"qtyUnit": "DOZ", |
| 127 |
"taxableAmount": 900.0 * 12, |
| 128 |
"cgstRate": 2.5, |
| 129 |
"sgstRate": 2.5 |
| 130 |
}, |
| 131 |
{ |
| 132 |
"productName": "product_with_cess", |
| 133 |
"hsnCode": "333333", |
| 134 |
"productDesc": "product_with_cess", |
| 135 |
"quantity": 1.0, |
| 136 |
"qtyUnit": "DOZ", |
| 137 |
"taxableAmount": 900.0 * 12, |
| 138 |
"cgstRate": 6.0, |
| 139 |
"sgstRate": 6.0, |
| 140 |
"cessRate": 5.0 |
| 141 |
} |
| 142 |
], |
| 143 |
"Indian EDI send json UOM value is not matched" |
| 144 |
) |
| 145 |
|
| 146 |
# =================================== Full discount test ===================================== |
| 147 |
json_value = ewaybill_invoice_full_discount._ewaybill_generate_direct_json() |
| 148 |
expected.update({ |
| 149 |
"docNo": "INV/18-19/0002", |
| 150 |
"itemList": [{ |
| 151 |
"productName": "product_a", "hsnCode": "111111", "productDesc": "product_a", "quantity": 1.0, |
| 152 |
"qtyUnit": "UNT", "taxableAmount": 0.0, "cgstRate": 0.0, "sgstRate": 0.0, 'igstRate': 0.0, |
| 153 |
}], |
| 154 |
"totalValue": 0.0, |
| 155 |
"cgstValue": 0.0, |
| 156 |
"sgstValue": 0.0, |
| 157 |
"igstValue": 0.0, |
| 158 |
"cessValue": 0.0, |
| 159 |
"cessNonAdvolValue": 0.00, |
| 160 |
"otherValue": 0.0, |
| 161 |
"totInvValue": 0.0 |
| 162 |
}) |
| 163 |
self.assertDictEqual(json_value, expected, "Indian EDI with 100% discount sent json value is not matched") |
| 164 |
|
| 165 |
# =================================== Zero quantity test ============================================= |
| 166 |
json_value = ewaybill_invoice_zero_qty._ewaybill_generate_direct_json() |
| 167 |
expected.update({ |
| 168 |
"docNo": "INV/18-19/0003", |
| 169 |
"itemList": [{ |
| 170 |
"productName": "product_a", "hsnCode": "111111", "productDesc": "product_a", "quantity": 0.0, |
| 171 |
"qtyUnit": "UNT", "taxableAmount": 0.0, "cgstRate": 0.0, "sgstRate": 0.0, 'igstRate': 0.0, |
| 172 |
}], |
| 173 |
"totalValue": 0.0, |
| 174 |
"cgstValue": 0.0, |
| 175 |
"sgstValue": 0.0, |
| 176 |
"igstValue": 0.0, |
| 177 |
"cessValue": 0.0, |
| 178 |
"cessNonAdvolValue": 0.00, |
| 179 |
"otherValue": 0.0, |
| 180 |
"totInvValue": 0.0 |
| 181 |
}) |
| 182 |
self.assertDictEqual(json_value, expected, "Indian EDI with 0(zero) quantity sent json value is not matched") |
| 183 |
|
| 184 |
def test_ewaybill_zero_distance(self): |
| 185 |
""" |
| 186 |
Ewaybill Zero distance test |
| 187 |
""" |
| 188 |
ewaybill = self.env['l10n.in.ewaybill'].create({ |
| 189 |
'type_id': self.env.ref('l10n_in_ewaybill.type_tax_invoice_sub_type_supply').id, |
| 190 |
'account_move_id': self.invoice.id, |
| 191 |
'transporter_id': self.partner_a.id, |
| 192 |
'mode': '2', |
| 193 |
'distance': 0, |
| 194 |
'transportation_doc_no': 123456789, |
| 195 |
'transportation_doc_date': '2024-04-26' |
| 196 |
}) |
| 197 |
|
| 198 |
# Sub-test: Extract `Distance` when multiple alerts in response |
| 199 |
with self.subTest(scenario="Extract distance when multiple alerts in response"): |
| 200 |
expected_distance = 118 |
| 201 |
response = { |
| 202 |
'status_cd': '1', |
| 203 |
'status_desc': 'EWAYBILL request succeeds', |
| 204 |
'data': { |
| 205 |
'ewayBillNo': 123456789012, |
| 206 |
'ewayBillDate': '26/02/2024 12:09:43 PM', |
| 207 |
'validUpto': '27/02/2024 12:09:43 PM', |
| 208 |
"alert": ", Distance between these two pincodes is 118, " |
| 209 |
} |
| 210 |
} |
| 211 |
distance_val = ewaybill._l10n_in_ewaybill_handle_zero_distance_alert_if_present(response.get('data')) |
| 212 |
self.assertEqual(distance_val['distance'], expected_distance) |
| 213 |
|
| 214 |
# Sub-test: Extract `Distance` when single alert in response |
| 215 |
with self.subTest(scenario="Extract distance when single alert in response"): |
| 216 |
ewaybill.distance = 0 |
| 217 |
expected_distance = 222 |
| 218 |
response = { |
| 219 |
'status_cd': '1', |
| 220 |
'status_desc': 'EWAYBILL request succeeds', |
| 221 |
'data': { |
| 222 |
'ewayBillNo': 987654321012, |
| 223 |
'ewayBillDate': '08/04/2025 11:04:04 AM', |
| 224 |
'validUpto': '09/04/2025 11:04:04 AM', |
| 225 |
'alert': 'Distance between these two pincodes is 222' |
| 226 |
} |
| 227 |
} |
| 228 |
distance_val = ewaybill._l10n_in_ewaybill_handle_zero_distance_alert_if_present(response.get('data')) |
| 229 |
self.assertEqual(distance_val['distance'], expected_distance) |
| 230 |
|
| 231 |
def test_ewaybill_export_overseas(self): |
| 232 |
ewaybill_invoice_with_export_without_lut = self.env['l10n.in.ewaybill'].create({ |
| 233 |
"type_id": self.env.ref("l10n_in_ewaybill.type_tax_invoice_sub_type_export").id, |
| 234 |
"account_move_id": self.invoice_with_export_without_lut.id, |
| 235 |
"distance": 20, |
| 236 |
"mode": "1", |
| 237 |
"vehicle_no": "GJ11AA1234", |
| 238 |
"vehicle_type": "R", |
| 239 |
}) |
| 240 |
|
| 241 |
ewaybill_invoice_with_export_lut = self.env['l10n.in.ewaybill'].create({ |
| 242 |
"type_id": self.env.ref("l10n_in_ewaybill.type_tax_invoice_sub_type_export").id, |
| 243 |
"account_move_id": self.invoice_with_export_lut.id, |
| 244 |
"distance": 20, |
| 245 |
"mode": "1", |
| 246 |
"vehicle_no": "GJ11AA1234", |
| 247 |
"vehicle_type": "R", |
| 248 |
}) |
| 249 |
|
| 250 |
# ================================== Ewaybill JSON for Export without LUT =========================================== |
| 251 |
json_value = ewaybill_invoice_with_export_without_lut._ewaybill_generate_direct_json() |
| 252 |
expected = { |
| 253 |
"supplyType": "O", |
| 254 |
"subSupplyType": "3", |
| 255 |
"docType": "INV", |
| 256 |
"transactionType": 1, |
| 257 |
"transDistance": "20", |
| 258 |
"docNo": False, |
| 259 |
"docDate": "01/01/2019", |
| 260 |
"fromGstin": "24AAGCC7144L6ZE", |
| 261 |
"fromTrdName": "Default Company", |
| 262 |
"fromAddr1": "Khodiyar Chowk", |
| 263 |
"fromAddr2": "Sala Number 3", |
| 264 |
"fromPlace": "Amreli", |
| 265 |
"fromPincode": 365220, |
| 266 |
"fromStateCode": 24, |
| 267 |
"actFromStateCode": 24, |
| 268 |
"toGstin": "URP", |
| 269 |
"toTrdName": "Foreign Partner", |
| 270 |
"toAddr1": "351 Horner Chapel Rd", |
| 271 |
"toAddr2": "", |
| 272 |
"toPlace": "Peebles", |
| 273 |
"toPincode": 999999, |
| 274 |
"actToStateCode": 99, |
| 275 |
"toStateCode": 99, |
| 276 |
"itemList": [{ |
| 277 |
"productName": "product_a", |
| 278 |
"hsnCode": "111111", |
| 279 |
"productDesc": "product_a", |
| 280 |
"quantity": 1.0, |
| 281 |
"qtyUnit": "UNT", |
| 282 |
"taxableAmount": 1000.0, |
| 283 |
"igstRate": 18.0, |
| 284 |
}], |
| 285 |
"totalValue": 1000.0, |
| 286 |
"cgstValue": 0.0, |
| 287 |
"sgstValue": 0.0, |
| 288 |
"igstValue": 180.0, |
| 289 |
"cessValue": 0.0, |
| 290 |
"cessNonAdvolValue": 0.0, |
| 291 |
"otherValue": 0.0, |
| 292 |
"totInvValue": 1180.0, |
| 293 |
"transMode": "1", |
| 294 |
"vehicleNo": "GJ11AA1234", |
| 295 |
"vehicleType": "R" |
| 296 |
} |
| 297 |
self.assertDictEqual(json_value, expected, "Indian EDI Export without LUT json value does not match") |
| 298 |
|
| 299 |
# ================================== Ewaybill JSON for Export with LUT =========================================== |
| 300 |
json_value = ewaybill_invoice_with_export_lut._ewaybill_generate_direct_json() |
| 301 |
expected.update({ |
| 302 |
"igstValue": 0.0, |
| 303 |
"totInvValue": 1000.0, |
| 304 |
}) |
| 305 |
self.assertDictEqual(json_value, expected, "Indian EDI Export with LUT json value does not match") |
| 306 |
|
| 307 |
def test_ewaybill_transporter_gst(self): |
| 308 |
self.partner_b.write({ |
| 309 |
"vat": False, |
| 310 |
"street": "Block no. 401", |
| 311 |
"street2": "Street 2", |
| 312 |
"city": "City 2", |
| 313 |
"zip": "500001", |
| 314 |
"state_id": self.env.ref("base.state_in_ts").id, |
| 315 |
"country_id": self.env.ref("base.in").id, |
| 316 |
"l10n_in_gst_treatment": "unregistered", |
| 317 |
}) |
| 318 |
ewaybill_invoice = self.env['l10n.in.ewaybill'].create({ |
| 319 |
"type_id": self.env.ref("l10n_in_ewaybill.type_tax_invoice_sub_type_supply").id, |
| 320 |
"account_move_id": self.invoice.id, |
| 321 |
"distance": 20, |
| 322 |
"mode": "1", |
| 323 |
"vehicle_no": "GJ11AA1234", |
| 324 |
"vehicle_type": "R", |
| 325 |
"transporter_id": self.partner_b.id, |
| 326 |
}) |
| 327 |
expected = { |
| 328 |
"supplyType": "O", |
| 329 |
"docType": "INV", |
| 330 |
"subSupplyType": "1", |
| 331 |
"transactionType": 1, |
| 332 |
"transDistance": "20", |
| 333 |
"docNo": "INV/18-19/0001", |
| 334 |
"docDate": "01/01/2019", |
| 335 |
"fromGstin": "24AAGCC7144L6ZE", |
| 336 |
"fromTrdName": "Default Company", |
| 337 |
"fromAddr1": "Khodiyar Chowk", |
| 338 |
"fromAddr2": "Sala Number 3", |
| 339 |
"fromPlace": "Amreli", |
| 340 |
"fromPincode": 365220, |
| 341 |
"fromStateCode": 24, |
| 342 |
"actFromStateCode": 24, |
| 343 |
"toGstin": "24ABCPM8965E1ZE", |
| 344 |
"toTrdName": "Partner Intra State", |
| 345 |
"toAddr1": "Karansinhji Rd", |
| 346 |
"toAddr2": "Karanpara", |
| 347 |
"toPlace": "Rajkot", |
| 348 |
"toPincode": 360001, |
| 349 |
"actToStateCode": 24, |
| 350 |
"toStateCode": 24, |
| 351 |
"itemList": [ |
| 352 |
{ |
| 353 |
"productName": "product_a", |
| 354 |
"hsnCode": "111111", |
| 355 |
"productDesc": "product_a", |
| 356 |
"quantity": 1.0, |
| 357 |
"qtyUnit": "UNT", |
| 358 |
"taxableAmount": 900.0, |
| 359 |
"cgstRate": 2.5, |
| 360 |
"sgstRate": 2.5 |
| 361 |
}, |
| 362 |
{ |
| 363 |
"productName": "product_with_cess", |
| 364 |
"hsnCode": "333333", |
| 365 |
"productDesc": "product_with_cess", |
| 366 |
"quantity": 1.0, |
| 367 |
"qtyUnit": "UNT", |
| 368 |
"taxableAmount": 900.0, |
| 369 |
"cgstRate": 6.0, |
| 370 |
"sgstRate": 6.0, |
| 371 |
"cessRate": 5.0 |
| 372 |
} |
| 373 |
], |
| 374 |
"totalValue": 1800.0, |
| 375 |
"cgstValue": 76.5, |
| 376 |
"sgstValue": 76.5, |
| 377 |
"igstValue": 0.0, |
| 378 |
"cessValue": 45.0, |
| 379 |
"cessNonAdvolValue": 1.59, |
| 380 |
"otherValue": 0.0, |
| 381 |
"totInvValue": 1999.59, |
| 382 |
"transMode": "1", |
| 383 |
"vehicleNo": "GJ11AA1234", |
| 384 |
"vehicleType": "R", |
| 385 |
"transporterName": self.partner_b.name, |
| 386 |
} |
| 387 |
json_value = ewaybill_invoice._ewaybill_generate_direct_json() |
| 388 |
self.assertDictEqual(json_value, expected, "Indian EDI Ewaybill without transporter GST sent json value is not matched") |
| 389 |
|
| 390 |
# ===================== Unregistered Transporter (No GSTIN) and vehicle number is not present ===================== |
| 391 |
ewaybill_invoice_2 = self.env['l10n.in.ewaybill'].create({ |
| 392 |
"type_id": self.env.ref("l10n_in_ewaybill.type_tax_invoice_sub_type_supply").id, |
| 393 |
"account_move_id": self.invoice.id, |
| 394 |
"distance": 20, |
| 395 |
"mode": "1", |
| 396 |
"transportation_doc_no": "123456789", |
| 397 |
"vehicle_type": "R", |
| 398 |
"transporter_id": self.partner_b.id, |
| 399 |
}) |
| 400 |
expected_msg = _('- Transporter %s does not have a valid GST Number', self.partner_b.name) |
| 401 |
self.assertEqual(ewaybill_invoice_2._check_transporter(), [expected_msg]) |