Changeset f6775f5 in rattail


Ignore:
Timestamp:
07/03/18 18:53:24 (2 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
b11ff75
Parents:
3f924b1
Message:

Add setup/teardown handler hooks when cloning a batch

also fix a small rowcount bug

Location:
rattail/batch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/handlers.py

    r3f924b1 rf6775f5  
    452452            del batch.data_rows[:]
    453453
     454    def setup_clone(self, oldbatch, progress=None):
     455        """
     456        Perform any setup (caching etc.) necessary for cloning batch.  Note
     457        that the ``oldbatch`` arg is the "old" batch, i.e. the one from which a
     458        clone is to be created.
     459        """
     460
     461    def teardown_clone(self, newbatch, progress=None):
     462        """
     463        Perform any teardown (cleanup etc.) necessary after cloning a batch.
     464        Note that the ``newbatch`` arg is the "new" batch, i.e. the one which
     465        was just created by cloning the old batch.
     466        """
     467
    454468    def clone(self, oldbatch, created_by, progress=None):
    455469        """
    456470        Clone the given batch as a new batch, and return the new batch.
    457471        """
     472        self.setup_clone(oldbatch, progress=progress)
    458473        batch_class = self.batch_model_class
    459474        batch_mapper = orm.class_mapper(batch_class)
     
    463478        newbatch.rowcount = 0
    464479        for name in batch_mapper.columns.keys():
    465             if name not in ('uuid', 'id', 'created', 'created_by_uuid', 'executed', 'executed_by_uuid'):
     480            if name not in ('uuid', 'id', 'created', 'created_by_uuid', 'rowcount', 'executed', 'executed_by_uuid'):
    466481                setattr(newbatch, name, getattr(oldbatch, name))
    467482
     
    481496
    482497        self.refresh_batch_status(newbatch)
     498        self.teardown_clone(newbatch, progress=progress)
    483499        return newbatch
    484500
     
    488504        newrow = row_class()
    489505        for name in row_mapper.columns.keys():
    490             if name not in ('uuid', 'batch_uuid'):
     506            if name not in ('uuid', 'batch_uuid', 'sequence'):
    491507                setattr(newrow, name, getattr(oldrow, name))
    492508        return newrow
  • rattail/batch/labels.py

    r3f924b1 rf6775f5  
    6060    setup_populate = setup
    6161    setup_refresh = setup
     62    setup_clone = setup
    6263
    6364    def make_batch(self, session, progress=None, **kwargs):
Note: See TracChangeset for help on using the changeset viewer.