Debian Codegraph @

addons/l10n_in_edi/models/account_move_send.py

raw
1 from odoo import api, fields, models
2
3
4 class AccountMoveSend(models.AbstractModel):
5 _inherit = 'account.move.send'
6
7 @api.model
8 def _is_in_edi_applicable(self, move):
9 return (
10 move._l10n_in_check_einvoice_eligible()
11 and move.state == 'posted'
12 and move.l10n_in_edi_status != 'sent'
13 )
14
15 def _get_all_extra_edis(self) -> dict:
16 # EXTENDS 'account'
17 res = super()._get_all_extra_edis()
18 res.update({
19 'in_edi_send': {
20 'label': self.env._("E-invoicing"),
21 'is_applicable': self._is_in_edi_applicable,
22 'help': self.env._(
23 "Send the e-invoice json to the Indian Invoice Registration Portal (IRP)."
24 )
25 }
26 })
27 return res
28
29 # -------------------------------------------------------------------------
30 # ALERTS
31 # -------------------------------------------------------------------------
32
33 def _get_alerts(self, moves, moves_data):
34 # EXTENDS 'account'
35 alerts = super()._get_alerts(moves, moves_data)
36 if in_moves := moves.filtered(lambda m: 'in_edi_send' in moves_data[m]['extra_edis']):
37 if in_alerts := in_moves._l10n_in_check_einvoice_validation():
38 alerts.update(in_alerts)
39 return alerts
40
41 # -------------------------------------------------------------------------
42 # SENDING METHODS
43 # -------------------------------------------------------------------------
44
45 def _get_invoice_extra_attachments(self, invoice):
46 # EXTENDS 'account'
47 return super()._get_invoice_extra_attachments(invoice) + invoice.l10n_in_edi_attachment_id
48
49 def _call_web_service_before_invoice_pdf_render(self, invoices_data):
50 # EXTENDS 'account'
51 super()._call_web_service_before_invoice_pdf_render(invoices_data)
52 for invoice, invoice_data in invoices_data.items():
53 if 'in_edi_send' in invoice_data['extra_edis']:
54 if error := invoice._l10n_in_edi_send_invoice():
55 invoice_data['error'] = {
56 'error_title': self.env._(
57 "Error when sending the invoice to government:"
58 ),
59 'errors': error['messages'],
60 'retry': error.get('is_warning'),
61 }
62 elif invoice.invoice_pdf_report_id:
63 invoice.write({'invoice_pdf_report_file': False})
64 if self._can_commit():
65 self.env.cr.commit()