From 1491cbd2d02fcaaf99d9461e590dc3dbce61e73c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 20 Dec 2018 11:20:31 +0100 Subject: [PATCH] Add script fix_invoice_attachment_filename --- account_usability/account.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/account_usability/account.py b/account_usability/account.py index 1d78c7b..3f3eff4 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -121,6 +121,30 @@ class AccountInvoice(models.Model): lines.unlink() return True + def fix_invoice_attachment_filename(self): + # This script is designed to fix attachment of invoices + # badly generated by Odoo v8. I found this problem in Nov 2018 at + # Encres Dubuit when investigating a bug where Odoo would create a + # new attachment when printing an old invoice that already had the + # PDF of the invoice as attachment + logger.info('START fix customer invoice attachment filename') + # Run this script as admin to fix problem in all companies + self = self.sudo() + attachs = self.env['ir.attachment'].search([ + ('res_model', '=', 'account.invoice'), + ('res_id', '!=', False), + ('type', '=', 'binary'), + ('name', '=like', 'INV%.pdf'), + ('datas_fname', '=like', 'INV%.pdf.pdf')]) + for attach in attachs: + inv = self.browse(attach.res_id) + if inv.type in ('out_invoice', 'out_refund'): + attach.datas_fname = attach.name + logger.info( + 'Fixed field datas_fname of attachment ID %s name %s', + attach.id, attach.name) + logger.info('END fix customer invoice attachment filename') + class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line'