Skip to content

Commit

Permalink
[17.0][MIG] mail_improved_tracking_value: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
psugne committed Oct 15, 2024
1 parent e88b443 commit 2d12902
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 48 deletions.
3 changes: 2 additions & 1 deletion mail_improved_tracking_value/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ value changes on predefined fields.
It adds support for many2many and one2many fields, which are not handled
well by default.
It also implements a new view (little bit more user friendly than the
existing one) to watch for changes
existing one) to watch for changes

Installation
============
Expand Down Expand Up @@ -60,6 +60,7 @@ Contributors
------------

* Thierry Ducrest <[email protected]>
* Ugnė Sinkevičienė <[email protected]>

Maintainer
----------
Expand Down
4 changes: 2 additions & 2 deletions mail_improved_tracking_value/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

{
"name": "Improved tracking value change",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"summary": "Improves tracking changed values for certain type of fields."
"Adds a user-friendly view to consult them.",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Tools",
"website": "https://github.com/OCA/social",
"depends": ["base", "mail"],
"depends": ["mail"],
"data": ["views/mail_tracking_value.xml"],
}
2 changes: 1 addition & 1 deletion mail_improved_tracking_value/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MailMessage(models.Model):

@api.model
def name_get(self):
res = super(MailMessage, self).name_get()
res = super().name_get()
params = self.env.context.get("params")
if params:
model = params.get("model")
Expand Down
25 changes: 10 additions & 15 deletions mail_improved_tracking_value/models/mail_tracking_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class MailTrackingValue(models.Model):

_inherit = "mail.tracking.value"

new_value_formatted = fields.Char(
Expand All @@ -25,33 +24,31 @@ class MailTrackingValue(models.Model):
"new_value_float",
"new_value_text",
"new_value_datetime",
"new_value_monetary",
"old_value_char",
"old_value_integer",
"old_value_float",
"old_value_text",
"old_value_datetime",
"old_value_monetary",
)
def _compute_formatted_value(self):
"""Sets the value formatted field used in the view"""
for record in self:
if record.field_type in ("many2many", "one2many", "char"):
if record.field_id.ttype in ("many2many", "one2many", "char"):
record.new_value_formatted = record.new_value_char
record.old_value_formatted = record.old_value_char
elif record.field_type == "integer":
elif record.field_id.ttype == "integer":
record.new_value_formatted = str(record.new_value_integer)
record.old_value_formatted = str(record.old_value_integer)
elif record.field_type == "float":
elif record.field_id.ttype == "float":
record.new_value_formatted = str(record.new_value_float)
record.old_value_formatted = str(record.old_value_float)
elif record.field_id.ttype == "monetary":
record.new_value_formatted = str(record.new_value_float)
record.old_value_formatted = str(record.old_value_float)
elif record.field_type == "monetary":
record.new_value_formatted = str(record.new_value_monetary)
record.old_value_formatted = str(record.old_value_monetary)
elif record.field_type == "datetime":
elif record.field_id.ttype == "datetime":
record.new_value_formatted = str(record.new_value_datetime)
record.old_value_formatted = str(record.old_value_datetime)
elif record.field_type == "text":
elif record.field_id.ttype == "text":
record.new_value_formatted = record.new_value_text
record.old_value_formatted = record.old_value_text

Expand All @@ -76,8 +73,8 @@ def get_values(source, prefix):
names = ""
json_ids = json.dumps([])
return {
"{}_value_char".format(prefix): names,
"{}_value_text".format(prefix): json_ids,
f"{prefix}_value_char": names,
f"{prefix}_value_text": json_ids,
}

field = self.env["ir.model.fields"]._get(model_name, col_name)
Expand All @@ -86,8 +83,6 @@ def get_values(source, prefix):

