| 1 |
from odoo import _, api, models |
| 2 |
|
| 3 |
|
| 4 |
class AccountMoveSend(models.AbstractModel): |
| 5 |
_inherit = 'account.move.send' |
| 6 |
|
| 7 |
@api.model |
| 8 |
def _is_sa_edi_applicable(self, move): |
| 9 |
zatca_document = move.edi_document_ids.filtered(lambda d: d.edi_format_id.code == 'sa_zatca' and d.state == 'to_send') |
| 10 |
return move.country_code == 'SA' and move.move_type in ('out_invoice', 'out_refund') and zatca_document and move.state != 'draft' |
| 11 |
|
| 12 |
def _get_all_extra_edis(self) -> dict: |
| 13 |
# EXTENDS 'account' |
| 14 |
res = super()._get_all_extra_edis() |
| 15 |
res.update({'sa_edi': {'label': _("To ZATCA"), 'is_applicable': self._is_sa_edi_applicable}}) |
| 16 |
return res |
| 17 |
|
| 18 |
def _call_web_service_before_invoice_pdf_render(self, invoices_data): |
| 19 |
# EXTENDS 'account' |
| 20 |
super()._call_web_service_before_invoice_pdf_render(invoices_data) |
| 21 |
|
| 22 |
to_process = self.env['account.move'] |
| 23 |
for invoice, invoice_data in invoices_data.items(): |
| 24 |
if 'sa_edi' in invoice_data['extra_edis']: |
| 25 |
to_process |= invoice |
| 26 |
to_process.action_process_edi_web_services() |