summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2020-08-31 14:44:34 +0000
committerLaurent Smet <las@odoo.com>2020-09-01 07:22:13 +0000
commitea1a690d9859eca7df478a6b4de3ed704f13e0f8 (patch)
tree053fe28e23636f077d66b3d4720fceafe820ca8c /addons
parentcd668909f578a7bbe87ab5e6f73df82855809c3b (diff)
[FIX] account_edi(_facturx): Don't spam the chatter with xmls
When using FacturX, the user shouldn't see any XML. Indeed, the XMLs are embedded inside the PDF. Then, this is confusing to see all this XML attachments directly in the chatter. To avoid that, FacturX is now creating the attachments without any link to the account.move. Also, when reseting to draft/post multi-times, the old attachments are unlinked because if we want to retrieve it, we could look directly inside the old PDFs. closes odoo/odoo#56818 Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/account_edi/models/account_edi_document.py21
-rw-r--r--addons/account_edi_facturx/models/account_edi_format.py2
2 files changed, 19 insertions, 4 deletions
diff --git a/addons/account_edi/models/account_edi_document.py b/addons/account_edi/models/account_edi_document.py
index 9e5dd2fbfed..e3a858ffd53 100644
--- a/addons/account_edi/models/account_edi_document.py
+++ b/addons/account_edi/models/account_edi_document.py
@@ -74,35 +74,48 @@ class AccountEdiDocument(models.Model):
Invoices are processed before payments.
"""
def _postprocess_post_edi_results(documents, edi_result):
+ attachments_to_unlink = self.env['ir.attachment']
for document in documents:
move = document.move_id
move_result = edi_result.get(move, {})
if move_result.get('attachment'):
+ old_attachment = document.attachment_id
document.write({
'attachment_id': move_result['attachment'].id,
'state': 'sent',
'error': False,
})
+ if not old_attachment.res_model or not old_attachment.res_id:
+ attachments_to_unlink |= old_attachment
else:
document.error = move_result.get('error', _("Error when processing the journal entry."))
+ # Attachments that are not explicitly linked to a business model could be removed because they are not
+ # supposed to have any traceability from the user.
+ attachments_to_unlink.unlink()
+
def _postprocess_cancel_edi_results(documents, edi_result):
invoice_ids_to_cancel = set() # Avoid duplicates
+ attachments_to_unlink = self.env['ir.attachment']
for document in documents:
move = document.move_id
move_result = edi_result.get(move, {})
if move_result.get('success'):
+ old_attachment = document.attachment_id
document.write({
'state': 'cancelled',
'error': False,
'attachment_id': False,
})
- # The user requested a cancellation of the EDI and it has been approved. Then, the invoice
- # can be safely cancelled.
if move.is_invoice(include_receipts=True) and 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)
+ if not old_attachment.res_model or not old_attachment.res_id:
+ attachments_to_unlink |= old_attachment
+
else:
document.error = move_result.get('error') or _("Error when cancelling the journal entry.")
@@ -111,6 +124,10 @@ class AccountEdiDocument(models.Model):
invoices.button_draft()
invoices.button_cancel()
+ # Attachments that are not explicitly linked to a business model could be removed because they are not
+ # supposed to have any traceability from the user.
+ attachments_to_unlink.unlink()
+
test_mode = self._context.get('edi_test_mode', False)
# ==== Process invoices ====
diff --git a/addons/account_edi_facturx/models/account_edi_format.py b/addons/account_edi_facturx/models/account_edi_format.py
index ed2db035fee..d7a9483c2e8 100644
--- a/addons/account_edi_facturx/models/account_edi_format.py
+++ b/addons/account_edi_facturx/models/account_edi_format.py
@@ -112,8 +112,6 @@ class AccountEdiFormat(models.Model):
return self.env['ir.attachment'].create({
'name': xml_name,
'datas': base64.encodebytes(xml_content),
- 'res_model': 'account.move',
- 'res_id': invoice._origin.id,
'mimetype': 'application/xml'
})