forked from tvtma/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX][MIG] mail: missing fields renames
- Loading branch information
1 parent
f2069ce
commit 6926676
Showing
5 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import base | ||
from . import account | ||
from . import mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
1 change: 1 addition & 0 deletions
1
openupgrade_framework/odoo_patch/odoo/addons/mail/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import base |
53 changes: 53 additions & 0 deletions
53
openupgrade_framework/odoo_patch/odoo/addons/mail/models/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"field", | ||
"field_id", | ||
), | ||
("mail.tracking.value", "mail_tracking_value", "field", "field_id"), | ||
] | ||
|
||
|
||
|