From e680f29560ac20133c7af0c6364c6ef494662eac Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 25 Apr 2016 14:11:47 +0200 Subject: [PATCH 1/2] [FIX] account, sale: modify invoice When a user validates an invoice linked to a SO, he might want to modify it afterwards thanks to the 'Modify' option in the refund wizard. This will create a refund, reconcile and create a draft invoice. The issue is that the draft invoice is not linked with the SO. The fix is to link, in this specific case only, the draft invoice to the SO. At the same time, we have to make sure to: - unlink the first invoice (to prevent counting the quantity as invoiced in the SO) - keep track of the first invoice/refund in the invoice list of the SO opw-673446 --- addons/account/wizard/account_invoice_refund.py | 2 +- addons/sale/sale.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/account/wizard/account_invoice_refund.py b/addons/account/wizard/account_invoice_refund.py index 226b3e711f8..638b0e1fc1e 100644 --- a/addons/account/wizard/account_invoice_refund.py +++ b/addons/account/wizard/account_invoice_refund.py @@ -87,7 +87,7 @@ class AccountInvoiceRefund(models.TransientModel): invoice = invoice[0] del invoice['id'] invoice_lines = inv_line_obj.browse(invoice['invoice_line_ids']) - invoice_lines = inv_obj._refund_cleanup_lines(invoice_lines) + invoice_lines = inv_obj.with_context(mode='modify')._refund_cleanup_lines(invoice_lines) tax_lines = inv_tax_obj.browse(invoice['tax_line_ids']) tax_lines = inv_obj._refund_cleanup_lines(tax_lines) invoice.update({ diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 02b00c9680c..3bea2419718 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -52,6 +52,9 @@ class SaleOrder(models.Model): """ for order in self: invoice_ids = order.order_line.mapped('invoice_lines').mapped('invoice_id') + # Search for invoices which have been 'cancelled' (filter_refund = 'modify' in + # 'account.invoice.refund') + invoice_ids |= invoice_ids.search([('origin', 'like', order.name)]) # Search for refunds as well refund_ids = self.env['account.invoice'].browse() if invoice_ids: @@ -835,6 +838,16 @@ class AccountInvoice(models.Model): order.message_post(body=_("Invoice %s paid") % (name)) return res + @api.model + def _refund_cleanup_lines(self, lines): + result = super(AccountInvoice, self)._refund_cleanup_lines(lines) + if self.env.context.get('mode') == 'modify': + for i in xrange(0, len(lines)): + for name, field in lines[i]._fields.iteritems(): + if name == 'sale_line_ids': + result[i][2][name] = [(6, 0, lines[i][name].ids)] + lines[i][name] = False + return result class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' From e24888205375ecf6d6ad2832ce7cbaee0c5edf89 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Mon, 25 Apr 2016 16:26:04 +0200 Subject: [PATCH 2/2] [FIX] base: fetch mimetype on ir.attachment for binary fields --- openerp/addons/base/ir/ir_http.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openerp/addons/base/ir/ir_http.py b/openerp/addons/base/ir/ir_http.py index 72e66e24c33..5148b11c8d8 100644 --- a/openerp/addons/base/ir/ir_http.py +++ b/openerp/addons/base/ir/ir_http.py @@ -300,6 +300,10 @@ class ir_http(osv.AbstractModel): mimetype = obj.mimetype elif filename: mimetype = mimetypes.guess_type(filename)[0] + elif getattr(env[model]._fields[field], 'attachment', False): + # for binary fields, fetch the ir_attachement for mimetype check + attach_mimetype = env['ir.attachment'].search_read(domain=[('res_model', '=', model), ('res_id', '=', id), ('res_field', '=', field)], fields=['mimetype'], limit=1) + mimetype = attach_mimetype and attach_mimetype[0]['mimetype'] if not mimetype: mimetype = default_mimetype headers.append(('Content-Type', mimetype))