Skip to content

Commit

Permalink
[FIX] account: make sure that the invoice is saved immediately after …
Browse files Browse the repository at this point in the history
…the edi decoder

Part-of: #122194
  • Loading branch information
jco-odoo authored and lordkrandel committed Sep 19, 2023
1 parent af90aea commit c02d8b1
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3074,30 +3074,28 @@ def _extend_with_attachments(self, attachments, new=False):
"""
success = False

for file_data in attachments._unwrap_edi_attachments(): # sorted by priority

decoder = self._get_edi_decoder(file_data, new=new)

try:
if decoder and not success:
with self.env.cr.savepoint(), self._get_edi_creation() as invoice:
# pylint: disable=not-callable
success = decoder(invoice, file_data, new)
# sorted by priority
for file_data in attachments._unwrap_edi_attachments():
if not success and (decoder := self._get_edi_decoder(file_data, new=new)):
try:
with self.env.cr.savepoint():
with self._get_edi_creation() as invoice:
# pylint: disable=not-callable
success = decoder(invoice, file_data, new)
if success:
invoice._link_bill_origin_to_purchase_orders(timeout=4)

except RedirectWarning as rw:
raise rw
except Exception as e:
_logger.exception(
"Error importing attachment '%s' as invoice: %s",
file_data['filename'],
str(e),
)

finally:
if file_data.get('on_close'):
file_data['on_close']()
except RedirectWarning:
raise
except Exception:
_logger.exception(
"Error importing attachment '%s' as invoice (decoder=%s)",
file_data['filename'],
decoder.__name__
)
finally:
if file_data.get('on_close'):
file_data['on_close']()

return success

Expand Down

0 comments on commit c02d8b1

Please sign in to comment.