Skip to content

Commit

Permalink
[FIX] l10n_it_edi_sdicoop: if to the PA, it should be changed to sent
Browse files Browse the repository at this point in the history
First thing is that when you send an invoice to PA in test/production,
it should be considered as sent after the xml is generated as we do not
have the functionality to send sign invoices yet.

We added a test for posting the invoice when the invoice partner has a
l10n_it_pa_index (and it is of length 6).

Alos, when the proxy user is a 'demo' user, creates a
traceback. The solution is to only add the demo response to those that
would have been sent to the iap server otherwise.

We also avoid doing a call to the IAP server if there are no invoices to be
sent (e.g. because they all go to the PA)

opw-2807213

closes odoo#91410

X-original-commit: 2221f01
Signed-off-by: William André (wan) <wan@odoo.com>
  • Loading branch information
jco-odoo committed May 15, 2022
1 parent b2cdaf7 commit 38d8086
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions addons/l10n_it_edi_sdicoop/models/account_edi_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _l10n_it_post_invoices_step_1(self, invoices):
invoice.message_post(
body=(_("Invoices for PA are not managed by Odoo, you can download the document and send it on your own."))
)
to_return[invoice] = {'attachment': attachment}
to_return[invoice] = {'attachment': attachment, 'success': True}
else:
to_send[filename] = {
'invoice': invoice,
Expand All @@ -163,8 +163,9 @@ def _l10n_it_post_invoices_step_1(self, invoices):
'error': _("You must accept the terms and conditions in the settings to use FatturaPA."),
'blocking_level': 'error'} for invoice in invoices}

responses = {}
if proxy_user._get_demo_state() == 'demo':
responses = {filename: {'id_transaction': 'demo'} for invoice in invoices}
responses = {i['data']['filename']: {'id_transaction': 'demo'} for i in to_send.values()}
else:
try:
responses = self._l10n_it_edi_upload([i['data'] for i in to_send.values()], proxy_user)
Expand Down Expand Up @@ -336,6 +337,9 @@ def _l10n_it_edi_upload(self, files, proxy_user):
'EI03': {'error': _lt('Unauthorized user'), 'blocking_level': 'error'},
}

if not files:
return {}

result = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/out/SdiRiceviFile', params={'files': files})

# Translate the errors.
Expand Down
27 changes: 27 additions & 0 deletions addons/l10n_it_edi_sdicoop/tests/test_edi_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def setUpClass(cls):
'is_company': True,
})

cls.italian_partner_b = cls.env['res.partner'].create({
'name': 'pa partner',
'vat': 'IT06655971007',
'l10n_it_codice_fiscale': '06655971007',
'l10n_it_pa_index': '123456',
'country_id': cls.env.ref('base.it').id,
'street': 'Via Test PA',
'zip': '32121',
'city': 'PA Town',
'is_company': True
})

cls.italian_partner_no_address_codice = cls.env['res.partner'].create({
'name': 'Alessi',
'l10n_it_codice_fiscale': '00465840031',
Expand Down Expand Up @@ -230,6 +242,16 @@ def setUpClass(cls):
],
})

cls.pa_partner_invoice = cls.env['account.move'].with_company(cls.company).create({
'move_type': 'out_invoice',
'invoice_date': datetime.date(2022, 3, 24),
'partner_id': cls.italian_partner_b.id,
'partner_bank_id': cls.test_bank.id,
'invoice_line_ids': [
(0, 0, cls.standard_line),
],
})

# We create this because we are unable to post without a proxy user existing
cls.proxy_user = cls.env['account_edi_proxy_client.user'].create({
'id_client': 'l10n_it_edi_sdicoop_test',
Expand All @@ -246,6 +268,7 @@ def setUpClass(cls):
cls.non_latin_and_latin_invoice._post()
cls.below_400_codice_simplified_invoice._post()
cls.total_400_VAT_simplified_invoice._post()
cls.pa_partner_invoice._post()

cls.edi_basis_xml = cls._get_test_file_content('IT00470550013_basis.xml')
cls.edi_simplified_basis_xml = cls._get_test_file_content('IT00470550013_simpl.xml')
Expand Down Expand Up @@ -533,3 +556,7 @@ def test_more_400_simplified_invoice(self):
def test_non_domestic_simplified_invoice(self):
with self.assertRaises(UserError):
self.non_domestic_simplified_invoice._post()

def test_send_pa_partner(self):
res = self.edi_format._l10n_it_post_invoices_step_1(self.pa_partner_invoice)
self.assertEqual(res[self.pa_partner_invoice], {'attachment': self.pa_partner_invoice.l10n_it_edi_attachment_id, 'success': True})

0 comments on commit 38d8086

Please sign in to comment.