Xavier ALT (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.0-opw-50710-xal into 
lp:openobject-addons/6.0.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-opw-50710-xal/+merge/113961

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
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-opw-50710-xal/+merge/113961
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.0-opw-50710-xal.
=== modified file 'account/invoice.py'
--- account/invoice.py	2012-03-16 16:47:19 +0000
+++ account/invoice.py	2012-07-09 11:58:22 +0000
@@ -374,6 +374,15 @@
                 unlink_ids.append(t['id'])
             else:
                 raise osv.except_osv(_('Invalid action !'), _('Cannot delete invoice(s) that are already opened or paid !'))
+        # TODO: temporary fix in 6.0, remove this in later version when subflows support
+        # automatically sending subflow.delete upon deletion
+        wf_service = netsvc.LocalService("workflow")
+        for id in unlink_ids:
+            wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr)
+        # force removal on concurrency-check field from context because
+        # system will raise an error if record was modified by workflow
+        if context and unlink_ids:
+            context.pop(self.CONCURRENCY_CHECK_FIELD, None)
         osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
         return True
 

=== modified file 'purchase/purchase.py'
--- purchase/purchase.py	2012-06-29 14:14:29 +0000
+++ purchase/purchase.py	2012-07-09 11:58:22 +0000
@@ -401,7 +401,13 @@
             inv_id = self.pool.get('account.invoice').create(cr, uid, inv, {'type':'in_invoice', 'journal_type': 'purchase'})
             self.pool.get('account.invoice').button_compute(cr, uid, [inv_id], {'type':'in_invoice'}, set_total=True)
             self.pool.get('purchase.order.line').write(cr, uid, todo, {'invoiced':True})
-            self.write(cr, uid, [o.id], {'invoice_ids': [(4, inv_id)]})
+
+            order_values = {'invoice_ids': [(4, inv_id)]}
+            # If order is in 'Invoice Exception' state, reset it to correct state
+            # after invoice creation (=> Approved)
+            if o.state == 'except_invoice':
+                order_values['state'] = 'approved'
+            self.write(cr, uid, [o.id], order_values)
             res = inv_id
         return res
 

=== modified file 'purchase/purchase_view.xml'
--- purchase/purchase_view.xml	2012-03-06 10:24:05 +0000
+++ purchase/purchase_view.xml	2012-07-09 11:58:22 +0000
@@ -192,6 +192,7 @@
                                 <button name="action_cancel" states="approved,except_picking,except_invoice,wait" string="Cancel Purchase Order" type="object" icon="gtk-cancel"/>
                                 <button name="picking_ok" states="except_picking" string="Manually Corrected" icon="gtk-convert"/>
                                 <button name="invoice_ok" states="except_invoice" string="Manually Corrected" icon="gtk-convert"/>
+                                <button name="invoice_recreate" states="except_invoice" string="Recreate Invoice" icon="gtk-go-forward"/>
                                 <button name="purchase_confirm" states="draft" string="Convert to Purchase Order" icon="gtk-go-forward"/>
                                 <button name="purchase_appbuyer" states="wait_auth" string="Approve Purchase" icon="gtk-ok"/>
                                 <button name="purchase_approve" states="confirmed" string="Approved" icon="gtk-go-forward"/>

=== modified file 'purchase/purchase_workflow.xml'
--- purchase/purchase_workflow.xml	2011-01-14 00:11:01 +0000
+++ purchase/purchase_workflow.xml	2012-07-09 11:58:22 +0000
@@ -135,6 +135,11 @@
             <field name="act_to" ref="act_invoice_done"/>
             <field name="signal">invoice_ok</field>
         </record>
+        <record id="trans_except_invoice_invoice_recreate" model="workflow.transition">
+            <field name="act_from" ref="act_except_invoice"/>
+            <field name="act_to" ref="act_invoice"/>
+            <field name="signal">invoice_recreate</field>
+        </record>
         <record id="trans_except_picking" model="workflow.transition">
             <field name="act_from" ref="act_except_picking"/>
             <field name="act_to" ref="act_cancel"/>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to