[FIX] l10n_it_edi_sdicoop: if to the PA, it should be changed to sent
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/odoo#91419 X-original-commit: 2221f0145607e4cd0880e7435b637f620d15cecf Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -150,7 +150,7 @@ class AccountEdiFormat(models.Model):
|
||||
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,
|
||||
@@ -163,8 +163,9 @@ class AccountEdiFormat(models.Model):
|
||||
'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)
|
||||
@@ -336,6 +337,9 @@ class AccountEdiFormat(models.Model):
|
||||
'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.
|
||||
|
||||
@@ -59,6 +59,18 @@ class TestItEdi(AccountEdiTestCommon):
|
||||
'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',
|
||||
@@ -230,6 +242,16 @@ class TestItEdi(AccountEdiTestCommon):
|
||||
],
|
||||
})
|
||||
|
||||
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',
|
||||
@@ -246,6 +268,7 @@ class TestItEdi(AccountEdiTestCommon):
|
||||
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')
|
||||
@@ -533,3 +556,7 @@ class TestItEdi(AccountEdiTestCommon):
|
||||
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})
|
||||
|
||||
Reference in New Issue
Block a user