2
0

[FIX] account_chart_update: false positive detecting diff on Html fields

When executing the chart updater and selecting the "notes" field from fiscal positions, you were getting differences 100% of the time.

This was because [fiscal position's notes field is Html][1], while [the template field is Text][2].

@moduon MT-1912

[1]: 5ef647d5d4/addons/account/models/partner.py (L32)
[2]: 5ef647d5d4/addons/account/models/chart_template.py (L1470)
This commit is contained in:
Jairo Llopis 2023-01-11 10:19:31 +00:00 committed by Luis J. Salvatierra
parent bcef995ecc
commit 79bbd7cdc4
3 changed files with 17 additions and 8 deletions

View File

@ -1,7 +1,6 @@
* `Tecnativa <https://www.tecnativa.com>`_: * `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza * Pedro M. Baeza
* Jairo Llopis
* Ernesto Tejeda * Ernesto Tejeda
* Jacques-Etienne Baudoux <je@bcim.be> * Jacques-Etienne Baudoux <je@bcim.be>
@ -9,3 +8,4 @@
* Nacho Muñoz <nacmuro@gmail.com> * Nacho Muñoz <nacmuro@gmail.com>
* Alberto Martín - Guadaltech <alberto.martin@guadaltech.es> * Alberto Martín - Guadaltech <alberto.martin@guadaltech.es>
* Fernando La Chica - GreenIce <fernandolachica@gmail.com> * Fernando La Chica - GreenIce <fernandolachica@gmail.com>
* Jairo Llopis (https://www.moduon.team/)

View File

@ -327,7 +327,7 @@ class TestAccountChartUpdate(common.HttpCase):
self.account_template.tag_ids = [ self.account_template.tag_ids = [
(6, 0, [self.account_tag_1.id, self.account_tag_2.id]) (6, 0, [self.account_tag_1.id, self.account_tag_2.id])
] ]
self.fp_template.note = "<p>Test note</p>" self.fp_template.note = "Test note. \n \n Multiline. \n"
self.fp_template.account_ids.account_dest_id = new_account_tmpl.id self.fp_template.account_ids.account_dest_id = new_account_tmpl.id
self.fp_template.tax_ids.tax_dest_id = self.tax_template.id self.fp_template.tax_ids.tax_dest_id = self.tax_template.id
wizard = self.wizard_obj.create(self.wizard_vals) wizard = self.wizard_obj.create(self.wizard_vals)
@ -341,7 +341,7 @@ class TestAccountChartUpdate(common.HttpCase):
self.assertEqual(wizard.account_ids.account_id, self.account_template) self.assertEqual(wizard.account_ids.account_id, self.account_template)
self.assertEqual(wizard.account_ids.type, "updated") self.assertEqual(wizard.account_ids.type, "updated")
self.assertTrue(wizard.fiscal_position_ids) self.assertTrue(wizard.fiscal_position_ids)
self.assertTrue(wizard.fiscal_position_ids.type, "updated") self.assertEqual(wizard.fiscal_position_ids.type, "updated")
self.assertEqual( self.assertEqual(
wizard.fiscal_position_ids.fiscal_position_id, self.fp_template wizard.fiscal_position_ids.fiscal_position_id, self.fp_template
) )
@ -359,7 +359,7 @@ class TestAccountChartUpdate(common.HttpCase):
self.assertEqual(self.account.name, self.account_template.name) self.assertEqual(self.account.name, self.account_template.name)
self.assertIn(self.account_tag_1, self.account.tag_ids) self.assertIn(self.account_tag_1, self.account.tag_ids)
self.assertIn(self.account_tag_2, self.account.tag_ids) self.assertIn(self.account_tag_2, self.account.tag_ids)
self.assertEqual(self.fp.note, self.fp_template.note) self.assertEqual(self.fp.note, f"<p>{self.fp_template.note}</p>")
self.assertEqual(self.fp.account_ids.account_dest_id, new_account) self.assertEqual(self.fp.account_ids.account_dest_id, new_account)
self.assertEqual(self.fp.tax_ids.tax_dest_id, self.tax) self.assertEqual(self.fp.tax_ids.tax_dest_id, self.tax)
wizard.unlink() wizard.unlink()
@ -384,7 +384,6 @@ class TestAccountChartUpdate(common.HttpCase):
self.assertFalse(wizard.fiscal_position_ids) self.assertFalse(wizard.fiscal_position_ids)
self.tax_template.description = "Test description" self.tax_template.description = "Test description"
self.account_template.name = "Other name" self.account_template.name = "Other name"
self.fp_template.note = "<p>Test note</p>"
wizard.unlink() wizard.unlink()
# Remove objects # Remove objects
new_tax_tmpl.unlink() new_tax_tmpl.unlink()

View File

@ -13,6 +13,8 @@ import logging
from contextlib import closing from contextlib import closing
from io import StringIO from io import StringIO
from markupsafe import Markup
from odoo import _, api, exceptions, fields, models, tools from odoo import _, api, exceptions, fields, models, tools
from odoo.tools import config from odoo.tools import config
@ -672,7 +674,7 @@ class WizardUpdateChartsAccounts(models.TransientModel):
return set(models.MAGIC_COLUMNS) | specials return set(models.MAGIC_COLUMNS) | specials
@api.model @api.model
def diff_fields(self, template, real): def diff_fields(self, template, real): # noqa: C901
"""Get fields that are different in template and real records. """Get fields that are different in template and real records.
:param odoo.models.Model template: :param odoo.models.Model template:
@ -721,10 +723,18 @@ class WizardUpdateChartsAccounts(models.TransientModel):
): ):
result[key] = expected result[key] = expected
else: else:
template_value = template[key] template_value, real_value = template[key], real[key]
if template._name == "account.account.template" and key == "code": if template._name == "account.account.template" and key == "code":
template_value = self.padded_code(template["code"]) template_value = self.padded_code(template["code"])
if template_value != real[key]: # Normalize values when one field is Char and the other is Html
if (
isinstance(template_value, str) and isinstance(real_value, Markup)
) or (
isinstance(template_value, Markup) and isinstance(real_value, str)
):
template_value = Markup(template_value).striptags()
real_value = Markup(real_value).striptags()
if template_value != real_value:
result[key] = template_value result[key] = template_value
# Avoid to cache recordset references # Avoid to cache recordset references
if key in result: if key in result: