| 1 |
|
| 2 |
|
| 3 |
import time |
| 4 |
|
| 5 |
from odoo import models, fields |
| 6 |
from odoo.exceptions import UserError |
| 7 |
from odoo.addons.l10n_hu_edi.models.l10n_hu_edi_connection import L10nHuEdiConnection |
| 8 |
|
| 9 |
|
| 10 |
class L10n_Hu_EdiCancellation(models.TransientModel): |
| 11 |
_name = 'l10n_hu_edi.cancellation' |
| 12 |
_description = 'Technical Annulment Wizard' |
| 13 |
|
| 14 |
invoice_id = fields.Many2one( |
| 15 |
comodel_name='account.move', |
| 16 |
string='Invoice to cancel', |
| 17 |
) |
| 18 |
code = fields.Selection( |
| 19 |
selection=[ |
| 20 |
('ERRATIC_DATA', 'ERRATIC_DATA - Erroneous data'), |
| 21 |
('ERRATIC_INVOICE_NUMBER', 'ERRATIC_INVOICE_NUMBER - Erroneous invoice number'), |
| 22 |
('ERRATIC_INVOICE_ISSUE_DATE', 'ERRATIC_INVOICE_ISSUE_DATE - Erroneous issue date'), |
| 23 |
], |
| 24 |
string='Annulment Code', |
| 25 |
required=True, |
| 26 |
) |
| 27 |
reason = fields.Char( |
| 28 |
string='Annulment Reason', |
| 29 |
required=True, |
| 30 |
) |
| 31 |
|
| 32 |
def button_request_cancel(self): |
| 33 |
with L10nHuEdiConnection(self.env) as connection: |
| 34 |
self.invoice_id._l10n_hu_edi_acquire_lock() |
| 35 |
self.invoice_id._l10n_hu_edi_request_cancel(connection, self.code, self.reason) |
| 36 |
|
| 37 |
if 'query_status' in self.invoice_id._l10n_hu_edi_get_valid_actions(): |
| 38 |
time.sleep(2) |
| 39 |
self.invoice_id._l10n_hu_edi_query_status(connection) |
| 40 |
|
| 41 |
formatted_message = self.env['account.move.send']._format_error_html(self.invoice_id.l10n_hu_edi_messages) |
| 42 |
self.invoice_id.message_post(body=formatted_message) |
| 43 |
|
| 44 |
if self.env['account.move.send']._can_commit(): |
| 45 |
self.env.cr.commit() |
| 46 |
|
| 47 |
if self.invoice_id.l10n_hu_edi_messages.get('blocking_level') == 'error': |
| 48 |
raise UserError(self.env['account.move.send']._format_error_text(self.invoice_id.l10n_hu_edi_messages)) |