450
450
cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res))
453
def action_invoice_cancel(self, cr, uid, ids, context={}):
453
def action_invoice_cancel(self, cr, uid, ids, context=None):
454
454
for sale in self.browse(cr, uid, ids):
455
455
for line in sale.order_line:
457
# Check if the line is invoiced (has asociated invoice
458
# lines from non-cancelled invoices).
457
461
for iline in line.invoice_lines:
458
if iline.invoice_id and iline.invoice_id.state == 'cancel':
462
if iline.invoice_id and iline.invoice_id.state != 'cancel':
462
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced': invoiced})
463
self.write(cr, uid, ids, {'state': 'invoice_except', 'invoice_ids': False})
465
# Update the line (only when needed)
466
if line.invoiced != invoiced:
467
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced': invoiced}, context=context)
468
self.write(cr, uid, ids, {'state': 'invoice_except', 'invoice_ids': False}, context=context)
466
def action_invoice_end(self, cr, uid, ids, context={}):
471
def action_invoice_end(self, cr, uid, ids, context=None):
467
472
for order in self.browse(cr, uid, ids, context=context):
474
# Update the sale order lines state (and invoiced flag).
468
476
for line in order.order_line:
479
# Check if the line is invoiced (has asociated invoice
480
# lines from non-cancelled invoices).
483
for iline in line.invoice_lines:
484
if iline.invoice_id and iline.invoice_id.state != 'cancel':
487
if line.invoiced != invoiced:
488
vals['invoiced'] = invoiced
489
# If the line was in exception state, now it gets confirmed.
469
490
if line.state == 'exception':
470
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'state': 'confirmed'}, context=context)
491
vals['state'] = 'confirmed'
492
# Update the line (only when needed).
494
self.pool.get('sale.order.line').write(cr, uid, [line.id], vals, context=context)
496
# Update the sale order state.
472
498
if order.state == 'invoice_except':
473
499
self.write(cr, uid, [order.id], {'state' : 'progress'}, context=context)