Debian Codegraph @

addons/l10n_in_edi/tests/test_edi_json.py

raw
1 from freezegun import freeze_time
2
3 from odoo import Command
4 from odoo.tests import tagged
5 from odoo.addons.l10n_in.tests.common import L10nInTestInvoicingCommon
6
7
8 @tagged("post_install_l10n", "post_install", "-at_install")
9 class TestEdiJson(L10nInTestInvoicingCommon):
10
11 @classmethod
12 def setUpClass(cls):
13 super().setUpClass()
14 cls.maxDiff = None
15
16 cls.partner_a.l10n_in_gst_treatment = "regular"
17
18 cls.product_a_discount = cls.env['product.product'].create({
19 'name': 'product_a discount',
20 'uom_id': cls.env.ref('uom.product_uom_unit').id,
21 'lst_price': 400.0,
22 'standard_price': 400.0,
23 'property_account_income_id': cls.company_data['default_account_revenue'].id,
24 'property_account_expense_id': cls.company_data['default_account_expense'].id,
25 'taxes_id': [Command.set(cls.sgst_sale_5.ids)],
26 'supplier_taxes_id': [Command.set(cls.sgst_purchase_5.ids)],
27 "l10n_in_hsn_code": "111111",
28 })
29 gst_with_cess = cls.env.ref("account.%s_sgst_sale_12" % (cls.company_data["company"].id)
30 ) + cls.env.ref("account.%s_cess_5_plus_1591_sale" % (cls.company_data["company"].id))
31 product_with_cess = cls.env["product.product"].create({
32 "name": "product_with_cess",
33 "uom_id": cls.env.ref("uom.product_uom_unit").id,
34 "lst_price": 1000.0,
35 "standard_price": 800.0,
36 "property_account_income_id": cls.company_data["default_account_revenue"].id,
37 "property_account_expense_id": cls.company_data["default_account_expense"].id,
38 "taxes_id": [Command.set(gst_with_cess.ids)],
39 "supplier_taxes_id": [Command.set(cls.sgst_purchase_5.ids)],
40 "l10n_in_hsn_code": "333333",
41 })
42 rounding = cls.env["account.cash.rounding"].create({
43 "name": "half-up",
44 "rounding": 1.0,
45 "strategy": "add_invoice_line",
46 "profit_account_id": cls.company_data['default_account_expense'].id,
47 "loss_account_id": cls.company_data['default_account_expense'].id,
48 "rounding_method": "HALF-UP",
49 })
50
51 cls.invoice = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_with_cess)
52 cls.invoice.write({
53 "invoice_line_ids": [(1, l_id, {"discount": 10}) for l_id in cls.invoice.invoice_line_ids.ids]})
54 cls.invoice.action_post()
55 with freeze_time('2023-12-25'):
56 cls.invoice_reverse = cls.invoice._reverse_moves()
57 cls.invoice_reverse.action_post()
58 cls.invoice_full_discount = cls.init_invoice("out_invoice", post=False, products=cls.product_a)
59 cls.invoice_full_discount.write({
60 "invoice_line_ids": [(1, l_id, {"discount": 100}) for l_id in cls.invoice_full_discount.invoice_line_ids.ids]})
61 cls.invoice_full_discount.action_post()
62 cls.invoice_zero_qty = cls.init_invoice("out_invoice", post=False, products=cls.product_a)
63 cls.invoice_zero_qty.write({
64 "invoice_line_ids": [(1, l_id, {"quantity": 0}) for l_id in cls.invoice_zero_qty.invoice_line_ids.ids]})
65 cls.invoice_zero_qty.action_post()
66 cls.invoice_negative_unit_price = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_a_discount + cls.product_with_cess)
67 cls.invoice_negative_unit_price.write({
68 "invoice_line_ids": [
69 (1, cls.invoice_negative_unit_price.invoice_line_ids[0].id, {"price_unit": 1000}),
70 (1, cls.invoice_negative_unit_price.invoice_line_ids[1].id, {"price_unit": -400}),
71 ]})
72 cls.invoice_negative_unit_price.action_post()
73 cls.invoice_negative_qty = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_a_discount + cls.product_with_cess)
74 cls.invoice_negative_qty.write({
75 "invoice_line_ids": [
76 (1, cls.invoice_negative_qty.invoice_line_ids[0].id, {"price_unit": 1000}),
77 (1, cls.invoice_negative_qty.invoice_line_ids[1].id, {"price_unit": 400, 'quantity': -1}),
78 ]})
79 cls.invoice_negative_qty.action_post()
80 cls.invoice_negative_unit_price_and_qty = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_a_discount + cls.product_with_cess)
81 cls.invoice_negative_unit_price_and_qty.write({
82 "invoice_line_ids": [
83 (1, cls.invoice_negative_unit_price_and_qty.invoice_line_ids[0].id, {"price_unit": -1000, 'quantity': -1}),
84 (1, cls.invoice_negative_unit_price_and_qty.invoice_line_ids[1].id, {"price_unit": -400}),
85 ]})
86 cls.invoice_negative_unit_price_and_qty.action_post()
87 cls.invoice_negative_with_discount = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_a_discount)
88 cls.invoice_negative_with_discount.write({
89 "invoice_line_ids": [
90 (1, cls.invoice_negative_with_discount.invoice_line_ids[0].id, {"price_unit": 2000, 'discount': 50}),
91 (1, cls.invoice_negative_with_discount.invoice_line_ids[1].id, {"price_unit": -400}),
92 ]})
93 cls.invoice_negative_with_discount.action_post()
94 cls.invoice_negative_more_than_max_line = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_b + cls.product_a_discount)
95 cls.invoice_negative_more_than_max_line.write({
96 "invoice_line_ids": [
97 (1, cls.invoice_negative_more_than_max_line.invoice_line_ids[0].id, {"price_unit": 2000, 'discount': 50}),
98 (1, cls.invoice_negative_more_than_max_line.invoice_line_ids[1].id, {"price_unit": 1000}),
99 (1, cls.invoice_negative_more_than_max_line.invoice_line_ids[2].id, {"price_unit": -1100}),
100 ]})
101 cls.invoice_negative_more_than_max_line.action_post()
102 cls.invoice_cash_rounding = cls.init_invoice("out_invoice", post=False, products=cls.product_a + cls.product_with_cess)
103 cls.invoice_cash_rounding.write({
104 "invoice_line_ids": [(1, l_id, {"discount": 10}) for l_id in cls.invoice_cash_rounding.invoice_line_ids.ids],
105 "invoice_cash_rounding_id": rounding.id,
106 })
107 cls.invoice_cash_rounding.action_post()
108 cls.invoice_with_intra_igst = cls.init_invoice(
109 "out_invoice", partner=cls.sez_partner, post=False, products=cls.product_a
110 )
111 igst_18 = cls.env['account.chart.template'].with_company(
112 cls.company_data["company"]).ref('igst_sale_18')
113 cls.invoice_with_intra_igst.write({
114 'invoice_line_ids': [
115 Command.update(line_id, {'tax_ids': [Command.clear(), Command.set(igst_18.ids)]})
116 for line_id in cls.invoice_with_intra_igst.invoice_line_ids.ids
117 ]
118 })
119 cls.invoice_with_intra_igst.action_post()
120 cls.overseas = cls.env['res.partner'].create({
121 'name': 'Overseas',
122 'vat': False,
123 'l10n_in_gst_treatment': 'overseas',
124 'street': 'Block no. 402',
125 'city': 'Some city',
126 'zip': '999999',
127 'country_id': cls.env.ref('base.us').id,
128 })
129 cls.invoice_with_export = cls.init_invoice(
130 "out_invoice", partner=cls.overseas, post=False, products=cls.product_a
131 )
132 cls.invoice_with_export.write({
133 'l10n_in_state_id': cls.env.ref('l10n_in.state_in_oc').id,
134 'invoice_line_ids': [
135 Command.update(line_id, {'tax_ids': [Command.clear(), Command.set(igst_18.ids)]})
136 for line_id in cls.invoice_with_export.invoice_line_ids.ids
137 ]
138 })
139 cls.invoice_with_export.action_post()
140 cls.invoice_global_discount = cls.init_invoice("out_invoice", post=False, products=cls.product_a)
141 cls.invoice_global_discount.write({
142 "invoice_line_ids": [(0, 0, {
143 "name": "Global Discount Line",
144 "price_unit": -100.0,
145 })]
146 })
147 cls.invoice_global_discount.action_post()
148
149 def test_edi_json(self):
150 # line1: 1000, 10% discount and a tax of 5%
151 # line2: 1000, 10% discount and 4 taxes: 5%, 1.591, 6% SGST 6% CGST, each one affecting the base:
152 # 900 * 1.05 = 945
153 # 945 + 1.591 ~= 946.59
154 # 946.59 * 0.06 = 56.80
155 # total tax: 160.19
156 expected = {
157 "Version": "1.1",
158 "TranDtls": {"TaxSch": "GST", "SupTyp": "B2B", "RegRev": "N", "IgstOnIntra": "N"},
159 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0001", "Dt": "01/01/2019"},
160 "SellerDtls": {
161 "Addr1": "Khodiyar Chowk",
162 "Loc": "Amreli",
163 "Pin": 365220,
164 "Stcd": "24",
165 "Addr2": "Sala Number 3",
166 "LglNm": "Default Company",
167 "GSTIN": "24AAGCC7144L6ZE"},
168 "BuyerDtls": {
169 "Addr1": "Karansinhji Rd",
170 "Loc": "Rajkot",
171 "Pin": 360001,
172 "Stcd": "24",
173 "Addr2": "Karanpara",
174 "POS": "24",
175 "LglNm": "Partner Intra State",
176 "GSTIN": "24ABCPM8965E1ZE"},
177 "ItemList": [
178 {
179 "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "111111", "Qty": 1.0,
180 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 100.0, "AssAmt": 900.0,
181 "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 22.5, "SgstAmt": 22.5, "CesRt": 0.0, "CesAmt": 0.0,
182 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
183 "OthChrg": 0.0, "TotItemVal": 945.0
184 },
185 {
186 "SlNo": "2", "PrdDesc": "product_with_cess", "IsServc": "N", "HsnCd": "333333", "Qty": 1.0,
187 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 100.0, "AssAmt": 900.0,
188 "GstRt": 12.0, "IgstAmt": 0.0, "CgstAmt": 54.0, "SgstAmt": 54.0, "CesRt": 5.0, "CesAmt": 45.0,
189 "CesNonAdvlAmt": 1.59, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
190 "OthChrg": 0.0, "TotItemVal": 1054.59
191 }
192 ],
193 "ValDtls": {
194 "AssVal": 1800.0, "CgstVal": 76.5, "SgstVal": 76.5, "IgstVal": 0.0, "CesVal": 46.59,
195 "StCesVal": 0.0, "Discount": 0.0, "RndOffAmt": 0.0, "TotInvVal": 1999.59
196 }
197 }
198 with self.subTest(scenario="Taxable Invoice"):
199 json_value = self.invoice._l10n_in_edi_generate_invoice_json()
200 self.assertDictEqual(json_value, expected, "Indian EDI send json value is not matched")
201 expected_copy_rounding = expected.copy()
202
203 # ================================== Credit Note ============================================
204 with self.subTest(scenario="Credit Note"):
205 credit_note_expected = expected.copy()
206 credit_note_expected['DocDtls'] = {"Typ": "CRN", "No": "RINV/23-24/0001", "Dt": "25/12/2023"}
207 self.assertDictEqual(
208 self.invoice_reverse._l10n_in_edi_generate_invoice_json(),
209 credit_note_expected,
210 "Indian E-invoice Credit note json value is not matched"
211 )
212
213 # =================================== Full discount test =====================================
214 with self.subTest(scenario="Full Discount Invoice"):
215 json_value = self.invoice_full_discount._l10n_in_edi_generate_invoice_json()
216 expected.update({
217 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0002", "Dt": "01/01/2019"},
218 "ItemList": [{
219 "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "111111", "Qty": 1.0,
220 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 1000.0, "AssAmt": 0.0,
221 "GstRt": 0.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0,
222 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
223 "OthChrg": 0.0, "TotItemVal": 0.0}],
224 "ValDtls": {"AssVal": 0.0, "CgstVal": 0.0, "SgstVal": 0.0, "IgstVal": 0.0, "CesVal": 0.0,
225 "StCesVal": 0.0, "Discount": 0.0, "RndOffAmt": 0.0, "TotInvVal": 0.0}
226 })
227 self.assertDictEqual(json_value, expected, "Indian EDI with 100% discount sent json value is not matched")
228
229 # =================================== Zero quantity test =============================================
230 with self.subTest(scenario="Zero Quantity Invoice"):
231 json_value = self.invoice_zero_qty._l10n_in_edi_generate_invoice_json()
232 expected.update({
233 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0003", "Dt": "01/01/2019"},
234 "ItemList": [{
235 "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "111111", "Qty": 0.0,
236 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 0.0, "Discount": 0.0, "AssAmt": 0.0,
237 "GstRt": 0.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0,
238 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
239 "OthChrg": 0.0, "TotItemVal": 0.0}],
240 })
241 self.assertDictEqual(json_value, expected, "Indian EDI with 0(zero) quantity sent json value is not matched")
242
243 # =================================== Negative unit price test =============================================
244 json_value = self.invoice_negative_unit_price._l10n_in_edi_generate_invoice_json()
245 with self.subTest(scenario="Negative Unit Price Invoice"):
246 expected.update({
247 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0004", "Dt": "01/01/2019"},
248 "ItemList": [
249 {
250 "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "111111", "Qty": 1.0,
251 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 400.0, "AssAmt": 600.0,
252 "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 15.0, "SgstAmt": 15.0, "CesRt": 0.0, "CesAmt": 0.0,
253 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
254 "OthChrg": 0.0, "TotItemVal": 630.0
255 },
256 {
257 "SlNo": "3", "PrdDesc": "product_with_cess", "IsServc": "N", "HsnCd": "333333", "Qty": 1.0,
258 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 0.0, "AssAmt": 1000.0,
259 "GstRt": 12.0, "IgstAmt": 0.0, "CgstAmt": 60.0, "SgstAmt": 60.0, "CesRt": 5.0, "CesAmt": 50.0,
260 "CesNonAdvlAmt": 1.59, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
261 "OthChrg": 0.0, "TotItemVal": 1171.59
262 }
263 ],
264 "ValDtls": {
265 "AssVal": 1600.0, "CgstVal": 75.0, "SgstVal": 75.0, "IgstVal": 0.0, "CesVal": 51.59,
266 "StCesVal": 0.0, "Discount": 0.0, "RndOffAmt": 0.0, "TotInvVal": 1801.59
267 },
268 })
269 self.assertDictEqual(json_value, expected, "Indian EDI with negative unit price sent json value is not matched")
270
271 with self.subTest(scenario="Negative quantity Invoice"):
272 expected.update({"DocDtls": {"Typ": "INV", "No": "INV/18-19/0005", "Dt": "01/01/2019"}})
273 json_value = self.invoice_negative_qty._l10n_in_edi_generate_invoice_json()
274 self.assertDictEqual(json_value, expected, "Indian EDI with negative quantity sent json value is not matched")
275
276 with self.subTest(scenario="Negative unit price and quantity Invoice"):
277 expected.update({"DocDtls": {"Typ": "INV", "No": "INV/18-19/0006", "Dt": "01/01/2019"}})
278 json_value = self.invoice_negative_unit_price_and_qty._l10n_in_edi_generate_invoice_json()
279 self.assertDictEqual(json_value, expected, "Indian EDI with negative unit price and quantity sent json value is not matched")
280
281 with self.subTest(scenario="Negative unit price with discount Invoice"):
282 expected.update({
283 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0007", "Dt": "01/01/2019"},
284 "ItemList": [{
285 "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "111111", "Qty": 1.0,
286 "Unit": "UNT", "UnitPrice": 2000.0, "TotAmt": 2000.0, "Discount": 1400.0, "AssAmt": 600.0,
287 "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 15.0, "SgstAmt": 15.0, "CesRt": 0.0, "CesAmt": 0.0,
288 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
289 "OthChrg": 0.0, "TotItemVal": 630.0
290 }],
291 "ValDtls": {
292 "AssVal": 600.0, "CgstVal": 15.0, "SgstVal": 15.0, "IgstVal": 0.0, "CesVal": 0.0,
293 "StCesVal": 0.0, "Discount": 0.0, "RndOffAmt": 0.0, "TotInvVal": 630.0
294 },
295 })
296 json_value = self.invoice_negative_with_discount._l10n_in_edi_generate_invoice_json()
297 self.assertDictEqual(json_value, expected, "Indian EDI with negative unit price and quantity sent json value is not matched")
298
299 with self.subTest(scenario="Negative value more than max line"):
300 expected.update({
301 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0008", "Dt": "01/01/2019"},
302 "ItemList": [{
303 "SlNo": "1", "PrdDesc": "product_a", "IsServc": "N", "HsnCd": "111111", "Qty": 1.0,
304 "Unit": "UNT", "UnitPrice": 2000.0, "TotAmt": 2000.0, "Discount": 2000.0, "AssAmt": 0.0,
305 "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 0.0, "SgstAmt": 0.0, "CesRt": 0.0, "CesAmt": 0.0,
306 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
307 "OthChrg": 0.0, "TotItemVal": 0.0
308 },
309 {
310 "SlNo": "2", "PrdDesc": "product_b", "IsServc": "N", "HsnCd": "111111", "Qty": 1.0,
311 "Unit": "UNT", "UnitPrice": 1000.0, "TotAmt": 1000.0, "Discount": 100.0, "AssAmt": 900.0,
312 "GstRt": 5.0, "IgstAmt": 0.0, "CgstAmt": 22.5, "SgstAmt": 22.5, "CesRt": 0.0, "CesAmt": 0.0,
313 "CesNonAdvlAmt": 0.0, "StateCesRt": 0.0, "StateCesAmt": 0.0, "StateCesNonAdvlAmt": 0.0,
314 "OthChrg": 0.0, "TotItemVal": 945.0
315 }],
316 "ValDtls": {
317 "AssVal": 900.0, "CgstVal": 22.5, "SgstVal": 22.5, "IgstVal": 0.0, "CesVal": 0.0,
318 "StCesVal": 0.0, "Discount": 0.0, "RndOffAmt": 0.0, "TotInvVal": 945.0
319 },
320 })
321 json_value = self.invoice_negative_more_than_max_line._l10n_in_edi_generate_invoice_json()
322 self.assertDictEqual(json_value, expected, "Indian EDI with negative value more than max line sent json value is not matched")
323
324 with self.subTest(scenario="Cash Rounding Invoice"):
325 json_value = self.invoice_cash_rounding._l10n_in_edi_generate_invoice_json()
326 expected_copy_rounding.update({
327 "DocDtls": {"Typ": "INV", "No": "INV/18-19/0009", "Dt": "01/01/2019"},
328 "ValDtls": {
329 "AssVal": 1800.0, "CgstVal": 76.5, "SgstVal": 76.5, "IgstVal": 0.0, "CesVal": 46.59,
330 "StCesVal": 0.0, "Discount": 0.0, "RndOffAmt": 0.41, "TotInvVal": 2000.00
331 }})
332 self.assertDictEqual(json_value, expected_copy_rounding, "Indian EDI with cash rounding sent json value is not matched")
333
334 with self.subTest(scenario="SEZ Intra IGST Invoice"):
335 json_value = self.invoice_with_intra_igst._l10n_in_edi_generate_invoice_json()
336 expected_with_intra_igst = {
337 'Version': '1.1',
338 'TranDtls': {'TaxSch': 'GST', 'SupTyp': 'SEZWP', 'RegRev': 'N', 'IgstOnIntra': 'N'},
339 'DocDtls': {'Typ': 'INV', 'No': 'INV/18-19/0010', 'Dt': '01/01/2019'},
340 'SellerDtls': expected['SellerDtls'],
341 'BuyerDtls': {
342 'Addr1': 'Block no. 402',
343 'Loc': 'Some city',
344 'Pin': 500002,
345 'Stcd': '24',
346 'POS': '24',
347 'LglNm': 'SEZ Partner',
348 'GSTIN': '36AAAAA1234AAZA'
349 },
350 'ItemList': [{
351 'SlNo': '1',
352 'PrdDesc': 'product_a',
353 'IsServc': 'N',
354 'HsnCd': '111111',
355 'Qty': 1.0,
356 'Unit': 'UNT',
357 'UnitPrice': 1000.0,
358 'TotAmt': 1000.0,
359 'Discount': 0.0,
360 'AssAmt': 1000.0,
361 'GstRt': 18.0,
362 'IgstAmt': 180.0,
363 'CgstAmt': 0.0,
364 'SgstAmt': 0.0,
365 'CesRt': 0.0,
366 'CesAmt': 0.0,
367 'CesNonAdvlAmt': 0.0,
368 'StateCesRt': 0.0,
369 'StateCesAmt': 0.0,
370 'StateCesNonAdvlAmt': 0.0,
371 'OthChrg': 0.0,
372 'TotItemVal': 1180.0
373 }],
374 'ValDtls': {
375 'AssVal': 1000.0,
376 'Discount': 0.0,
377 'CgstVal': 0.0,
378 'SgstVal': 0.0,
379 'IgstVal': 180.0,
380 'CesVal': 0.0,
381 'StCesVal': 0.0,
382 'RndOffAmt': 0.0,
383 'TotInvVal': 1180.0
384 }
385 }
386 self.assertDictEqual(
387 json_value,
388 expected_with_intra_igst,
389 "Indian EDI with Intra IGST sent json value is not matched"
390 )
391 with self.subTest(scenario="Overseas Export Invoice"):
392 json_value = self.invoice_with_export._l10n_in_edi_generate_invoice_json()
393 expected_with_overseas = expected_with_intra_igst.copy()
394 expected_with_overseas.update({
395 'TranDtls': {'TaxSch': 'GST', 'SupTyp': 'EXPWP', 'RegRev': 'N', 'IgstOnIntra': 'N'},
396 'BuyerDtls': {
397 'Addr1': 'Block no. 402',
398 'Loc': 'Some city',
399 'Pin': 999999,
400 'Stcd': '96',
401 'POS': '96',
402 'LglNm': 'Overseas',
403 'GSTIN': 'URP'
404 },
405 'DocDtls': {'Dt': '01/01/2019', 'No': 'INV/18-19/0011', 'Typ': 'INV'},
406 'ExpDtls': {'CntCode': 'US', 'ForCur': 'INR', 'RefClm': 'Y'}
407 })
408 self.assertDictEqual(
409 json_value,
410 expected_with_overseas,
411 "Indian EDI with Overseas sent json value is not matched"
412 )
413
414 # =================================== RCM Tax test =============================================
415 with self.subTest(scenario="RCM Tax Invoice"):
416 json_value = self.invoice_with_rcm._l10n_in_edi_generate_invoice_json()
417 self.assertEqual(
418 json_value['TranDtls'],
419 {
420 "TaxSch": "GST",
421 "SupTyp": "B2B",
422 "RegRev": "Y",
423 "IgstOnIntra": "N"
424 },
425 "Indian EDI with RCM tax TranDtls json value is not matched"
426 )
427 self.assertDictEqual(
428 json_value['ItemList'][0],
429 {
430 "SlNo": "1",
431 "PrdDesc": "product_a",
432 "IsServc": "N",
433 "HsnCd": "111111",
434 "Qty": 1.0,
435 "Unit": "UNT",
436 "UnitPrice": 1000.0,
437 "TotAmt": 1000.0,
438 "Discount": 0.0,
439 "AssAmt": 1000.0,
440 "GstRt": 18.0,
441 "IgstAmt": 180.0,
442 "CgstAmt": 0.0,
443 "SgstAmt": 0.0,
444 "CesRt": 0.0,
445 "CesAmt": 0.0,
446 "CesNonAdvlAmt": 0.0,
447 "StateCesRt": 0.0,
448 "StateCesAmt": 0.0,
449 "StateCesNonAdvlAmt": 0.0,
450 "OthChrg": 0.0,
451 "TotItemVal": 1000.0
452 },
453 "Indian EDI with RCM tax ItemList json value is not matched"
454 )
455 self.assertDictEqual(
456 json_value['ValDtls'],
457 {
458 "AssVal": 1000.0,
459 "CgstVal": 0.0,
460 "SgstVal": 0.0,
461 "IgstVal": 180.0,
462 "CesVal": 0.0,
463 "StCesVal": 0.0,
464 "Discount": 0.0,
465 "RndOffAmt": 0.0,
466 "TotInvVal": 1000.0
467 },
468 "Indian EDI with RCM tax ValDtls json value is not matched"
469 )
470
471 # =================================== SEZ LUT Tax test =============================================
472 with self.subTest(scenario="SEZ LUT Tax Invoice"):
473 json_value = self.invoice_with_sez_lut._l10n_in_edi_generate_invoice_json()
474 self.assertEqual(
475 json_value['TranDtls'],
476 {
477 "TaxSch": "GST",
478 "SupTyp": "SEZWOP",
479 "RegRev": "N",
480 "IgstOnIntra": "N"
481 },
482 "Indian EDI with SEZ LUT tax TranDtls json value is not matched"
483 )
484 self.assertDictEqual(
485 json_value['ItemList'][0],
486 {
487 "SlNo": "1",
488 "PrdDesc": "product_a",
489 "IsServc": "N",
490 "HsnCd": "111111",
491 "Qty": 1.0,
492 "Unit": "UNT",
493 "UnitPrice": 1000.0,
494 "TotAmt": 1000.0,
495 "Discount": 0.0,
496 "AssAmt": 1000.0,
497 "GstRt": 18.0,
498 "IgstAmt": 0.0,
499 "CgstAmt": 0.0,
500 "SgstAmt": 0.0,
501 "CesRt": 0.0,
502 "CesAmt": 0.0,
503 "CesNonAdvlAmt": 0.0,
504 "StateCesRt": 0.0,
505 "StateCesAmt": 0.0,
506 "StateCesNonAdvlAmt": 0.0,
507 "OthChrg": 0.0,
508 "TotItemVal": 1000.0
509 },
510 "Indian EDI with SEZ LUT tax ItemList json value is not matched"
511 )
512 self.assertDictEqual(
513 json_value['ValDtls'],
514 {
515 "AssVal": 1000.0,
516 "CgstVal": 0.0,
517 "SgstVal": 0.0,
518 "IgstVal": 0.0,
519 "CesVal": 0.0,
520 "StCesVal": 0.0,
521 "Discount": 0.0,
522 "RndOffAmt": 0.0,
523 "TotInvVal": 1000.0
524 },
525 "Indian EDI with SEZ LUT tax ValDtls json value is not matched"
526 )
527
528 # =================================== SEZ without LUT Tax test =============================================
529 with self.subTest(scenario="SEZ Tax Invoice"):
530 json_value = self.invoice_with_sez_without_lut._l10n_in_edi_generate_invoice_json()
531 self.assertEqual(
532 json_value['TranDtls'],
533 {
534 "TaxSch": "GST",
535 "SupTyp": "SEZWP",
536 "RegRev": "N",
537 "IgstOnIntra": "N"
538 },
539 "Indian EDI without SEZ LUT tax TranDtls json value is not matched"
540 )
541 self.assertDictEqual(
542 json_value['ItemList'][0],
543 {
544 "SlNo": "1",
545 "PrdDesc": "product_a",
546 "IsServc": "N",
547 "HsnCd": "111111",
548 "Qty": 1.0,
549 "Unit": "UNT",
550 "UnitPrice": 1000.0,
551 "TotAmt": 1000.0,
552 "Discount": 0.0,
553 "AssAmt": 1000.0,
554 "GstRt": 18.0,
555 "IgstAmt": 180.0,
556 "CgstAmt": 0.0,
557 "SgstAmt": 0.0,
558 "CesRt": 0.0,
559 "CesAmt": 0.0,
560 "CesNonAdvlAmt": 0.0,
561 "StateCesRt": 0.0,
562 "StateCesAmt": 0.0,
563 "StateCesNonAdvlAmt": 0.0,
564 "OthChrg": 0.0,
565 "TotItemVal": 1180.0
566 },
567 "Indian EDI without SEZ LUT tax ItemList json value is not matched"
568 )
569 self.assertDictEqual(
570 json_value['ValDtls'],
571 {
572 "AssVal": 1000.0,
573 "CgstVal": 0.0,
574 "SgstVal": 0.0,
575 "IgstVal": 180.0,
576 "CesVal": 0.0,
577 "StCesVal": 0.0,
578 "Discount": 0.0,
579 "RndOffAmt": 0.0,
580 "TotInvVal": 1180.0
581 },
582 "Indian EDI with SEZ without LUT tax ValDtls json value is not matched"
583 )
584 # =================================== Export LUT Tax test =============================================
585 with self.subTest(scenario="Export LUT Tax Invoice"):
586 self.assertEqual(
587 self.invoice_with_export_lut._l10n_in_edi_generate_invoice_json(),
588 {
589 'Version': '1.1',
590 'TranDtls': {
591 'TaxSch': 'GST',
592 'SupTyp': 'EXPWOP',
593 'RegRev': 'N',
594 'IgstOnIntra': 'N'
595 },
596 'DocDtls': {
597 'Typ': 'INV',
598 'No': False,
599 'Dt': '01/01/2019'
600 },
601 'SellerDtls': {
602 'Addr1': 'Khodiyar Chowk',
603 'Loc': 'Amreli',
604 'Pin': 365220,
605 'Stcd': '24',
606 'Addr2': 'Sala Number 3',
607 'LglNm': 'Default Company',
608 'GSTIN': '24AAGCC7144L6ZE'
609 },
610 'BuyerDtls': {
611 'Addr1': '351 Horner Chapel Rd',
612 'Loc': 'Peebles',
613 'Pin': 999999,
614 'Stcd': '96',
615 'POS': '96',
616 'LglNm': 'Foreign Partner',
617 'GSTIN': 'URP'
618 },
619 'ItemList': [
620 {
621 'SlNo': '1',
622 'PrdDesc': 'product_a',
623 'IsServc': 'N',
624 'HsnCd': '111111',
625 'Qty': 1.0,
626 'Unit': 'UNT',
627 'UnitPrice': 1000.0,
628 'TotAmt': 1000.0,
629 'Discount': 0.0,
630 'AssAmt': 1000.0,
631 'GstRt': 18.0,
632 'IgstAmt': 0.0,
633 'CgstAmt': 0.0,
634 'SgstAmt': 0.0,
635 'CesRt': 0.0,
636 'CesAmt': 0.0,
637 'CesNonAdvlAmt': 0.0,
638 'StateCesRt': 0.0,
639 'StateCesAmt': 0.0,
640 'StateCesNonAdvlAmt': 0.0,
641 'OthChrg': 0.0,
642 'TotItemVal': 1000.0
643 }
644 ],
645 'ValDtls': {
646 'AssVal': 1000.0,
647 'CgstVal': 0.0,
648 'SgstVal': 0.0,
649 'IgstVal': 0.0,
650 'CesVal': 0.0,
651 'StCesVal': 0.0,
652 'Discount': 0.0,
653 'RndOffAmt': 0.0,
654 'TotInvVal': 1000.0
655 },
656 'ExpDtls': {
657 'RefClm': 'N',
658 'ForCur': 'INR',
659 'CntCode': 'US'
660 }
661 }
662 )
663
664 # =================================== Export without LUT Tax test =============================================
665 with self.subTest(scenario="Export Tax Invoice"):
666 self.assertEqual(
667 self.invoice_with_export_without_lut._l10n_in_edi_generate_invoice_json(),
668 {
669 'Version': '1.1',
670 'TranDtls': {
671 'TaxSch': 'GST',
672 'SupTyp': 'EXPWP',
673 'RegRev': 'N',
674 'IgstOnIntra': 'N'
675 },
676 'DocDtls': {
677 'Typ': 'INV',
678 'No': False,
679 'Dt': '01/01/2019'
680 },
681 'SellerDtls': {
682 'Addr1': 'Khodiyar Chowk',
683 'Loc': 'Amreli',
684 'Pin': 365220,
685 'Stcd': '24',
686 'Addr2': 'Sala Number 3',
687 'LglNm': 'Default Company',
688 'GSTIN': '24AAGCC7144L6ZE'
689 },
690 'BuyerDtls': {
691 'Addr1': '351 Horner Chapel Rd',
692 'Loc': 'Peebles',
693 'Pin': 999999,
694 'Stcd': '96',
695 'POS': '96',
696 'LglNm': 'Foreign Partner',
697 'GSTIN': 'URP'
698 },
699 'ItemList': [
700 {
701 'SlNo': '1',
702 'PrdDesc': 'product_a',
703 'IsServc': 'N',
704 'HsnCd': '111111',
705 'Qty': 1.0,
706 'Unit': 'UNT',
707 'UnitPrice': 1000.0,
708 'TotAmt': 1000.0,
709 'Discount': 0.0,
710 'AssAmt': 1000.0,
711 'GstRt': 18.0,
712 'IgstAmt': 180.0,
713 'CgstAmt': 0.0,
714 'SgstAmt': 0.0,
715 'CesRt': 0.0,
716 'CesAmt': 0.0,
717 'CesNonAdvlAmt': 0.0,
718 'StateCesRt': 0.0,
719 'StateCesAmt': 0.0,
720 'StateCesNonAdvlAmt': 0.0,
721 'OthChrg': 0.0,
722 'TotItemVal': 1180.0
723 }
724 ],
725 'ValDtls': {
726 'AssVal': 1000.0,
727 'CgstVal': 0.0,
728 'SgstVal': 0.0,
729 'IgstVal': 180.0,
730 'CesVal': 0.0,
731 'StCesVal': 0.0,
732 'Discount': 0.0,
733 'RndOffAmt': 0.0,
734 'TotInvVal': 1180.0
735 },
736 'ExpDtls': {
737 'RefClm': 'Y',
738 'ForCur': 'INR',
739 'CntCode': 'US'
740 }
741 }
742 )
743
744 # ==================================== Global Discount Line Test ==============================================
745 with self.subTest(scenario="Global Discount Line"):
746 self.assertDictEqual(
747 self.invoice_global_discount._l10n_in_edi_generate_invoice_json(),
748 {
749 'Version': '1.1',
750 'TranDtls': {
751 'TaxSch': 'GST',
752 'SupTyp': 'B2B',
753 'RegRev': 'N',
754 'IgstOnIntra': 'N'
755 },
756 'DocDtls': {
757 'Typ': 'INV',
758 'No': 'INV/18-19/0012',
759 'Dt': '01/01/2019'
760 },
761 'SellerDtls': {
762 'Addr1': 'Khodiyar Chowk',
763 'Loc': 'Amreli',
764 'Pin': 365220,
765 'Stcd': '24',
766 'Addr2': 'Sala Number 3',
767 'LglNm': 'Default Company',
768 'GSTIN': '24AAGCC7144L6ZE'
769 },
770 'BuyerDtls': {
771 'Addr1': 'Karansinhji Rd',
772 'Loc': 'Rajkot',
773 'Pin': 360001,
774 'Stcd': '24',
775 'Addr2': 'Karanpara',
776 'POS': '24',
777 'LglNm': 'Partner Intra State',
778 'GSTIN': '24ABCPM8965E1ZE'
779 },
780 'ItemList': [
781 {
782 'SlNo': '1',
783 'PrdDesc': 'product_a',
784 'IsServc': 'N',
785 'HsnCd': '111111',
786 'Qty': 1.0,
787 'Unit': 'UNT',
788 'UnitPrice': 1000.0,
789 'TotAmt': 1000.0,
790 'Discount': 0.0,
791 'AssAmt': 1000.0,
792 'GstRt': 5.0,
793 'IgstAmt': 0.0,
794 'CgstAmt': 25.0,
795 'SgstAmt': 25.0,
796 'CesRt': 0.0,
797 'CesAmt': 0.0,
798 'CesNonAdvlAmt': 0.0,
799 'StateCesRt': 0.0,
800 'StateCesAmt': 0.0,
801 'StateCesNonAdvlAmt': 0.0,
802 'OthChrg': 0.0,
803 'TotItemVal': 1050.0
804 }
805 ],
806 'ValDtls': {
807 'AssVal': 1000.0,
808 'CgstVal': 25.0,
809 'SgstVal': 25.0,
810 'IgstVal': 0.0,
811 'CesVal': 0.0,
812 'StCesVal': 0.0,
813 'Discount': 100.0,
814 'RndOffAmt': 0.0,
815 'TotInvVal': 950.0
816 }
817 },
818 "Indian EDI with global discount did not match"
819 )
820
821 # =================================== Export without LUT Tax test =============================================
822 with self.subTest(scenario="Export Tax Invoice Without LUT and Include Tax"):
823 self.assertEqual(
824 self.invoice_with_export_without_lut_inc._l10n_in_edi_generate_invoice_json(),
825 {
826 'Version': '1.1',
827 'TranDtls': {
828 'TaxSch': 'GST',
829 'SupTyp': 'EXPWP',
830 'RegRev': 'N',
831 'IgstOnIntra': 'N'
832 },
833 'DocDtls': {
834 'Typ': 'INV',
835 'No': False,
836 'Dt': '01/01/2019'
837 },
838 'SellerDtls': {
839 'Addr1': 'Khodiyar Chowk',
840 'Loc': 'Amreli',
841 'Pin': 365220,
842 'Stcd': '24',
843 'Addr2': 'Sala Number 3',
844 'LglNm': 'Default Company',
845 'GSTIN': '24AAGCC7144L6ZE'
846 },
847 'BuyerDtls': {
848 'Addr1': '351 Horner Chapel Rd',
849 'Loc': 'Peebles',
850 'Pin': 999999,
851 'Stcd': '96',
852 'POS': '96',
853 'LglNm': 'Foreign Partner',
854 'GSTIN': 'URP'
855 },
856 'ItemList': [
857 {
858 'SlNo': '1',
859 'PrdDesc': 'product_a',
860 'IsServc': 'N',
861 'HsnCd': '111111',
862 'Qty': 1.0,
863 'Unit': 'UNT',
864 'UnitPrice': 1000.00,
865 'TotAmt': 1000.00,
866 'Discount': 0.0,
867 'AssAmt': 1000.00,
868 'GstRt': 18.0,
869 'IgstAmt': 180.0,
870 'CgstAmt': 0.0,
871 'SgstAmt': 0.0,
872 'CesRt': 0.0,
873 'CesAmt': 0.0,
874 'CesNonAdvlAmt': 0.0,
875 'StateCesRt': 0.0,
876 'StateCesAmt': 0.0,
877 'StateCesNonAdvlAmt': 0.0,
878 'OthChrg': 0.0,
879 'TotItemVal': 1180.0
880 }
881 ],
882 'ValDtls': {
883 'AssVal': 1000.0,
884 'CgstVal': 0.0,
885 'SgstVal': 0.0,
886 'IgstVal': 180.0,
887 'CesVal': 0.0,
888 'StCesVal': 0.0,
889 'Discount': 0.0,
890 'RndOffAmt': 0.0,
891 'TotInvVal': 1180.0
892 },
893 'ExpDtls': {
894 'RefClm': 'Y',
895 'ForCur': 'INR',
896 'CntCode': 'US'
897 }
898 }
899 )