[FIX] mail,account_edi: fix creation of invoice upon email reception
When receiving an email on a mailbox with an alias that triggers the creation of invoices, 4 bugs could occur. 1. If the xml received contains replacement characters (U+FFFD �), and the charset of the part of the email is "US-ASCII" the encoding of the string will fail, preventing the rest of the flow to be completed. Be more resilient, encode the string and ignores these characters if this case occurs. NB: sometimes, the charset is omitted for a Content-type: text/xml. This is valid but not recommended (see: https://www.ietf.org/rfc/rfc2376.txt). In this case, the default used is "US-ASCII". This means that any non-ascii char will be lost (they are replaced by the replacement character: �, see: https://github.com/python/cpython/blob/3.10/Lib/email/contentmanager.py#L67 ) when decoding the attachment. 2. When the xml attachment is created in Odoo, the mimetype is 'text/plain' (rather than 'application/xml'). Thus, the `_decode_attachment` needs to be more flexible when guessing the type of the attachment (to know which function to use to read the content of the attachment and create the invoice). 3. When creating an invoice from an email with an xml attachment, the xml is attached as the `message_main_attachment_id`. It's only later on that the content of the xml is read and we possibly find the PDF in base64 inside. When creating the PDF attachment, it was not set as the `message_main_attachment_id`, so the PDF was not rendered on the right part of the invoice form view. Add a clause to replace the `message_main_attachment_id` in such a case. 4. When the xml attachment represents a credit note, the move_type of the invoice created by the email alias needs to be changed. Indeed, the invoice is created before decoding the attachment, so we can only change the `move_type` later. opw-3144519 opw-3149649 closes odoo/odoo#119602 Signed-off-by:Laurent Smet <las@odoo.com>
Showing
- addons/account_edi/models/account_edi_format.py 3 additions, 3 deletionsaddons/account_edi/models/account_edi_format.py
- addons/account_edi_ubl_cii/models/account_edi_common.py 16 additions, 2 deletionsaddons/account_edi_ubl_cii/models/account_edi_common.py
- addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py 15 additions, 0 deletions...s/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py
- addons/mail/models/mail_thread.py 4 additions, 1 deletionaddons/mail/models/mail_thread.py
- addons/test_mail/data/test_mail_data.py 50 additions, 0 deletionsaddons/test_mail/data/test_mail_data.py
- addons/test_mail/tests/test_mail_gateway.py 21 additions, 0 deletionsaddons/test_mail/tests/test_mail_gateway.py
Loading