Skip to content

Commit bc09e19

Browse files
committed
[IMP] account_{edi_ubl_cii,peppol}: partner improvements
This commit improves the UX by displaying more intuitive placeholders for the peppol identifier. The peppol information is also automatically verified when important data changes. It also adds a special case for Belgium in which we try to use the vat number as the peppol identifier with the company registry endpoint. closes odoo#238447 Task: 5172378 Forward-port-of: odoo#238251 Forward-port-of: odoo#233160 Signed-off-by: Allesio Pellicciotta (peal) <[email protected]> Signed-off-by: Claire Bretton (clbr) <[email protected]>
1 parent ccdf34b commit bc09e19

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

addons/account_edi_ubl_cii/models/res_partner.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ def _compute_is_peppol_edi_format(self):
220220
for partner in self:
221221
partner.is_peppol_edi_format = partner.invoice_edi_format in self._get_peppol_formats()
222222

223+
def _get_peppol_endpoint_value(self, country_code, field):
224+
self.ensure_one()
225+
value = field in self._fields and self[field]
226+
227+
if (
228+
country_code == 'BE'
229+
and field == 'company_registry'
230+
and not value
231+
and self.vat
232+
):
233+
value = self.vat
234+
if value.isalnum():
235+
value = value.removeprefix(country_code)
236+
237+
return sanitize_peppol_endpoint(value)
238+
223239
@api.depends(lambda self: self._peppol_eas_endpoint_depends() + ['peppol_eas'])
224240
def _compute_peppol_endpoint(self):
225241
""" If the EAS changes and a valid endpoint is available, set it. Otherwise, keep the existing value."""
@@ -228,11 +244,9 @@ def _compute_peppol_endpoint(self):
228244
country_code = partner._deduce_country_code()
229245
if country_code in EAS_MAPPING:
230246
field = EAS_MAPPING[country_code].get(partner.peppol_eas)
231-
if field \
232-
and field in partner._fields \
233-
and (peppol_endpoint := sanitize_peppol_endpoint(partner[field])) \
234-
and not partner._build_error_peppol_endpoint(partner.peppol_eas, peppol_endpoint):
235-
partner.peppol_endpoint = peppol_endpoint
247+
value = partner._get_peppol_endpoint_value(country_code, field)
248+
if field and value and not partner._build_error_peppol_endpoint(partner.peppol_eas, value):
249+
partner.peppol_endpoint = value
236250

237251
@api.depends(lambda self: self._peppol_eas_endpoint_depends())
238252
def _compute_peppol_eas(self):
@@ -249,8 +263,9 @@ def _compute_peppol_eas(self):
249263
new_eas = next(iter(EAS_MAPPING[country_code].keys()))
250264
# Iterate on the possible EAS until a valid one is found
251265
for eas, field in eas_to_field.items():
252-
if field and field in partner._fields and (peppol_endpoint := sanitize_peppol_endpoint(partner[field])):
253-
if not partner._build_error_peppol_endpoint(eas, peppol_endpoint):
266+
if field and field in partner._fields:
267+
value = partner._get_peppol_endpoint_value(country_code, field)
268+
if value and not partner._build_error_peppol_endpoint(eas, value):
254269
new_eas = eas
255270
break
256271
partner.peppol_eas = new_eas

addons/account_edi_ubl_cii/views/res_partner_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
widget="filterable_selection"
1515
options="{'whitelist_fname': 'available_peppol_eas'}"
1616
class="o_field_peppol_eas_selection"/>
17-
<field name="peppol_endpoint" nolabel="1" placeholder="Your endpoint"/>
17+
<field name="peppol_endpoint" nolabel="1"/>
1818
</xpath>
1919
</field>
2020
</record>

addons/account_peppol/models/res_partner.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ class ResPartner(models.Model):
2727
available_peppol_edi_formats = fields.Json(compute='_compute_available_peppol_edi_formats')
2828
peppol_verification_state = fields.Selection(
2929
selection=[
30-
('not_verified', 'Not verified yet'),
31-
('not_valid', 'Not on Peppol'), # does not exist on Peppol at all
32-
('not_valid_format', 'Cannot receive this format'), # registered on Peppol but cannot receive the selected document type
33-
('valid', 'Valid'),
30+
('not_verified', 'Unchecked'),
31+
('not_valid', 'Partner is not on Peppol'), # does not exist on Peppol at all
32+
('not_valid_format', 'Partner cannot receive format'), # registered on Peppol but cannot receive the selected document type
33+
('valid', 'Partner is on Peppol'),
3434
],
35-
string='Peppol endpoint verification',
35+
string='Peppol status',
3636
company_dependent=True,
3737
)
3838

39+
@api.onchange('invoice_edi_format', 'peppol_endpoint', 'peppol_eas')
40+
def _onchange_verify_peppol_status(self):
41+
self.button_account_peppol_check_partner_endpoint()
42+
3943
# -------------------------------------------------------------------------
4044
# COMPUTE METHODS
4145
# -------------------------------------------------------------------------

addons/account_peppol/views/res_partner_views.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131
<xpath expr="//div[@id='peppol_address']" position="after">
3232
<field name="is_peppol_edi_format" invisible="1"/>
3333
<field name="peppol_verification_state" invisible="1" force_save="1"/>
34-
<label for="peppol_verification_state"
35-
groups="base.group_no_one"
36-
invisible="not peppol_endpoint"/>
37-
<div class="row"
38-
groups="base.group_no_one"
39-
invisible="not peppol_endpoint">
34+
<label for="peppol_verification_state" invisible="not peppol_endpoint"/>
35+
<div class="row" invisible="not peppol_endpoint">
4036
<div class="col-6">
4137
<field name="peppol_verification_state" readonly="1"/>
4238
</div>

0 commit comments

Comments
 (0)