[FIX] sale: trigger signal manual invoice for make invoices wizard (not advance)
authorDenis Ledoux <dle@openerp.com>
Mon, 24 Mar 2014 10:34:27 +0000 (11:34 +0100)
committerDenis Ledoux <dle@openerp.com>
Mon, 24 Mar 2014 10:34:27 +0000 (11:34 +0100)
bzr revid: dle@openerp.com-20140324103427-yckncrnynvs5si8i

addons/sale/wizard/sale_make_invoice.py

index 4771601..4405349 100644 (file)
@@ -20,6 +20,7 @@
 
 from openerp.osv import fields, osv
 from openerp.tools.translate import _
+from openerp import netsvc
 
 class sale_make_invoice(osv.osv_memory):
     _name = "sale.make.invoice"
@@ -46,6 +47,7 @@ class sale_make_invoice(osv.osv_memory):
         order_obj = self.pool.get('sale.order')
         mod_obj = self.pool.get('ir.model.data')
         act_obj = self.pool.get('ir.actions.act_window')
+        wf_service = netsvc.LocalService("workflow")
         newinv = []
         if context is None:
             context = {}
@@ -55,11 +57,13 @@ class sale_make_invoice(osv.osv_memory):
                 raise osv.except_osv(_('Warning!'), _("You shouldn't manually invoice the following sale order %s") % (sale_order.name))
 
         order_obj.action_invoice_create(cr, uid, context.get(('active_ids'), []), data['grouped'], date_invoice=data['invoice_date'])
-
-        for o in order_obj.browse(cr, uid, context.get(('active_ids'), []), context=context):
+        orders = order_obj.browse(cr, uid, context.get(('active_ids'), []), context=context)
+        for o in orders:
             for i in o.invoice_ids:
                 newinv.append(i.id)
-
+        # Dummy call to workflow, will not create another invoice but bind the new invoice to the subflow
+        for id in [o.id for o in orders if o.order_policy == 'manual']:
+            wf_service.trg_validate(uid, 'sale.order', id, 'manual_invoice', cr)
         result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree1')
         id = result and result[1] or False
         result = act_obj.read(cr, uid, [id], context=context)[0]