[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) <las@odoo.com>
This commit is contained in:
Antoine Boonen
2024-01-16 22:39:56 +00:00
parent 5b284d4176
commit d0ed8cd287
@@ -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
])