Debian Codegraph @

addons/l10n_gr_edi/models/account_move_send.py

raw symbols SCIP
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_gr_edi_applicable(self, move):
9 return move.l10n_gr_edi_enable_send_invoices
10
11 def _get_all_extra_edis(self) -> dict:
12 # EXTENDS 'account'
13 res = super()._get_all_extra_edis()
14 res['gr_edi'] = {'label': _("myDATA"), 'is_applicable': self._is_gr_edi_applicable}
15 return res
16
17 # -------------------------------------------------------------------------
18 # ALERTS
19 # -------------------------------------------------------------------------
20
21 def _get_alerts(self, moves, moves_data):
22 # EXTENDS 'account'
23 alerts = super()._get_alerts(moves, moves_data)
24 invoices_with_alert = moves.filtered('l10n_gr_edi_alerts')
25
26 if len(invoices_with_alert) == 1:
27 alerts = invoices_with_alert.l10n_gr_edi_alerts
28 elif len(invoices_with_alert) > 1:
29 alerts['l10n_gr_edi_not_ready_invoice'] = {
30 'message': _("The following invoice(s) are not ready to be sent to myDATA: \n%s",
31 '\n'.join(f"- {move.display_name}" for move in invoices_with_alert)),
32 'action_text': _("View Invoice(s)"),
33 'action': invoices_with_alert._get_records_action(name=_("Check Invoice(s)")),
34 }
35
36 return alerts
37
38 # -------------------------------------------------------------------------
39 # SENDING METHODS
40 # -------------------------------------------------------------------------
41
42 def _call_web_service_before_invoice_pdf_render(self, invoices_data):
43 # EXTENDS 'account'
44 super()._call_web_service_before_invoice_pdf_render(invoices_data)
45
46 invoices = self.env['account.move']
47 for invoice, invoice_data in invoices_data.items():
48 if 'gr_edi' in invoice_data['extra_edis']:
49 invoices |= invoice
50
51 # Send multiple invoice at once (if available) in one batch
52 if invoices:
53 invoices.l10n_gr_edi_try_send_invoices()
54
55 for invoice, invoice_data in invoices_data.items():
56 if invoice in invoices and invoice.l10n_gr_edi_state != 'invoice_sent':
57 invoice_data['error'] = {
58 'error_title': _("Error when sending invoice to myDATA"),
59 'errors': [invoice.l10n_gr_edi_document_ids.sorted()[0].message],
60 }