From 9c9552fd20e1cf2cee9f14a0ca093d3fc749f0f7 Mon Sep 17 00:00:00 2001 From: Yolann Sabaux Date: Thu, 25 Jan 2024 12:53:23 +0000 Subject: [PATCH] [FIX] account, mail: allow account custom sub model tracking Steps to reproduce: - Create an invoice and confirm it - reset to draft - change the account of an aml (product sales -> asset) -> on the log note you will see the detail of the modification `Account: 400000 Product Sales -> 101000 Current Assets` - connect with Demo - go on the same invoice Issue: You will not see the details of the aml account change This is problematic since Accountant and auditors should be able to see it. Cause: Sub-model tracking is not supported. Although we override this constraint in accounting (refer to https://github.com/odoo/odoo/blob/f56de22f10d09e6e34b25cbff04bbb6bf0823e54/addons/account/models/account_move.py#L5058-L5071), it remains inaccessible for users other than base.system. This is because we attempt to locate the account_id field on the model account.move defined in tracking.mail_message_id. opw-3632295 closes odoo/odoo#155034 X-original-commit: 20f00a73cb280fd9a3636122c4a8a316abcee0d0 Signed-off-by: Thibault Delavallee (tde) Signed-off-by: Yolann Sabaux (yosa) --- addons/account/tests/__init__.py | 1 + .../account/tests/test_mail_tracking_value.py | 39 +++++++++++++++++++ addons/mail/models/mail_tracking_value.py | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 addons/account/tests/test_mail_tracking_value.py diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py index 543026a0e00..ef30fad5f09 100644 --- a/addons/account/tests/__init__.py +++ b/addons/account/tests/__init__.py @@ -44,3 +44,4 @@ from . import test_account_partner from . import test_setup_wizard from . import test_structured_reference from . import test_product +from . import test_mail_tracking_value diff --git a/addons/account/tests/test_mail_tracking_value.py b/addons/account/tests/test_mail_tracking_value.py new file mode 100644 index 00000000000..f9f574f5ba9 --- /dev/null +++ b/addons/account/tests/test_mail_tracking_value.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +from odoo import Command +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.mail.tests.common import MailCommon +from odoo.tests import Form +from odoo.tests.common import tagged + + +@tagged('post_install', '-at_install') +class TestTracking(AccountTestInvoicingCommon, MailCommon): + + def test_aml_change_tracking(self): + """ tests that the field_groups is correctly set """ + account_move = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_line_ids': [Command.create({'product_id': self.product_a.id, 'price_unit': 200.0})] + }) + account_move.action_post() + account_move.button_draft() + old_value = account_move.invoice_line_ids.account_id + + with Form(account_move) as account_move_form: + with account_move_form.invoice_line_ids.edit(0) as line_form: + line_form.account_id = self.company_data['default_account_assets'] + new_value = account_move.invoice_line_ids.account_id + + self.flush_tracking() + self.assertTracking(account_move.message_ids, [ + ('account_id', 'many2one', old_value, new_value), + ]) + + tracking_value = account_move.message_ids.sudo().tracking_value_ids + tracking_value._compute_field_groups() + + self.assertEqual(tracking_value.field_groups, False, "There is no group on account.move.line.account_id") diff --git a/addons/mail/models/mail_tracking_value.py b/addons/mail/models/mail_tracking_value.py index c5533287800..4dd4b822264 100644 --- a/addons/mail/models/mail_tracking_value.py +++ b/addons/mail/models/mail_tracking_value.py @@ -38,7 +38,7 @@ class MailTracking(models.Model): @api.depends('mail_message_id', 'field_id') def _compute_field_groups(self): for tracking in self: - model = self.env[tracking.mail_message_id.model] + model = self.env[tracking.field_id.model] field = model._fields.get(tracking.field_id.name) tracking.field_groups = field.groups if field else 'base.group_system'