[FIX] account_edi_proxy_client, l10n_it_edi_sdicoop: do not make request in demo mode
When demo data is installed, requests to the proxy are blocked and we simulate a successful result by default and the proxy. - an account_edi_proxy_client.user is created even though it's counterpart on the proxy doesn't exist. - sending invoices is successfull and checking the status return simulate the invoice was accepted. - the cron checking for incoming invoice returns immediatly and no new invoice is created. closes odoo/odoo#72092 X-original-commit: 7be2e136c5e7a62d440f8323f36076d486976825 Signed-off-by: Josse Colpaert <jco@openerp.com> Signed-off-by: bfr-o <bfr-o@users.noreply.github.com>
This commit is contained in:
@@ -18,6 +18,9 @@ Odoo database.
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'demo': [
|
||||
'data/config_demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="account_edi_proxy_client_demo" model="ir.config_parameter">
|
||||
<field name="key">account_edi_proxy_client.demo</field>
|
||||
<field name="value">True</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -64,6 +64,10 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
'id': uuid.uuid4().hex,
|
||||
}
|
||||
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
# Last barrier : in case the demo mode is not handled by the caller, we block access.
|
||||
raise Exception("Can't access the proxy in demo mode")
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
url,
|
||||
@@ -120,19 +124,22 @@ class AccountEdiProxyClientUser(models.Model):
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||
)
|
||||
|
||||
try:
|
||||
response = self._make_request(SERVER_URL + '/iap/account_edi/1/create_user', params={
|
||||
'dbuuid': company.env['ir.config_parameter'].get_param('database.uuid'),
|
||||
'company_id': company.id,
|
||||
'edi_format_code': edi_format.code,
|
||||
'edi_identification': edi_identification,
|
||||
'public_key': base64.b64encode(public_pem)
|
||||
})
|
||||
except AccountEdiProxyError as e:
|
||||
raise UserError(e.message)
|
||||
if 'error' in response:
|
||||
raise UserError(response['error'])
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
# simulate registration
|
||||
response = {'id_client': 'demo', 'refresh_token': 'demo'}
|
||||
else:
|
||||
try:
|
||||
response = self._make_request(SERVER_URL + '/iap/account_edi/1/create_user', params={
|
||||
'dbuuid': company.env['ir.config_parameter'].get_param('database.uuid'),
|
||||
'company_id': company.id,
|
||||
'edi_format_code': edi_format.code,
|
||||
'edi_identification': edi_identification,
|
||||
'public_key': base64.b64encode(public_pem)
|
||||
})
|
||||
except AccountEdiProxyError as e:
|
||||
raise UserError(e.message)
|
||||
if 'error' in response:
|
||||
raise UserError(response['error'])
|
||||
|
||||
self.create({
|
||||
'id_client': response['id_client'],
|
||||
|
||||
@@ -22,6 +22,9 @@ class AccountEdiFormat(models.Model):
|
||||
def _cron_receive_fattura_pa(self):
|
||||
''' Check the proxy for incoming invoices.
|
||||
'''
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
return
|
||||
|
||||
proxy_users = self.env['account_edi_proxy_client.user'].search([('edi_format_id', '=', self.env.ref('l10n_it_edi.edi_fatturaPA').id)])
|
||||
for proxy_user in proxy_users:
|
||||
company = proxy_user.company_id
|
||||
@@ -58,11 +61,13 @@ class AccountEdiFormat(models.Model):
|
||||
})
|
||||
|
||||
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:
|
||||
_logger.error('Error while receiving file from 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:
|
||||
_logger.error('Error while receiving file from SdiCoop: %s', e)
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Export
|
||||
@@ -133,10 +138,14 @@ class AccountEdiFormat(models.Model):
|
||||
return {invoice: {
|
||||
'error': _("You must accept the terms and conditions in the settings to use FatturaPA."),
|
||||
'blocking_level': 'error'} for invoice in invoices}
|
||||
try:
|
||||
responses = self._l10n_it_edi_upload([i['data'] for i in to_send.values()], proxy_user)
|
||||
except AccountEdiProxyError as e:
|
||||
return {invoice: {'error': e.message, 'blocking_level': 'error'} for invoice in invoices}
|
||||
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
responses = {filename: {'id_transaction': 'demo'} for invoice in invoices}
|
||||
else:
|
||||
try:
|
||||
responses = self._l10n_it_edi_upload([i['data'] for i in to_send.values()], proxy_user)
|
||||
except AccountEdiProxyError as e:
|
||||
return {invoice: {'error': e.message, 'blocking_level': 'error'} for invoice in invoices}
|
||||
|
||||
for filename, response in responses.items():
|
||||
invoice = to_send[filename]['invoice']
|
||||
@@ -160,11 +169,16 @@ class AccountEdiFormat(models.Model):
|
||||
return {invoice: {
|
||||
'error': _("You must accept the terms and conditions in the settings to use FatturaPA."),
|
||||
'blocking_level': 'error'} for invoice in invoices}
|
||||
try:
|
||||
responses = proxy_user._make_request(SERVER_URL + '/api/l10n_it_edi/1/in/TrasmissioneFatture',
|
||||
params={'ids_transaction': list(to_check.keys())})
|
||||
except AccountEdiProxyError as e:
|
||||
return {invoice: {'error': e.message, 'blocking_level': 'error'} for invoice in invoices}
|
||||
|
||||
if self.env['ir.config_parameter'].get_param('account_edi_proxy_client.demo', False):
|
||||
# simulate success and bypass ack
|
||||
return {invoice: {'attachment': invoice.l10n_it_edi_attachment_id} for invoice in invoices}
|
||||
else:
|
||||
try:
|
||||
responses = proxy_user._make_request(SERVER_URL + '/api/l10n_it_edi/1/in/TrasmissioneFatture',
|
||||
params={'ids_transaction': list(to_check.keys())})
|
||||
except AccountEdiProxyError as e:
|
||||
return {invoice: {'error': e.message, 'blocking_level': 'error'} for invoice in invoices}
|
||||
|
||||
proxy_acks = []
|
||||
for id_transaction, response in responses.items():
|
||||
|
||||
Reference in New Issue
Block a user