From fba274f8d16fea05214d8f79daf19abf046458ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nshimiyimana=20S=C3=A9na?= Date: Mon, 13 Feb 2023 15:07:25 +0000 Subject: [PATCH] [FIX] l10n_it_edi: fix uploading Fattura PA XML bill with documents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Steps to reproduce * install account_accountant, documents and l10n_it_edi * Switch to an Italian company * go to Documents > Configuration > Workspaces and create a new workspace `W` and it's child `W1` * under Documents > Settings, activate Accounting and set `Workspace`to `W` * save and go back to Documents > Settings, and click `Journals` under 'Accounting' * add a line with Journals = 'Vendor Bills' and Workspace = `W1` * go to Accounting > Vendor > Bills and upload a Fattura PA XML bill * now open the newly generated bill You should see that the chatter does not load. # Cause When uploading a Fattura PA XML bill, a PDF attachment is created and added to the chatter. The issue is happening because the `ir.attachment` record ends up in an invalid state where its 'res_model' field is false. The 'res_model' field is actually defined when the attachment is initially created. However, that value ends up being overwritten when a related `documents.document` is created here: https://github.com/odoo/enterprise/blob/3f53e50989fbb9551565429aede7c0a1e4d6e5a4/documents_account/models/account_move.py#L88 Because of the following line, that `documents.document` will be assigned a default `res_id` (but no `res_model`). https://github.com/odoo/odoo/blob/26b2cbd4e5c73ea66456a91ea9cb36d6b174cae7/addons/l10n_it_edi/models/account_edi_format.py#L767 However, setting `res_id` (or `res_model`) on a `documents.document` will also overwrite the related attachments' values (in this case, the attachment's `res_model` is set to false because the document's `res_model` is false). This behavior happens because of this inverse compute: https://github.com/odoo/enterprise/blob/b4201e6b422e5b0bde1f04db37bcda4941d0665f/documents/models/document.py#L97-L104 opw-3119669 closes odoo/odoo#113299 X-original-commit: 6839abc79a947e30750ec535058828c190c18955 Signed-off-by: Josse Colpaert Signed-off-by: Nshimiyimana Serge Séna (sesn) --- addons/l10n_it_edi/models/account_edi_format.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/l10n_it_edi/models/account_edi_format.py b/addons/l10n_it_edi/models/account_edi_format.py index dd8da4bd7a6..0f76a8e0b7e 100644 --- a/addons/l10n_it_edi/models/account_edi_format.py +++ b/addons/l10n_it_edi/models/account_edi_format.py @@ -700,9 +700,8 @@ class AccountEdiFormat(models.Model): 'res_id': new_invoice.id, }) - # default_res_id is had to context to avoid facturx to import his content # no_new_invoice to prevent from looping on the message_post that would create a new invoice without it - new_invoice.with_context(no_new_invoice=True, default_res_id=new_invoice.id).message_post( + new_invoice.with_context(no_new_invoice=True).message_post( body=(_("Attachment from XML")), attachment_ids=[attachment_64.id] )