From 987ffe4f6940810d1ad744deb34a09eba11717c7 Mon Sep 17 00:00:00 2001 From: "Ricardo Gomes Rodrigues (rigr)" Date: Fri, 16 Dec 2022 10:44:51 +0000 Subject: [PATCH] [FIX] account: aml's `partner_id` modified after the move has been posted when using the hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: 1. Activate the hash mode on a journal 2. Create an account move 3. Choose a customer who is not a commercial partner (e.g. Brandon Freeman from Azure Interior) 4. Post the move 5. Error saying that we cannot modify the `partner_id` because the move has already been posted This is because currently we first post the move and then we modify the `partner_id` of the lines whose `partner_id` is different from the account's `commercial_partner_id`. We can easily fix this by posting the move after the lines'`partner_id` have been modified. closes odoo/odoo#108177 X-original-commit: 1036134a2f0d921fd6a659b4951e5fa63975b78d Signed-off-by: William André (wan) Signed-off-by: Ricardo Gomes Rodrigues (rigr) --- addons/account/models/account_move.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index b3bfe769652..f53447ffeae 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3278,10 +3278,6 @@ class AccountMove(models.Model): # Create the analytic lines in batch is faster as it leads to less cache invalidation. to_post.line_ids._create_analytic_lines() - to_post.write({ - 'state': 'posted', - 'posted_before': True, - }) # Trigger copying for recurring invoices to_post.filtered(lambda m: m.auto_post not in ('no', 'at_date'))._copy_recurring_entries() @@ -3296,6 +3292,12 @@ class AccountMove(models.Model): if wrong_lines: wrong_lines.write({'partner_id': invoice.commercial_partner_id.id}) + to_post.write({ + 'state': 'posted', + 'posted_before': True, + }) + + for invoice in to_post: invoice.message_subscribe([ p.id for p in [invoice.partner_id]