~ubuntu-branches/ubuntu/oneiric/openerp-server/oneiric

« back to all changes in this revision

Viewing changes to bin/addons/sale/sale.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2011-01-01 09:45:38 UTC
  • mfrom: (19.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110101094538-lg37tzn110haohp6
Tags: 5.0.15-2
* Removing README.source and headers in copyright file.
* Removing vcs fields.
* Updating year in copyright file.
* Orphaning package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
450
450
                    cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res))
451
451
        return res
452
452
 
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:
 
456
                #
 
457
                # Check if the line is invoiced (has asociated invoice
 
458
                # lines from non-cancelled invoices).
 
459
                #
456
460
                invoiced = False
457
461
                for iline in line.invoice_lines:
458
 
                    if iline.invoice_id and iline.invoice_id.state == 'cancel':
459
 
                        continue
460
 
                    else:
 
462
                    if iline.invoice_id and iline.invoice_id.state != 'cancel':
461
463
                        invoiced = True
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})
 
464
                        break
 
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)
464
469
        return True
465
470
    
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):
 
473
            #
 
474
            # Update the sale order lines state (and invoiced flag).
 
475
            #
468
476
            for line in order.order_line:
 
477
                vals = {}
 
478
                #
 
479
                # Check if the line is invoiced (has asociated invoice
 
480
                # lines from non-cancelled invoices).
 
481
                #
 
482
                invoiced = False
 
483
                for iline in line.invoice_lines:
 
484
                    if iline.invoice_id and iline.invoice_id.state != 'cancel':
 
485
                        invoiced = True
 
486
                        break
 
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)
471
 
            
 
491
                    vals['state'] = 'confirmed'
 
492
                # Update the line (only when needed).
 
493
                if vals:
 
494
                    self.pool.get('sale.order.line').write(cr, uid, [line.id], vals, context=context)
 
495
            #
 
496
            # Update the sale order state.
 
497
            #
472
498
            if order.state == 'invoice_except':
473
499
                self.write(cr, uid, [order.id], {'state' : 'progress'}, context=context)
474
500