Debian Codegraph @

addons/l10n_sa_edi/wizard/l10n_sa_edi_otp_wizard.py

raw symbols SCIP
1 from odoo import fields, models, _, api
2 from odoo.exceptions import UserError
3
4
5 class L10n_Sa_EdiOtpWizard(models.TransientModel):
6 _name = 'l10n_sa_edi.otp.wizard'
7 _description = 'Request ZATCA OTP'
8
9 l10n_sa_renewal = fields.Boolean("PCSID Renewal",
10 help="Used to decide whether we should call the PCSID renewal API or the CCSID API",
11 default=False)
12 l10n_sa_otp = fields.Char("OTP", copy=False, help="OTP required to get a CCSID. Can only be acquired through "
13 "the Fatoora portal.")
14 journal_id = fields.Many2one('account.journal', default=lambda self: self.env.context.get('active_id'), required=True)
15
16 @api.model
17 def default_get(self, fields):
18 res = super().default_get(fields)
19 if self.env.company.l10n_sa_api_mode == 'sandbox':
20 res['l10n_sa_otp'] = '123456' if self.l10n_sa_renewal else '123345'
21 return res
22
23 def validate(self):
24 if not self.l10n_sa_otp:
25 raise UserError(_("Please provide an OTP to complete the onboarding process"))
26 if self.l10n_sa_renewal:
27 return self.journal_id._l10n_sa_get_production_CSID(self.l10n_sa_otp)
28 self.journal_id._l10n_sa_api_onboard_journal(self.l10n_sa_otp)