Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][MIG][17.0] mail: missing fields renames #674

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading