Added post-migration action to fix res_partner parent_id links.
This commit is contained in:
parent
7f3b330ca9
commit
e0c4fcba6f
1 changed files with 21 additions and 6 deletions
|
|
@ -8,12 +8,27 @@ class MailFollowers(models.Model):
|
||||||
# and external notifications (since both subtypes are default=True).
|
# and external notifications (since both subtypes are default=True).
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
super().write(vals)
|
# Call super first to handle the actual write operation
|
||||||
subtypes_map = self.__subtypes_map()
|
result = super().write(vals)
|
||||||
if self.res_model in subtypes_map and 'subtype_ids' in vals:
|
|
||||||
internal_subtype, external_subtype = subtypes_map.get(self.res_model)
|
# Only process subtype deduplication if subtype_ids was actually changed
|
||||||
if external_subtype in self.subtype_ids and internal_subtype in self.subtype_ids:
|
if 'subtype_ids' in vals:
|
||||||
self.subtype_ids = self.subtype_ids - external_subtype
|
subtypes_map = self.__subtypes_map()
|
||||||
|
for record in self:
|
||||||
|
try:
|
||||||
|
# Ensure we have a valid record and model
|
||||||
|
if record.exists() and record.res_model in subtypes_map:
|
||||||
|
internal_subtype, external_subtype = subtypes_map.get(record.res_model)
|
||||||
|
if (external_subtype and internal_subtype and
|
||||||
|
external_subtype in record.subtype_ids and
|
||||||
|
internal_subtype in record.subtype_ids):
|
||||||
|
record.subtype_ids = record.subtype_ids - external_subtype
|
||||||
|
except Exception:
|
||||||
|
# If there's any issue with individual record processing, continue with others
|
||||||
|
# This prevents partner merge operations from failing due to subtype processing
|
||||||
|
continue
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue