Comment 26 for bug 865854

Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

If you need to clean your existing data paste this in your code in the class account_voucher and lauch it.
It will search for the existing refunf payment, cancel it, back to draft, change the sign and validate it.

    def fix_refund(self, cr, uid, ids=None, context=None):
        inv_obj = self.pool.get('account.invoice')
        invoice_ids = inv_obj.search(cr, uid, [['type', '=', 'out_refund']], context=context)
        for invoice in inv_obj.browse(cr, uid, invoice_ids, context=context):
            if invoice.reconciled:
                payment_id = invoice.payment_ids[0].id
                voucher_id = self.search(cr, uid, [['move_ids', '=', payment_id]])
                if voucher_id:
                    voucher = self.browse(cr, uid, voucher_id[0], context=context)
                    if voucher.amount > 0:
                        print '>>> CLEAN VOUCHER %s ====='%voucher.number
                        voucher.cancel_voucher()
                        voucher.action_cancel_draft()
                        voucher.write({
                            'amount': - voucher.amount,
                        })
                        wf_service = netsvc.LocalService("workflow")
                        wf_service.trg_validate(
                            uid, 'account.voucher', voucher.id, 'proforma_voucher', cr)
                        cr.commit()
                        print '<<< CLEAN VOUCHER DONE %s ====='%voucher.number
        return True