Skip to content

Commit 66265b4

Browse files
committed
[IMP] account_peppol: Add a demo EAS for Peppol
When the company is registered with this particular EAS, Odoo will act as if it was in demo mode. No call to the real Peppol Network is performed, everything is mocked locally. This allows to do the trainings on /trial databases, and get the lastests improvements. Also fixing some crons that needed to be run with the right company. task-4968580 closes odoo#220641 X-original-commit: 4678062 Signed-off-by: Laurent Smet (las) <las@odoo.com> Signed-off-by: Claire Bretton (clbr) <clbr@odoo.com>
1 parent 91b7898 commit 66265b4

6 files changed

Lines changed: 27 additions & 5 deletions

File tree

addons/account_edi_ubl_cii/models/res_partner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class ResPartner(models.Model):
138138
('EM', "Electronic mail"),
139139
]
140140
)
141+
available_peppol_eas = fields.Json(compute='_compute_available_peppol_eas')
141142

142143
@api.constrains('peppol_endpoint')
143144
def _check_peppol_fields(self):
@@ -254,6 +255,12 @@ def _compute_peppol_eas(self):
254255
break
255256
partner.peppol_eas = new_eas
256257

258+
@api.depends_context('company')
259+
@api.depends('company_id')
260+
def _compute_available_peppol_eas(self):
261+
# TO OVERRIDE
262+
self.available_peppol_eas = list(dict(self._fields['peppol_eas'].selection))
263+
257264
def _build_error_peppol_endpoint(self, eas, endpoint):
258265
""" This function contains all the rules regarding the peppol_endpoint."""
259266
if eas == '0208' and not re.match(r"^\d{10}$", endpoint):

addons/account_edi_ubl_cii/views/res_partner_views.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
<xpath expr="//group[@id='invoice_send_settings']" position="inside">
88
<label for="peppol_eas" string="Peppol Address" invisible="1"/> <!-- TODO remove in master -->
99
<div id="peppol_address" class="row" invisible="1"/> <!-- TODO remove in master -->
10+
<field name="available_peppol_eas" invisible="1"/>
1011
<field name="peppol_eas"
1112
placeholder="Peppol ID"
1213
nolabel="1"
14+
widget="filterable_selection"
15+
options="{'whitelist_fname': 'available_peppol_eas'}"
1316
class="o_field_peppol_eas_selection"/>
1417
<field name="peppol_endpoint" nolabel="1" placeholder="Your endpoint"/>
1518
</xpath>

addons/account_peppol/models/account_edi_proxy_user.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def _peppol_get_new_documents(self, skip_no_journal=False):
173173
}
174174
}
175175
for edi_user in self:
176+
edi_user = edi_user.with_company(edi_user.company_id)
176177
journal = edi_user.company_id.peppol_purchase_journal_id
177178
if not journal:
178179
msg = _('Please set a journal for Peppol invoices on %s before receiving documents.', edi_user.company_id.display_name)
@@ -245,6 +246,7 @@ def _peppol_get_message_status(self):
245246
job_count = self._context.get('peppol_crons_job_count') or BATCH_SIZE
246247
need_retrigger = False
247248
for edi_user in self:
249+
edi_user = edi_user.with_company(edi_user.company_id)
248250
edi_user_moves = self.env['account.move'].search(
249251
[
250252
('peppol_move_state', '=', 'processing'),
@@ -296,6 +298,7 @@ def _peppol_get_message_status(self):
296298

297299
def _peppol_get_participant_status(self):
298300
for edi_user in self:
301+
edi_user = edi_user.with_company(edi_user.company_id)
299302
try:
300303
proxy_user = edi_user._call_peppol_proxy("/api/peppol/2/participant_status")
301304
except AccountEdiProxyError as e:

addons/account_peppol/models/res_company.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,13 @@ def _peppol_supported_document_types(self):
281281
for identifier, document_name in identifiers.items()
282282
}
283283

284-
def _get_peppol_edi_mode(self):
284+
def _get_peppol_edi_mode(self, temporary_eas=False):
285285
self.ensure_one()
286286
config_param = self.env['ir.config_parameter'].sudo().get_param('account_peppol.edi.mode')
287287
# by design, we can only have zero or one proxy user per company with type Peppol
288288
peppol_user = self.sudo().account_edi_proxy_client_ids.filtered(lambda u: u.proxy_type == 'peppol')
289-
return peppol_user.edi_mode or config_param or 'prod'
289+
demo_if_demo_identifier = 'demo' if (temporary_eas or self.peppol_eas) == 'odemo' else False
290+
return demo_if_demo_identifier or peppol_user.edi_mode or config_param or 'prod'
290291

291292
def _get_peppol_webhook_endpoint(self):
292293
self.ensure_one()

addons/account_peppol/models/res_partner.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ResPartner(models.Model):
2222
invoice_sending_method = fields.Selection(
2323
selection_add=[('peppol', 'by Peppol')],
2424
)
25+
peppol_eas = fields.Selection(selection_add=[('odemo', 'Odoo Demo ID')]) # Not a real EAS, used for demonstration.
2526
available_peppol_sending_methods = fields.Json(compute='_compute_available_peppol_sending_methods')
2627
available_peppol_edi_formats = fields.Json(compute='_compute_available_peppol_edi_formats')
2728
peppol_verification_state = fields.Selection(
@@ -56,6 +57,14 @@ def _compute_available_peppol_edi_formats(self):
5657
else:
5758
partner.available_peppol_edi_formats = list(dict(self._fields['invoice_edi_format'].selection))
5859

60+
def _compute_available_peppol_eas(self):
61+
# EXTENDS 'account_edi_ubl_cii'
62+
super()._compute_available_peppol_eas()
63+
eas_codes = set(self.available_peppol_eas)
64+
if self.env.company._get_peppol_edi_mode() != 'demo' and 'odemo' in eas_codes:
65+
eas_codes.remove('odemo')
66+
self.available_peppol_eas = list(eas_codes)
67+
5968
# -------------------------------------------------------------------------
6069
# HELPERS
6170
# -------------------------------------------------------------------------

addons/account_peppol/wizard/peppol_registration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from odoo.exceptions import UserError, ValidationError
1010

1111
from odoo.addons.account_edi_proxy_client.models.account_edi_proxy_user import AccountEdiProxyError
12-
from odoo.addons.account_peppol.tools.demo_utils import handle_demo
1312

1413

1514
class PeppolRegistration(models.TransientModel):
@@ -105,10 +104,10 @@ def _compute_peppol_warnings(self):
105104
}
106105
wizard.peppol_warnings = peppol_warnings or False
107106

108-
@api.depends('company_id', 'edi_user_id')
107+
@api.depends('company_id', 'edi_user_id', 'peppol_eas')
109108
def _compute_edi_mode(self):
110109
for wizard in self:
111-
wizard.edi_mode = wizard.company_id._get_peppol_edi_mode()
110+
wizard.edi_mode = wizard.company_id._get_peppol_edi_mode(temporary_eas=wizard.peppol_eas)
112111

113112
@api.depends('peppol_eas', 'peppol_endpoint')
114113
def _compute_smp_registration_external_provider(self):

0 commit comments

Comments
 (0)