Skip to content

Commit

Permalink
[MIG] mail_improve_tracking_value: to v13
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelijaNorvaisaite committed Nov 28, 2023
1 parent 2fcf0a6 commit 6775f8e
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 194 deletions.
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude: |
# You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*)
default_language_version:
python: python3.8
python: python3
node: "14.13.0"
repos:
- repo: local
Expand Down Expand Up @@ -122,19 +122,15 @@ repos:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==19.8.0"]
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.5.3
- repo: https://github.com/OCA/pylint-odoo
rev: 7.0.2
hooks:
- id: pylint
- id: pylint_odoo
name: pylint with optional checks
args:
- --rcfile=.pylintrc
- --exit-zero
verbose: true
additional_dependencies: &pylint_deps
- pylint-odoo==3.5.0
- id: pylint
name: pylint with mandatory checks
- id: pylint_odoo
args:
- --rcfile=.pylintrc-mandatory
additional_dependencies: *pylint_deps
25 changes: 10 additions & 15 deletions mail_improved_tracking_value/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'Improved tracking value change',
'version': '12.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'
],
'data': [
'views/mail_tracking_value.xml'
],
"name": "Improved tracking value change",
"version": "13.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"],
"data": ["views/mail_tracking_value.xml"],
}
1 change: 0 additions & 1 deletion mail_improved_tracking_value/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

Expand Down
76 changes: 39 additions & 37 deletions mail_improved_tracking_value/models/mail_tracking_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,78 @@ class MailTrackingValue(models.Model):
_inherit = "mail.tracking.value"

new_value_formatted = fields.Char(
compute='_compute_formatted_value',
string='New value',
compute="_compute_formatted_value", string="New value",
)
old_value_formatted = fields.Char(
compute='_compute_formatted_value',
string='Old value',
)
record_name = fields.Char(
related='mail_message_id.record_name',
)
model = fields.Char(
related='mail_message_id.model',
store='True',
string='Model',
compute="_compute_formatted_value", string="Old value",
)
record_name = fields.Char(related="mail_message_id.record_name",)
model = fields.Char(related="mail_message_id.model", store="True", string="Model",)

@api.depends('new_value_char', 'new_value_integer', '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')
@api.depends(
"new_value_char",
"new_value_integer",
"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_type 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_type == "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_type == "float":
record.new_value_formatted = str(record.new_value_float)
record.old_value_formatted = str(record.old_value_float)
elif record.field_type == 'monetary':
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_type == "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_type == "text":
record.new_value_formatted = record.new_value_text
record.old_value_formatted = record.old_value_text

@api.model
def create_tracking_values(self, initial_value, new_value,
col_name, col_info, track_sequence):
def create_tracking_values(
self, initial_value, new_value, col_name, col_info, track_sequence,
):
""" Add tacking capabilities for many2many and one2many fields """
if col_info['type'] in ('many2many', 'one2many'):
if col_info["type"] in ("many2many", "one2many"):

def get_values(source, prefix):
if source:
names = ', '.join(source.exists().mapped('display_name'))
names = ", ".join(source.exists().mapped("display_name"))
json_ids = json.dumps(source.ids)
else:
names = ''
names = ""
json_ids = json.dumps([])
return {
'{}_value_char'.format(prefix): names,
'{}_value_text'.format(prefix): json_ids,
"{}_value_char".format(prefix): names,
"{}_value_text".format(prefix): json_ids,
}

values = {
'field': col_name,
'field_desc': col_info['string'],
'field_type': col_info['type'],
"field": col_name,
"field_desc": col_info["string"],
"field_type": col_info["type"],
}
values.update(get_values(initial_value, 'old'))
values.update(get_values(new_value, 'new'))
values.update(get_values(initial_value, "old"))
values.update(get_values(new_value, "new"))
return values
else:
return super().create_tracking_values(
initial_value, new_value,
col_name, col_info, track_sequence
initial_value, new_value, col_name, col_info, track_sequence,
)

Loading

0 comments on commit 6775f8e

Please sign in to comment.