[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
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user