Merge lp:~camptocamp/openobject-addons/hr_expense_cancelling into lp:openobject-addons/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Needs review
Proposed branch: lp:~camptocamp/openobject-addons/hr_expense_cancelling
Merge into: lp:openobject-addons/7.0
Diff against target: 40 lines (+19/-0)
2 files modified
hr_expense/hr_expense.py (+18/-0)
hr_expense/hr_expense_view.xml (+1/-0)
To merge this branch: bzr merge lp:~camptocamp/openobject-addons/hr_expense_cancelling
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp (community) Approve
OpenERP Core Team Pending
Review via email: mp+177523@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :
review: Needs Fixing (code, no test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Made fixes

review: Approve

Unmerged revisions

9296. By Yannick Vaucher @ Camptocamp

[PEP8]

9295. By Yannick Vaucher @ Camptocamp

[FIX] add missing context

9294. By Yannick Vaucher @ Camptocamp

[FIX] call workflow even when account_move_id is not set

9293. By Yannick Vaucher @ Camptocamp

[IMP] remove trailing spaces

9292. By Vincent Renaville@camptocamp

[FIX] Allow to cancel an expense

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hr_expense/hr_expense.py'
2--- hr_expense/hr_expense.py 2013-05-22 17:49:45 +0000
3+++ hr_expense/hr_expense.py 2013-09-02 09:43:57 +0000
4@@ -227,6 +227,24 @@
5 total_currency -= i['amount_currency'] or i['price']
6 return total, total_currency, account_move_lines
7
8+ def action_expense_cancel(self, cr, uid, ids, context=None):
9+ ## We will first check the the move is not reconciled
10+ for expense in self.browse(cr, uid, ids, context=context):
11+ if expense.account_move_id:
12+ for move_line in expense.account_move_id.line_id:
13+ if move_line.reconcile_id or move_line.reconcile_partial_id:
14+ raise osv.except_osv(
15+ _('Error!'),
16+ _('Please unreconcile payment accounting entries before cancelling this expense'))
17+ ### Then we unlink the move line
18+ self.pool.get('account.move').unlink(cr, uid, [expense.account_move_id.id], context=context)
19+ wf_service = netsvc.LocalService("workflow")
20+ wf_service.trg_delete(uid, 'hr.expense.expense', expense.id, cr)
21+ wf_service.trg_create(uid, 'hr.expense.expense', expense.id, cr)
22+ wf_service.trg_validate(uid, 'hr.expense.expense', expense.id, 'draft', cr)
23+
24+ return True
25+
26
27 def action_receipt_create(self, cr, uid, ids, context=None):
28 '''
29
30=== modified file 'hr_expense/hr_expense_view.xml'
31--- hr_expense/hr_expense_view.xml 2013-07-02 13:14:56 +0000
32+++ hr_expense/hr_expense_view.xml 2013-09-02 09:43:57 +0000
33@@ -67,6 +67,7 @@
34 <button name="refuse" states="confirm,accepted" string="Refuse" type="workflow" groups="base.group_hr_user" />
35 <button name="draft" states="confirm,cancelled" string="Set to Draft" type="workflow" groups="base.group_hr_user" />
36 <button name="done" states="accepted" string="Generate Accounting Entries" type="workflow" groups="account.group_account_invoice" class="oe_highlight"/>
37+ <button name="action_expense_cancel" states="done,paid" string="Cancel Expense" type="object" />
38 <button name="action_view_receipt" states="done" string="Open Accounting Entries" type="object" groups="account.group_account_invoice"/>
39 <field name="state" widget="statusbar" statusbar_visible="draft,confirm,accepted,done,paid" statusbar_colors='{"confirm":"blue","cancelled":"red"}'/>
40 </header>