|
|
"""
If the country_code changes, recompute the EAS only if there is a country_code, it exists in the
EAS_MAPPING, and the current EAS is not consistent with the new country_code.
"""
for partner in self:
partner.peppol_eas = partner.peppol_eas
country_code = partner._deduce_country_code()
if country_code in EAS_MAPPING:
eas_to_field = EAS_MAPPING[country_code]
if partner.peppol_eas not in eas_to_field:
candidates = {
eas: field
for eas, field in eas_to_field.items()
if eas not in DEPRECATED_PEPPOL_EAS
} or eas_to_field
new_eas = next(iter(candidates))
# Iterate on the possible EAS until a valid one is found
for eas, field in candidates.items():
if field and field in partner._fields:
value = partner._get_peppol_endpoint_value(country_code, field, eas)
if value and not partner._build_error_peppol_endpoint(eas, value):
new_eas = eas
break
partner.peppol_eas = new_eas
|
|