| 1 |
import pytz |
| 2 |
|
| 3 |
from odoo import api, fields, models |
| 4 |
|
| 5 |
from ..tools import _mer_api_reject_with_id, _mer_api_update_document_process_status |
| 6 |
|
| 7 |
|
| 8 |
class L10nHrMojEracunRejectInvoice(models.TransientModel): |
| 9 |
_name = 'l10n_hr_edi.mojeracun_reject_wizard' |
| 10 |
_description = "MojEracun Reject Invoice Wizard" |
| 11 |
|
| 12 |
move_id = fields.Many2one(comodel_name='account.move', required=True) |
| 13 |
rejection_type = fields.Selection( |
| 14 |
string="Rejection reason type", |
| 15 |
selection=[ |
| 16 |
('N', "'N' - Data discrepancy that does not affect tax calculation"), |
| 17 |
('U', "'U' - Data discrepancy that affects tax calculation"), |
| 18 |
('O', "'O' - Other"), |
| 19 |
], |
| 20 |
required=True |
| 21 |
) |
| 22 |
rejection_description = fields.Char(string="Rejection reason description", required=True) |
| 23 |
|
| 24 |
@api.model |
| 25 |
def default_get(self, fields_list): |
| 26 |
# EXTENDS 'base' |
| 27 |
results = super().default_get(fields_list) |
| 28 |
if 'move_id' in fields_list and 'move_id' not in results: |
| 29 |
move_id = self.env.context.get('active_ids', [])[0] |
| 30 |
results['move_id'] = move_id |
| 31 |
return results |
| 32 |
|
| 33 |
def button_reject_invoice(self): |
| 34 |
if self.move_id.l10n_hr_mer_document_eid: |
| 35 |
response = _mer_api_reject_with_id( |
| 36 |
self.move_id.company_id, |
| 37 |
self.move_id.l10n_hr_mer_document_eid, |
| 38 |
fields.Datetime.now(pytz.timezone('Europe/Zagreb')).strftime("%Y-%m-%dT%H:%M:%S"), |
| 39 |
self.rejection_type, |
| 40 |
self.rejection_description, |
| 41 |
) |
| 42 |
attachment = self.env["ir.attachment"].create( |
| 43 |
{ |
| 44 |
"name": f"mojeracun_{response['electronicId']}_rejection.xml", |
| 45 |
"raw": response['encodedXml'], |
| 46 |
"type": "binary", |
| 47 |
"mimetype": "application/xml", |
| 48 |
} |
| 49 |
) |
| 50 |
attachment.write({'res_model': 'account.move', 'res_id': self.move_id.id}) |
| 51 |
self.move_id._message_log( |
| 52 |
body=self.env._( |
| 53 |
"%(timestamp)s: eRacun document (ElectroicId: %(electronic_id)s) has been rejected successfully.", |
| 54 |
timestamp=response['fiscalizationTimestamp'], electronic_id=self.move_id.l10n_hr_mer_document_eid, |
| 55 |
), |
| 56 |
attachment_ids=attachment.ids, |
| 57 |
) |
| 58 |
self.move_id.l10n_hr_edi_addendum_id.business_document_status = '1' |
| 59 |
_mer_api_update_document_process_status( |
| 60 |
self.move_id.company_id, |
| 61 |
self.move_id.l10n_hr_mer_document_eid, |
| 62 |
'1', |
| 63 |
self.rejection_description, |
| 64 |
) |
| 65 |
self.move_id.button_cancel() |