From 7cb109e7b0ee2e46cef79ec7d3076d16715567f9 Mon Sep 17 00:00:00 2001 From: "Antoine Dupuis (andu)" Date: Fri, 20 May 2022 14:17:40 +0000 Subject: [PATCH] [FIX] account: fix write-after-post in PR 91638 PR 91638 introduced a write() on the partner_id after the AML state was set to 'posted'. This causes a problem for users who have the journal hash activated. Fix => move the write() before posting the AMLs. closes odoo/odoo#91997 X-original-commit: cd3bbeb15983b263ba2ffb419d59575b64a41ca2 Signed-off-by: Josse Colpaert Signed-off-by: Antoine Dupuis (andu) --- addons/account/models/account_move.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 795a0a8ed0e..ee78676cbe8 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2796,18 +2796,20 @@ class AccountMove(models.Model): # Create the analytic lines in batch is faster as it leads to less cache invalidation. to_post.mapped('line_ids').create_analytic_lines() + + for move in to_post: + # Fix inconsistencies that may occure if the OCR has been editing the invoice at the same time of a user. We force the + # partner on the lines to be the same as the one on the move, because that's the only one the user can see/edit. + wrong_lines = move.is_invoice() and move.line_ids.filtered(lambda aml: aml.partner_id != move.commercial_partner_id and not aml.display_type) + if wrong_lines: + wrong_lines.write({'partner_id': move.commercial_partner_id.id}) + to_post.write({ 'state': 'posted', 'posted_before': True, }) for move in to_post: - # Fix inconsistencies that may occure if the OCR has been editing the invoice at the same time of a user. We force the - # partner on the lines to be the same as the one on the move, because that's the only one the user can see/edit. - wrong_lines = move.is_invoice() and move.line_ids.filtered(lambda aml: aml.partner_id != move.commercial_partner_id) - if wrong_lines: - wrong_lines.write({'partner_id': move.commercial_partner_id.id}) - move.message_subscribe([p.id for p in [move.partner_id] if p not in move.sudo().message_partner_ids]) # Compute 'ref' for 'out_invoice'.