| 1 |
from odoo import fields, models |
| 2 |
from odoo.exceptions import UserError |
| 3 |
|
| 4 |
|
| 5 |
class ResConfigSettings(models.TransientModel): |
| 6 |
_inherit = 'res.config.settings' |
| 7 |
|
| 8 |
# E-Invoice |
| 9 |
l10n_in_edi_feature = fields.Boolean( |
| 10 |
related='company_id.l10n_in_edi_feature', |
| 11 |
readonly=False |
| 12 |
) |
| 13 |
l10n_in_edi_username = fields.Char( |
| 14 |
"Indian EDI username", |
| 15 |
related="company_id.l10n_in_edi_username", |
| 16 |
readonly=False |
| 17 |
) |
| 18 |
l10n_in_edi_password = fields.Char( |
| 19 |
"Indian EDI password", |
| 20 |
related="company_id.l10n_in_edi_password", |
| 21 |
readonly=False |
| 22 |
) |
| 23 |
|
| 24 |
# E-Invoice Methods |
| 25 |
def l10n_in_edi_test(self): |
| 26 |
self._l10n_in_check_gst_number() |
| 27 |
response = self.company_id._l10n_in_edi_authenticate() |
| 28 |
_ = self.env._ |
| 29 |
if response.get('error'): |
| 30 |
raise UserError("\n".join(["[%s] %s" % (e.get('code'), (e.get('message'))) for e in response['error']])) |
| 31 |
elif not self.company_id.sudo()._l10n_in_edi_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 |
} |