| 1 |
|
| 2 |
|
| 3 |
from odoo import models, fields, _ |
| 4 |
from odoo.exceptions import UserError |
| 5 |
from odoo.tools import html_escape |
| 6 |
from odoo.addons.l10n_in_ewaybill.tools.ewaybill_api import EWayBillApi, EWayBillError |
| 7 |
|
| 8 |
|
| 9 |
class ResConfigSettings(models.TransientModel): |
| 10 |
_inherit = 'res.config.settings' |
| 11 |
|
| 12 |
l10n_in_ewaybill_username = fields.Char( |
| 13 |
"Indian Ewaybill username", |
| 14 |
related='company_id.l10n_in_ewaybill_username', |
| 15 |
readonly=False |
| 16 |
) |
| 17 |
l10n_in_ewaybill_password = fields.Char( |
| 18 |
"Indian Ewaybill password", |
| 19 |
related='company_id.l10n_in_ewaybill_password', |
| 20 |
readonly=False |
| 21 |
) |
| 22 |
l10n_in_ewaybill_feature = fields.Boolean(related='company_id.l10n_in_ewaybill_feature', readonly=False) |
| 23 |
|
| 24 |
def l10n_in_ewaybill_test(self): |
| 25 |
self._l10n_in_check_gst_number() |
| 26 |
ewaybill_api = EWayBillApi(self.company_id) |
| 27 |
try: |
| 28 |
ewaybill_api._ewaybill_authenticate() |
| 29 |
except EWayBillError as e: |
| 30 |
raise UserError(e.get_all_error_message()) |
| 31 |
if not self.company_id.sudo()._l10n_in_ewaybill_token_is_valid(): |
| 32 |
raise UserError(_("Incorrect username or password, or the GST number on company does not match.")) |
| 33 |
return { |
| 34 |
'type': 'ir.actions.client', |
| 35 |
'tag': 'display_notification', |
| 36 |
'params': { |
| 37 |
'type': 'info', |
| 38 |
'sticky': False, |
| 39 |
'message': _("API credentials validated successfully"), |
| 40 |
} |
| 41 |
} |