[FIX] Merged Borja's branch for correction on Invoice correctd workflow action of sale order

lp bug: https://launchpad.net/bugs/574348 fixed

bzr revid: jvo@tinyerp.com-20100929154627-f7l6ej8qbteh38cq
This commit is contained in:
Borja (Pexego) 2010-09-29 21:16:27 +05:30 committed by Jay (OpenERP)
parent 6e8fd319e6
commit d3a5d4fad5
1 changed files with 35 additions and 12 deletions

View File

@ -503,30 +503,53 @@ class sale_order(osv.osv):
def action_invoice_cancel(self, cr, uid, ids, context=None):
if context is None:
context = {}
for sale in self.browse(cr, uid, ids, context=context):
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=None):
if context is None:
context = {}
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)
return True
def action_cancel(self, cr, uid, ids, context=None):