Skip to content

Commit

Permalink
[FIX] Allow to cancel an expense
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher authored and Stefan Rijnhart committed Jul 2, 2014
1 parent de1def6 commit 8457e36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions addons/hr_expense/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ def compute_expense_totals(self, cr, uid, exp, company_currency, ref, account_mo
total_currency -= i['amount_currency'] or i['price']
return total, total_currency, account_move_lines

def action_expense_cancel(self, cr, uid, ids, context=None):
## We will first check the the move is not reconciled
for expense in self.browse(cr, uid, ids, context=context):
if expense.account_move_id:
for move_line in expense.account_move_id.line_id:
if move_line.reconcile_id or move_line.reconcile_partial_id:
raise osv.except_osv(
_('Error!'),
_('Please unreconcile payment accounting entries before cancelling this expense'))
### Then we unlink the move line
self.pool.get('account.move').unlink(cr, uid, [expense.account_move_id.id], context=context)
wf_service = netsvc.LocalService("workflow")
wf_service.trg_delete(uid, 'hr.expense.expense', expense.id, cr)
wf_service.trg_create(uid, 'hr.expense.expense', expense.id, cr)
wf_service.trg_validate(uid, 'hr.expense.expense', expense.id, 'draft', cr)

return True


def action_receipt_create(self, cr, uid, ids, context=None):
'''
Expand Down
1 change: 1 addition & 0 deletions addons/hr_expense/hr_expense_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<button name="refuse" states="confirm,accepted" string="Refuse" type="workflow" groups="base.group_hr_user" />
<button name="draft" states="confirm,cancelled" string="Set to Draft" type="workflow" groups="base.group_hr_user" />
<button name="done" states="accepted" string="Generate Accounting Entries" type="workflow" groups="account.group_account_invoice" class="oe_highlight"/>
<button name="action_expense_cancel" states="done,paid" string="Cancel Expense" type="object" />
<button name="action_view_receipt" states="done" string="Open Accounting Entries" type="object" groups="account.group_account_invoice"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,accepted,done,paid" statusbar_colors='{"confirm":"blue","cancelled":"red"}'/>
</header>
Expand Down

0 comments on commit 8457e36

Please sign in to comment.