diff --git a/addons/l10n_it_edi_sdicoop/models/account_edi_format.py b/addons/l10n_it_edi_sdicoop/models/account_edi_format.py index 880eb484a8dda8baeb918e616a0fcc9b3c56796a..7f6412862aa411267071855372452035ab29d800 100644 --- a/addons/l10n_it_edi_sdicoop/models/account_edi_format.py +++ b/addons/l10n_it_edi_sdicoop/models/account_edi_format.py @@ -110,6 +110,13 @@ class AccountEdiFormat(models.Model): return super()._support_batching(move=move, state=state, company=company) + def _get_batch_key(self, move, state): + # OVERRIDE + if self.code != 'fattura_pa': + return super()._get_batch_key(move, state) + + return move.move_type, bool(move.l10n_it_edi_transaction) + def _l10n_it_post_invoices_step_1(self, invoices): ''' Send the invoices to the proxy. ''' @@ -209,6 +216,10 @@ class AccountEdiFormat(models.Model): to_return[invoice] = {'error': _('You are not allowed to check the status of this invoice.'), 'blocking_level': 'error'} continue + if not response.get('file'): # It means there is no status update, so we can skip it + document = invoice.edi_document_ids.filtered(lambda d: d.edi_format_id.code == 'fattura_pa') + to_return[invoice] = {'error': document.error, 'blocking_level': document.blocking_level} + continue xml = proxy_user._decrypt_data(response['file'], response['key']) response_tree = etree.fromstring(xml) if state == 'ricevutaConsegna': @@ -227,25 +238,26 @@ class AccountEdiFormat(models.Model): elif state == 'notificaEsito': outcome = response_tree.find('Esito').text if outcome == 'EC01': - to_return[invoice] = {'attachment': invoice.l10n_it_edi_attachment_id} + to_return[invoice] = {'attachment': invoice.l10n_it_edi_attachment_id, 'success': True} else: # ECO2 to_return[invoice] = {'error': _('The invoice was refused by the addressee.'), 'blocking_level': 'error'} elif state == 'NotificaDecorrenzaTermini': - to_return[invoice] = {'error': _('Expiration of the maximum term for communication of acceptance/refusal'), 'blocking_level': 'error'} + to_return[invoice] = {'attachment': invoice.l10n_it_edi_attachment_id, 'success': True} proxy_acks.append(id_transaction) - try: - proxy_user._make_request(server_url + '/api/l10n_it_edi/1/ack', - params={'transaction_ids': proxy_acks}) - except AccountEdiProxyError as e: - # Will be ignored and acked again next time. - _logger.error('Error while acking file to SdiCoop: %s', e) + if proxy_acks: + try: + proxy_user._make_request(server_url + '/api/l10n_it_edi/1/ack', + params={'transaction_ids': proxy_acks}) + except AccountEdiProxyError as e: + # Will be ignored and acked again next time. + _logger.error('Error while acking file to SdiCoop: %s', e) return to_return def _post_fattura_pa(self, invoices): # OVERRIDE - if not invoices.l10n_it_edi_transaction: + if not invoices[0].l10n_it_edi_transaction: return self._l10n_it_post_invoices_step_1(invoices) else: return self._l10n_it_post_invoices_step_2(invoices)