values = {
"field": field.id,
"field_desc": col_info["string"],
"field_type": col_info["type"],
}
values.update(get_values(initial_value, "old"))
values.update(get_values(new_value, "new"))
Expand Down
3 changes: 3 additions & 0 deletions mail_improved_tracking_value/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
52 changes: 25 additions & 27 deletions mail_improved_tracking_value/tests/test_improved_tracking_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_change_one2many(self):
self.assertEqual(tracking["new_value_text"], json.dumps([self.dr.id]))

def test_change_one2many_empty(self):
"""Test tracking one2many changes emtpy"""
"""Test tracking one2many changes empty"""
tracking = self.model.create_tracking_values(
self.mr,
None,
Expand Down Expand Up @@ -75,11 +75,9 @@ def test_char_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "char",
"old_value_char": "weakness",
"new_value_char": "strength",
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]._get("res.partner", "name").id,
}
)
self.assertEqual(r.old_value_formatted, "weakness")
Expand All @@ -89,11 +87,11 @@ def test_many2many_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "many2many",
"old_value_char": "123",
"new_value_char": "456",
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]
._get("res.partner", "category_id")
.id,
}
)
self.assertEqual(r.old_value_formatted, "123")
Expand All @@ -103,11 +101,11 @@ def test_one2many_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "one2many",
"old_value_char": "123",
"new_value_char": "456",
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]
._get("res.partner", "child_ids")
.id,
}
)
self.assertEqual(r.old_value_formatted, "123")
Expand All @@ -117,11 +115,11 @@ def test_integer_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "integer",
"old_value_integer": 1,
"new_value_integer": 3,
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]
._get("res.partner", "supplier_rank")
.id,
}
)
self.assertEqual(r.old_value_formatted, str(1))
Expand All @@ -131,11 +129,11 @@ def test_float_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "float",
"old_value_float": 1.1,
"new_value_float": 3.14159,
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]
._get("res.partner", "credit_limit")
.id,
}
)
self.assertEqual(r.old_value_formatted, str(1.1))
Expand All @@ -145,11 +143,11 @@ def test_monetary_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "monetary",
"old_value_monetary": 3.45,
"new_value_monetary": 5.45,
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"old_value_float": 3.45,
"new_value_float": 5.45,
"field_id": self.env["ir.model.fields"]
._get("res.partner", "credit")
.id,
}
)
self.assertEqual(r.old_value_formatted, str(3.45))
Expand All @@ -159,11 +157,11 @@ def test_datetime_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "datetime",
"old_value_datetime": "2018-01-01",
"new_value_datetime": "2018-01-04",
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]
._get("res.partner", "create_date")
.id,
}
)
self.assertEqual(r.old_value_formatted, "2018-01-01 00:00:00")
Expand All @@ -173,11 +171,11 @@ def test_text_tracking_value(self):
r = self.model.create(
{
"mail_message_id": self.msg.id,
"field_type": "text",
"old_value_text": "previous",
"new_value_text": "next",
"field": self.env["ir.model.fields"]._get("res.partner", "name").id,
"field_desc": "desc",
"field_id": self.env["ir.model.fields"]
._get("discuss.channel", "note")
.id,
}
)
self.assertEqual(r.old_value_formatted, "previous")
Expand Down
4 changes: 2 additions & 2 deletions mail_improved_tracking_value/views/mail_tracking_value.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
>
<field name="create_date" string="On" />
<field name="record_name" string="For" />
<field name="field_desc" string="Field changed" />
<field name="field_id" string="Field changed" />
<field name="old_value_formatted" />
<field name="new_value_formatted" />
<field name="model" />
Expand All @@ -31,7 +31,7 @@
<field name="create_date" class="oe-inline" />
<group name="main">
<field name="mail_message_id" string="For" />
<field name="field_desc" string="Field changed" />
<field name="field_id" string="Field changed" />
<field name="old_value_formatted" />
<field name="new_value_formatted" />
<field name="model" />
Expand Down

0 comments on commit 2d12902

Please sign in to comment.