[FIX] account_edi: also cancel non-invoice moves

Enables the EDI postprocessing method to cancel non-invoice moves.
This is useful for entry moves such as withholds in l10n_ec

X-original-commit: 1c515e1f55ea675df3f6aace7f6537889779779c
Part-of: odoo/odoo#113302
Co-authored-by: Josse Colpaert <jco@odoo.com>
This commit is contained in:
Stanislas Gueniffey
2023-03-31 15:52:17 +02:00
committed by Josse Colpaert
co-authored by Josse Colpaert
parent 6e03d2bd26
commit 6b031e7925
@@ -141,7 +141,7 @@ class AccountEdiDocument(models.Model):
attachments_to_unlink.unlink()
def _postprocess_cancel_edi_results(documents, edi_result):
invoice_ids_to_cancel = set() # Avoid duplicates
move_ids_to_cancel = set() # Avoid duplicates
attachments_to_unlink = self.env['ir.attachment']
for document in documents:
move = document.move_id
@@ -155,10 +155,10 @@ class AccountEdiDocument(models.Model):
'blocking_level': False,
})
if move.is_invoice(include_receipts=True) and move.state == 'posted':
if move.state == 'posted':
# The user requested a cancellation of the EDI and it has been approved. Then, the invoice
# can be safely cancelled.
invoice_ids_to_cancel.add(move.id)
move_ids_to_cancel.add(move.id)
if not old_attachment.res_model or not old_attachment.res_id:
attachments_to_unlink |= old_attachment
@@ -169,8 +169,8 @@ class AccountEdiDocument(models.Model):
'blocking_level': move_result.get('blocking_level', DEFAULT_BLOCKING_LEVEL) if move_result.get('error') else False,
})
if invoice_ids_to_cancel:
invoices = self.env['account.move'].browse(list(invoice_ids_to_cancel))
if move_ids_to_cancel:
invoices = self.env['account.move'].browse(list(move_ids_to_cancel))
invoices.button_draft()
invoices.button_cancel()