From d0ed8cd28735af3e46e31f269c13a8c6571fbcae Mon Sep 17 00:00:00 2001 From: Antoine Boonen Date: Tue, 16 Jan 2024 10:47:04 +0100 Subject: [PATCH] [FIX] hr_expense: Fix auto-extraction of attachments. Problem --------- In the commit 24345812cb015e86f362f8c35176646239bfb803 (odoo), we modified the extraction of attachment in such a way that mails coming in a journal from aliases with several attachments create several invoices. Due to the urgency of the task, the computation of whether an attachment needs auto-extraction or not, has been skipped which failing some tests that had been silenced. Linked PR #49816 (enterprise) fixes it. However, as a comment on the said PR suggested, we should add a context key that disable the auto-extraction. Objective --------- Add a context key that disable the auto-extraction and update commit 2bfe69be5c64743d0bf35793a427878170d0b3c6 (enterprise) to use the said context key. Solution --------- 1. Remove the override of the `_needs_auto_extract` 2. Manually set the main attachment of the created moves so that `register_as_main_attachment` is not called when accessing the move. This removes the auto-extraction without the need to use the key (we still keep the context key as suggested by the OCR team). closes odoo/odoo#149525 Related: odoo/enterprise#49816 Signed-off-by: Laurent Smet (las) --- addons/hr_expense/models/hr_expense_sheet.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/hr_expense/models/hr_expense_sheet.py b/addons/hr_expense/models/hr_expense_sheet.py index a94a76e1420..69bdcb0735a 100644 --- a/addons/hr_expense/models/hr_expense_sheet.py +++ b/addons/hr_expense/models/hr_expense_sheet.py @@ -674,6 +674,10 @@ class HrExpenseSheet(models.Model): company_account_sheets = self - own_account_sheets moves = self.env['account.move'].create([sheet._prepare_bills_vals() for sheet in own_account_sheets]) + # Set the main attachment on the moves directly to avoid recomputing the + # `register_as_main_attachment` on the moves which triggers the OCR again + for move in moves: + move.message_main_attachment_id = move.attachment_ids[0] if move.attachment_ids else None payments = self.env['account.payment'].with_context(**skip_context).create([ expense._prepare_payments_vals() for expense in company_account_sheets.expense_line_ids ])