Merge lp:~openerp-dev/openobject-addons/6.0-opw-50710-xal into lp:openobject-addons/6.0

Proposed by Xavier ALT
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/6.0-opw-50710-xal
Merge into: lp:openobject-addons/6.0
Diff against target: 66 lines (+22/-1)
4 files modified
account/invoice.py (+9/-0)
purchase/purchase.py (+7/-1)
purchase/purchase_view.xml (+1/-0)
purchase/purchase_workflow.xml (+5/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.0-opw-50710-xal
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+113961@code.launchpad.net

Description of the change

Hi,

This fix some problem with Purchase Order workflow and draft Invoice.

Steps:
- Create a Purchase Order (Invoicing method = From Order) and add some lines
- Confirm it.
- check and delete the draft invoice associated with the PO.

Current: - PO stay in "approved"
         - We have no way to re-create the invoice

Expected: - PO should switch to "Invoice Exception" (like standard invoice cancellation)
          - We should have a way to re-create invoice without doing it manually

This MP do:
- invoice: force workflow transition to "cancel" before unlink
           (so subflow.cancel is correctly triggered on PO - and PO switch to "Invoice Exception")
- purchase: add a transition from "invoice_except" to "invoice" + corresponding button in the view.
            (So user can re-create the invoice like it's done uppon 'approval')
- purchase: on invoice creation, force order state to "Approved" in case it's in "Invoice Exception".

Regards,
Xavier

To post a comment you must log in.

Unmerged revisions

5288. By Xavier ALT

[FIX] purchase: on 'Invoice Exception', allow to re-create invoice using PO method

 - When Purchase Order state is ``Invoice Exception`` and PO invoicing method
   is 'From Order' there is not way to re-create the invoice - like it's done
   by PO uppon 'approval'.

   So we add a workflow transition from 'except_invoice' to 'invoice' to allow
   re-creation of invoice and the corresponding button into purchase order view.

5287. By Xavier ALT

[FIX] account: force invoice transition to cancel before really unlinking them

 - when deleting 'draft' invoices, we have to force transition to 'cancel'
   before deleting them, otherwise workflow waiting on account.invoice
   ``subflow.cancel`` will never be trigger (ex: related PO will never switch
   to 'Invoice Exception' state)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/invoice.py'
2--- account/invoice.py 2012-03-16 16:47:19 +0000
3+++ account/invoice.py 2012-07-09 11:58:22 +0000
4@@ -374,6 +374,15 @@
5 unlink_ids.append(t['id'])
6 else:
7 raise osv.except_osv(_('Invalid action !'), _('Cannot delete invoice(s) that are already opened or paid !'))
8+ # TODO: temporary fix in 6.0, remove this in later version when subflows support
9+ # automatically sending subflow.delete upon deletion
10+ wf_service = netsvc.LocalService("workflow")
11+ for id in unlink_ids:
12+ wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
13+ # force removal on concurrency-check field from context because
14+ # system will raise an error if record was modified by workflow
15+ if context and unlink_ids:
16+ context.pop(self.CONCURRENCY_CHECK_FIELD, None)
17 osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
18 return True
19
20
21=== modified file 'purchase/purchase.py'
22--- purchase/purchase.py 2012-06-29 14:14:29 +0000
23+++ purchase/purchase.py 2012-07-09 11:58:22 +0000
24@@ -401,7 +401,13 @@
25 inv_id = self.pool.get('account.invoice').create(cr, uid, inv, {'type':'in_invoice', 'journal_type': 'purchase'})
26 self.pool.get('account.invoice').button_compute(cr, uid, [inv_id], {'type':'in_invoice'}, set_total=True)
27 self.pool.get('purchase.order.line').write(cr, uid, todo, {'invoiced':True})
28- self.write(cr, uid, [o.id], {'invoice_ids': [(4, inv_id)]})
29+
30+ order_values = {'invoice_ids': [(4, inv_id)]}
31+ # If order is in 'Invoice Exception' state, reset it to correct state
32+ # after invoice creation (=> Approved)
33+ if o.state == 'except_invoice':
34+ order_values['state'] = 'approved'
35+ self.write(cr, uid, [o.id], order_values)
36 res = inv_id
37 return res
38
39
40=== modified file 'purchase/purchase_view.xml'
41--- purchase/purchase_view.xml 2012-03-06 10:24:05 +0000
42+++ purchase/purchase_view.xml 2012-07-09 11:58:22 +0000
43@@ -192,6 +192,7 @@
44 <button name="action_cancel" states="approved,except_picking,except_invoice,wait" string="Cancel Purchase Order" type="object" icon="gtk-cancel"/>
45 <button name="picking_ok" states="except_picking" string="Manually Corrected" icon="gtk-convert"/>
46 <button name="invoice_ok" states="except_invoice" string="Manually Corrected" icon="gtk-convert"/>
47+ <button name="invoice_recreate" states="except_invoice" string="Recreate Invoice" icon="gtk-go-forward"/>
48 <button name="purchase_confirm" states="draft" string="Convert to Purchase Order" icon="gtk-go-forward"/>
49 <button name="purchase_appbuyer" states="wait_auth" string="Approve Purchase" icon="gtk-ok"/>
50 <button name="purchase_approve" states="confirmed" string="Approved" icon="gtk-go-forward"/>
51
52=== modified file 'purchase/purchase_workflow.xml'
53--- purchase/purchase_workflow.xml 2011-01-14 00:11:01 +0000
54+++ purchase/purchase_workflow.xml 2012-07-09 11:58:22 +0000
55@@ -135,6 +135,11 @@
56 <field name="act_to" ref="act_invoice_done"/>
57 <field name="signal">invoice_ok</field>
58 </record>
59+ <record id="trans_except_invoice_invoice_recreate" model="workflow.transition">
60+ <field name="act_from" ref="act_except_invoice"/>
61+ <field name="act_to" ref="act_invoice"/>
62+ <field name="signal">invoice_recreate</field>
63+ </record>
64 <record id="trans_except_picking" model="workflow.transition">
65 <field name="act_from" ref="act_except_picking"/>
66 <field name="act_to" ref="act_cancel"/>