Skip to content

Commit

Permalink
[FIX] hr_expense: Fix auto-extraction of attachments.
Browse files Browse the repository at this point in the history
Problem
---------
In the commit 2434581 (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 odoo#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#149525

Related: odoo/enterprise#49816
Signed-off-by: Laurent Smet (las) <las@odoo.com>
  • Loading branch information
aboo-odoo committed Jan 16, 2024
1 parent 5b284d4 commit d0ed8cd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addons/hr_expense/models/hr_expense_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ def _do_create_moves(self):
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
])
Expand Down

0 comments on commit d0ed8cd

Please sign in to comment.