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
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): get('account. invoice' )
payment_ id = invoice. payment_ ids[0]. id
voucher_ id = self.search(cr, uid, [['move_ids', '=', payment_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
inv_obj = self.pool.
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:
if voucher_id:
return True