diff --git a/rattail/batch/handheld.py b/rattail/batch/handheld.py index e5ee462482cfc20c52a9fd642fa6498283ed8a97..786b09f832e2d82f45232c6eb4b5e672a767b821 100644 --- a/rattail/batch/handheld.py +++ b/rattail/batch/handheld.py @@ -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) - raise RuntimeError("Batch execution action is not supported: {}".format(action)) + 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', diff --git a/rattail/batch/handlers.py b/rattail/batch/handlers.py index 0ae7045c77ddc9d63b45337e8cf8c20a42ef7869..07f00a4741ffdb31424656f16cbd419dc453b7a0 100644 --- a/rattail/batch/handlers.py +++ b/rattail/batch/handlers.py @@ -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):