~openerp-commiter/openobject-client-kde/pos_fiscal_ve

« back to all changes in this revision

Viewing changes to Koo/Dialogs/FormWidget.py

  • Committer: Albert Cervera i Areny
  • Date: 2011-01-02 18:50:12 UTC
  • Revision ID: albert@nan-tic.com-20110102185012-oc598jslgmst1fbs
[IMP] In FormWidget.py, allow duplicating several records at once, just like we do in one2many fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
338
338
                self.screen.new()
339
339
        
340
340
        def duplicate(self):
 
341
                # Store selected ids before executing modifiedSave() because, there, the selection is lost.
 
342
                selectedIds = self.screen.selectedIds()
 
343
 
341
344
                if not self.modifiedSave():
342
345
                        return
343
 
                res_id = self.screen.currentId()
344
 
                new_id = Rpc.session.execute('/object', 'execute', self.model, 'copy', res_id, {}, Rpc.session.context)
345
 
                self.screen.load( [new_id], self.screen.addOnTop() )
 
346
 
 
347
                QApplication.setOverrideCursor( Qt.WaitCursor )
 
348
 
 
349
                # Duplicate all selected records but, remember the ID of the copy of the 
 
350
                # currently selected record
 
351
                newId = None
 
352
                newIds = []
 
353
                currentId = self.screen.currentId()
 
354
                for id in selectedIds:
 
355
                        copyId = Rpc.session.execute('/object', 'execute', self.model, 'copy', id, {}, Rpc.session.context)
 
356
                        newIds.append( copyId )
 
357
                        if id == currentId:
 
358
                                newId = copyId
 
359
 
 
360
                # Ensure the copy of the currently selected ID is the first of the list
 
361
                # so it will be the current one, once loaded by screen.
 
362
                if newId in newIds:
 
363
                        newIds.remove( newId )
 
364
                        newIds.insert(0, newId)
 
365
 
 
366
                self.screen.load( newIds, self.screen.addOnTop() )
346
367
                self.updateStatus(_('<font color="orange">Working now on the duplicated document</font>'))
 
368
                QApplication.restoreOverrideCursor()
347
369
 
348
370
        def save(self):
349
371
                if not self.screen.currentRecord():