| 1 |
from freezegun import freeze_time |
| 2 |
from odoo.addons.l10n_in.tests.common import L10nInTestInvoicingCommon |
| 3 |
from odoo.tests import tagged |
| 4 |
|
| 5 |
|
| 6 |
@tagged("post_install_l10n", "post_install", "-at_install") |
| 7 |
class TestEwaybillJson(L10nInTestInvoicingCommon): |
| 8 |
|
| 9 |
@classmethod |
| 10 |
def setUpClass(cls): |
| 11 |
super().setUpClass() |
| 12 |
cls.env.company.write({ |
| 13 |
"l10n_in_edi_feature": True |
| 14 |
}) |
| 15 |
cls.invoice_a = cls.init_invoice( |
| 16 |
"out_invoice", |
| 17 |
post=True, |
| 18 |
products=cls.product_a, |
| 19 |
partner=cls.partner_a |
| 20 |
) |
| 21 |
cls.invoice_b = cls.init_invoice( |
| 22 |
"out_invoice", |
| 23 |
post=True, |
| 24 |
products=cls.product_a, |
| 25 |
partner=cls.partner_foreign |
| 26 |
) |
| 27 |
cls.partner_foreign_address = cls.env['res.partner'].create({ |
| 28 |
'name': "Foreign Partner Port Address", |
| 29 |
'commercial_partner_id': cls.partner_foreign.id, |
| 30 |
'country_id': cls.country_in.id, |
| 31 |
'state_id': cls.state_in_gj.id, |
| 32 |
'street': "Post Box No. 1 Mundra", |
| 33 |
'city': "Kutch", |
| 34 |
'zip': "370421", |
| 35 |
}) |
| 36 |
attachment_a = cls.env['ir.attachment'].create({ |
| 37 |
'name': 'einvoice_a.json', |
| 38 |
'res_model': 'account.move', |
| 39 |
'res_id': cls.invoice_a.id, |
| 40 |
'raw': b'{"Irn": "1234567890"}', |
| 41 |
}) |
| 42 |
attachment_b = cls.env['ir.attachment'].create({ |
| 43 |
'name': 'einvoice_b.json', |
| 44 |
'res_model': 'account.move', |
| 45 |
'res_id': cls.invoice_b.id, |
| 46 |
'raw': b'{"Irn": "1234567890"}', |
| 47 |
}) |
| 48 |
cls.invoice_a.write({ |
| 49 |
"l10n_in_edi_status": "sent", |
| 50 |
"l10n_in_edi_attachment_id": attachment_a.id, |
| 51 |
}) |
| 52 |
cls.invoice_b.write({ |
| 53 |
"l10n_in_edi_status": "sent", |
| 54 |
"l10n_in_edi_attachment_id": attachment_b.id, |
| 55 |
}) |
| 56 |
cls.invoice_b.l10n_in_gst_treatment = 'overseas' |
| 57 |
|
| 58 |
def test_ewaybill_irn(self): |
| 59 |
ewaybill_a = self.env['l10n.in.ewaybill'].create({ |
| 60 |
'account_move_id': self.invoice_a.id, |
| 61 |
'distance': 20, |
| 62 |
'mode': "1", |
| 63 |
'vehicle_no': "GJ11AA1234", |
| 64 |
'vehicle_type': "R", |
| 65 |
}) |
| 66 |
ewaybill_b = self.env['l10n.in.ewaybill'].create({ |
| 67 |
'account_move_id': self.invoice_b.id, |
| 68 |
'distance': 20, |
| 69 |
'mode': "1", |
| 70 |
'vehicle_no': "GJ11AA1234", |
| 71 |
'vehicle_type': "R", |
| 72 |
}) |
| 73 |
ewaybill_b.write({ |
| 74 |
'partner_ship_to_id': self.partner_foreign_address.id, |
| 75 |
}) |
| 76 |
self.assertTrue(ewaybill_a.is_process_through_irn) |
| 77 |
self.assertTrue(ewaybill_b.is_process_through_irn) |
| 78 |
self.assertDictEqual( |
| 79 |
ewaybill_a._ewaybill_generate_irn_json(), |
| 80 |
{ |
| 81 |
'Irn': "1234567890", |
| 82 |
'Distance': '20', |
| 83 |
'TransMode': '1', |
| 84 |
'VehNo': 'GJ11AA1234', |
| 85 |
'VehType': 'R', |
| 86 |
'DispDtls': { |
| 87 |
'Addr1': 'Khodiyar Chowk', |
| 88 |
'Loc': 'Amreli', |
| 89 |
'Pin': 365220, |
| 90 |
'Stcd': '24', |
| 91 |
'Addr2': 'Sala Number 3', |
| 92 |
'Nm': 'Default Company' |
| 93 |
} |
| 94 |
} |
| 95 |
) |
| 96 |
self.assertDictEqual( |
| 97 |
ewaybill_b._ewaybill_generate_irn_json(), |
| 98 |
{ |
| 99 |
'Irn': "1234567890", |
| 100 |
'Distance': '20', |
| 101 |
'TransMode': '1', |
| 102 |
'VehNo': 'GJ11AA1234', |
| 103 |
'VehType': 'R', |
| 104 |
'DispDtls': { |
| 105 |
'Addr1': 'Khodiyar Chowk', |
| 106 |
'Loc': 'Amreli', |
| 107 |
'Pin': 365220, |
| 108 |
'Stcd': '24', |
| 109 |
'Addr2': 'Sala Number 3', |
| 110 |
'Nm': 'Default Company' |
| 111 |
}, |
| 112 |
'ExpShipDtls': { |
| 113 |
'Addr1': 'Post Box No. 1 Mundra', |
| 114 |
'Loc': 'Kutch', |
| 115 |
'Pin': 370421, |
| 116 |
'Stcd': '24' |
| 117 |
} |
| 118 |
} |
| 119 |
) |
| 120 |
|
| 121 |
|
| 122 |
self.partner_b.write({ |
| 123 |
'vat': False, |
| 124 |
'name': 'Atlas' |
| 125 |
}) |
| 126 |
ewaybill_a.transporter_id = self.partner_b |
| 127 |
self.assertDictEqual( |
| 128 |
ewaybill_a._ewaybill_generate_irn_json(), |
| 129 |
{ |
| 130 |
'Irn': '1234567890', |
| 131 |
'Distance': '20', |
| 132 |
'TransMode': '1', |
| 133 |
'TransName': 'Atlas', |
| 134 |
'VehNo': 'GJ11AA1234', |
| 135 |
'VehType': 'R', |
| 136 |
'DispDtls': { |
| 137 |
'Addr1': 'Khodiyar Chowk', |
| 138 |
'Loc': 'Amreli', |
| 139 |
'Pin': 365220, |
| 140 |
'Stcd': '24', |
| 141 |
'Addr2': 'Sala Number 3', |
| 142 |
'Nm': 'Default Company' |
| 143 |
} |
| 144 |
} |
| 145 |
) |