Skip to content

Commit

Permalink
[FIX][MIG] mail: missing fields renames
Browse files Browse the repository at this point in the history
  • Loading branch information
haumenphai authored and phamgiang2510 committed Jul 12, 2024
1 parent f2069ce commit 6926676
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions openupgrade_framework/odoo_patch/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import base
from . import account
from . import mail
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
53 changes: 53 additions & 0 deletions openupgrade_framework/odoo_patch/odoo/addons/mail/models/base.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"field",
"field_id",
),
("mail.tracking.value", "mail_tracking_value", "field", "field_id"),
]


Expand Down

0 comments on commit 6926676

Please sign in to comment.