Changeset - 398f93f7c390
[Not reviewed]
0 2 0
Lance Edgar (lance) - 7 years ago 2018-01-05 20:38:51
lance@edbob.org
Make `BatchHandler.execute_many()` responsible for setting execution details
2 files changed with 18 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rattail/batch/handheld.py
Show inline comments
 
@@ -2,7 +2,7 @@
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
@@ -34,6 +34,7 @@ from sqlalchemy import orm
 
from rattail.db import api, model
 
from rattail.batch import BatchHandler, get_batch_handler
 
from rattail.gpc import GPC
 
from rattail.time import make_utc
 
from rattail.wince import parse_batch_file as parse_wince_file
 

	
 

	
 
@@ -170,11 +171,20 @@ class HandheldBatchHandler(BatchHandler):
 
        return self.execute_many([batch], user=user, action=action, progress=progress, **kwargs)
 

	
 
    def execute_many(self, batches, user=None, action='make_inventory_batch', progress=None, **kwargs):
 
        batches = [batch for batch in batches if not batch.executed]
 
        if not batches:
 
            return True
 
        if action == 'make_inventory_batch':
 
            return self.make_inventory_batch(batches, user, progress=progress)
 
            result = self.make_inventory_batch(batches, user, progress=progress)
 
        elif action == 'make_label_batch':
 
            return self.make_label_batch(batches, user, progress=progress)
 
            result = self.make_label_batch(batches, user, progress=progress)
 
        else:
 
            raise RuntimeError("Batch execution action is not supported: {}".format(action))
 
        now = make_utc()
 
        for batch in batches:
 
            batch.executed = now
 
            batch.executed_by = user
 
        return result
 

	
 
    def make_inventory_batch(self, handheld_batches, user, progress=None):
 
        handler = get_batch_handler(self.config, 'inventory',
rattail/batch/handlers.py
Show inline comments
 
@@ -2,7 +2,7 @@
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
@@ -33,6 +33,7 @@ import warnings
 
from sqlalchemy import orm
 

	
 
from rattail.db.cache import cache_model
 
from rattail.time import make_utc
 
from rattail.util import progress_loop, load_object
 

	
 

	
 
@@ -329,9 +330,12 @@ class BatchHandler(object):
 
        behavior is to simply execute each batch in succession.  Any batches
 
        which are already executed are skipped.
 
        """
 
        now = make_utc()
 
        for batch in batches:
 
            if not batch.executed:
 
                self.execute(batch, progress=progress, **kwargs)
 
                batch.executed = now
 
                batch.executed_by = kwargs['user']
 
        return True
 

	
 
    def clone(self, oldbatch, created_by):
0 comments (0 inline, 0 general)