From 12db02464bdd79c42c53fc54a8235758b17f42e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 17 Jan 2025 17:24:50 +0100 Subject: [PATCH] Use compute fields for format contact mechanism value --- modules/party/contact_mechanism.py | 31 ++++++++++++------------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/modules/party/contact_mechanism.py b/modules/party/contact_mechanism.py index e236b6d51a..f6a74b9493 100644 --- a/modules/party/contact_mechanism.py +++ b/modules/party/contact_mechanism.py @@ -271,24 +271,18 @@ class ContactMechanism( ('value_compact',) + tuple(clause[1:]), ] - @classmethod - def _format_values(cls, mechanisms): - for mechanism in mechanisms: - value = mechanism.format_value( - value=mechanism.value, type_=mechanism.type) - if value != mechanism.value: - mechanism.value = value - value_compact = mechanism.format_value_compact( - value=mechanism.value, type_=mechanism.type) - if value_compact != mechanism.value_compact: - mechanism.value_compact = value_compact - cls.save(mechanisms) - - @classmethod - def create(cls, vlist): - mechanisms = super().create(vlist) - cls._format_values(mechanisms) - return mechanisms + def compute_fields(self, field_names=None): + values = super().compute_fields(field_names=field_names) + if not field_names or {'value', 'type'} & field_names: + if getattr(self, 'value', None) and getattr(self, 'type', None): + value = self.format_value(value=self.value, type_=self.type) + if self.value != value: + values['value'] = value + value_compact = self.format_value_compact( + value=self.value, type_=self.type) + if getattr(self, 'value_compact', None) != value_compact: + values['value_compact'] = value_compact + return values @classmethod def write(cls, *args): @@ -305,7 +299,6 @@ class ContactMechanism( 'contact': mechanism.rec_name, }) super().write(*args) - cls._format_values(all_mechanisms) @classmethod def validate_fields(cls, mechanisms, field_names):