[FIX] Merged Borja's branch for correction on Invoice correctd workflow action of...
authorBorja (Pexego) <>
Wed, 29 Sep 2010 15:15:23 +0000 (20:45 +0530)
committerJay (OpenERP) <jvo@tinyerp.com>
Wed, 29 Sep 2010 15:15:23 +0000 (20:45 +0530)
lp bug: https://launchpad.net/bugs/574348 fixed

bzr revid: jvo@tinyerp.com-20100929151523-mpryy13k92r1mwvr

1  2 
addons/purchase_manual/purchase_manual.py
addons/sale/sale.py

@@@ -57,7 -57,7 +57,6 @@@ purchase_order_line(
  class purchase_order(osv.osv):
      _inherit='purchase.order'
      def action_invoice_create(self, cr, uid, ids, context={}):
--        print 'Invoice Create'
          res = super(purchase_order, self).action_invoice_create(cr, uid, ids, context)
          for po in self.browse(cr, uid, ids, context):
              todo = []
@@@ -75,4 -75,4 +74,9 @@@
                      todo.append(line.id)
          self.pool.get('purchase.order.line').action_confirm(cr, uid, todo, context)
          return res
++    _columns = {
++        'name': fields.char('Order SDER', size=64, required=True, select=True,
++readonly=True)
++        
++                }
  purchase_order()
@@@ -450,25 -445,49 +450,51 @@@ class sale_order(osv.osv)
                      cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res))
          return res
  
-     def action_invoice_cancel(self, cr, uid, ids, context={}):
+     def action_invoice_cancel(self, cr, uid, ids, context=None):
          for sale in self.browse(cr, uid, ids):
              for line in sale.order_line:
+                 #
+                 # Check if the line is invoiced (has asociated invoice
+                 # lines from non-cancelled invoices).
+                 #
                  invoiced = False
                  for iline in line.invoice_lines:
-                     if iline.invoice_id and iline.invoice_id.state == 'cancel':
-                         continue
-                     else:
+                     if iline.invoice_id and iline.invoice_id.state != 'cancel':
                          invoiced = True
-                 self.pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced': invoiced})
-         self.write(cr, uid, ids, {'state': 'invoice_except', 'invoice_ids': False})
++                        break
+                 # Update the line (only when needed)
+                 if line.invoiced != invoiced:
+                     self.pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced': invoiced}, context=context)
+         self.write(cr, uid, ids, {'state': 'invoice_except', 'invoice_ids': False}, context=context)
          return True
      
-     def action_invoice_end(self, cr, uid, ids, context={}):
+     def action_invoice_end(self, cr, uid, ids, context=None):
          for order in self.browse(cr, uid, ids, context=context):
+             #
+             # Update the sale order lines state (and invoiced flag).
+             #
              for line in order.order_line:
+                 vals = {}
+                 #
+                 # Check if the line is invoiced (has asociated invoice
+                 # lines from non-cancelled invoices).
+                 #
+                 invoiced = False
+                 for iline in line.invoice_lines:
+                     if iline.invoice_id and iline.invoice_id.state != 'cancel':
+                         invoiced = True
++                        break
+                 if line.invoiced != invoiced:
+                     vals['invoiced'] = invoiced
+                 # If the line was in exception state, now it gets confirmed.
                  if line.state == 'exception':
-                     self.pool.get('sale.order.line').write(cr, uid, [line.id], {'state': 'confirmed'}, context=context)
-             
+                     vals['state'] = 'confirmed'
+                 # Update the line (only when needed).
+                 if vals:
+                     self.pool.get('sale.order.line').write(cr, uid, [line.id], vals, context=context)
+             #
+             # Update the sale order state.
+             #
              if order.state == 'invoice_except':
                  self.write(cr, uid, [order.id], {'state' : 'progress'}, context=context)