diff --git a/openupgrade_framework/odoo_patch/odoo/addons/__init__.py b/openupgrade_framework/odoo_patch/odoo/addons/__init__.py index 868155b85053..dfa16d0f6f3d 100644 --- a/openupgrade_framework/odoo_patch/odoo/addons/__init__.py +++ b/openupgrade_framework/odoo_patch/odoo/addons/__init__.py @@ -1,2 +1,3 @@ from . import base from . import account +from . import mail diff --git a/openupgrade_framework/odoo_patch/odoo/addons/mail/__init__.py b/openupgrade_framework/odoo_patch/odoo/addons/mail/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/openupgrade_framework/odoo_patch/odoo/addons/mail/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/openupgrade_framework/odoo_patch/odoo/addons/mail/models/__init__.py b/openupgrade_framework/odoo_patch/odoo/addons/mail/models/__init__.py new file mode 100644 index 000000000000..0e44449338cf --- /dev/null +++ b/openupgrade_framework/odoo_patch/odoo/addons/mail/models/__init__.py @@ -0,0 +1 @@ +from . import base diff --git a/openupgrade_framework/odoo_patch/odoo/addons/mail/models/base.py b/openupgrade_framework/odoo_patch/odoo/addons/mail/models/base.py new file mode 100644 index 000000000000..9b711648fa5c --- /dev/null +++ b/openupgrade_framework/odoo_patch/odoo/addons/mail/models/base.py @@ -0,0 +1,53 @@ +from odoo.tools import groupby + +from odoo.addons.base.models.ir_model import IrModelFields +from odoo.addons.mail.models.ir_model_fields import IrModelField as IrModelFieldMail +from odoo.addons.mail.models.models import BaseModel + +# TODO: delete this as there is a solution from PR: https://github.com/odoo/odoo/pull/172881 + + +def _mail_track_get_field_sequence(self, field): + if isinstance(field, IrModelFields): + sequence = getattr(field, "tracking", getattr(field, "track_sequence", 100)) + else: + sequence = getattr( + self._fields[field], + "tracking", + getattr(self._fields[field], "track_sequence", 100), + ) + if sequence is True: + sequence = 100 + return sequence + + +def unlink(self): + tracked = self.filtered("tracking") + if tracked: + tracking_values = self.env["mail.tracking.value"].search( + [("field_id", "in", tracked.ids)] + ) + field_to_trackings = groupby(tracking_values, lambda track: track.field_id) + for field, trackings in field_to_trackings: + self.env["mail.tracking.value"].concat(*trackings).write( + { + "field_info": { + "desc": field.field_description, + "name": field.name, + "sequence": self.env[ + field.model_id.model + ]._mail_track_get_field_sequence(field), + "type": field.ttype, + } + } + ) + return super(IrModelFieldMail, self).unlink() + + +_mail_track_get_field_sequence._original_method = ( + BaseModel._mail_track_get_field_sequence +) +BaseModel._mail_track_get_field_sequence = _mail_track_get_field_sequence + +unlink._original_method = IrModelFieldMail.unlink +IrModelFieldMail.unlink = unlink diff --git a/openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py b/openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py index 8a4d181b97b5..51a27f99e187 100644 --- a/openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py +++ b/openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py @@ -19,6 +19,7 @@ "field", "field_id", ), + ("mail.tracking.value", "mail_tracking_value", "field", "field_id"), ]