Skip to content

Instantly share code, notes, and snippets.

@umiphos
Last active April 22, 2019 21:58
Show Gist options
  • Save umiphos/329ecb31a176ec5b0b0282f16e10b274 to your computer and use it in GitHub Desktop.
Save umiphos/329ecb31a176ec5b0b0282f16e10b274 to your computer and use it in GitHub Desktop.
Forced cancellation of an invoice in odoo via server action
for rec in records:
move_id = rec.move_id
# move_id.line_ids.remove_move_reconcile()
update_posted_state = rec.journal_id.update_posted
rec.journal_id.write({'update_posted': True})
# move_id.button_cancel()
# This action will delete any move_id that we have
rec.action_cancel()
rec.write({'state': 'cancel'})
rec.write({'move_id': False})
if move_id.exists():
move_id.unlink()
# Uncomment this if you want to delete the invoice
#if rec:
# rec.unlink()
rec.journal_id.write({'update_posted': update_posted_state})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment