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 19 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rattail/batch/handheld.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -31,12 +31,13 @@ import decimal
 

	
 
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
 

	
 

	
 
class HandheldBatchHandler(BatchHandler):
 
    """
 
    Handler for handheld batches.
 
@@ -167,17 +168,26 @@ class HandheldBatchHandler(BatchHandler):
 
        row.status_code = row.STATUS_OK
 

	
 
    def execute(self, batch, user=None, action='make_inventory_batch', progress=None, **kwargs):
 
        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',
 
                                    default='rattail.batch.inventory:InventoryBatchHandler')
 
        session = orm.object_session(handheld_batches[0])
 
        batch = handler.make_batch(session, created_by=user, handheld_batches=handheld_batches)
rattail/batch/handlers.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2018 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -30,12 +30,13 @@ import os
 
import shutil
 
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
 

	
 

	
 
class BatchHandler(object):
 
    """
 
    Base class and partial default implementation for batch handlers.  It is
 
@@ -326,15 +327,18 @@ class BatchHandler(object):
 
    def execute_many(self, batches, progress=None, **kwargs):
 
        """
 
        Execute a set of batches, with given progress and kwargs.  Default
 
        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):
 
        """
 
        Clone the given batch as a new batch, and return the new batch.
 
        """
0 comments (0 inline, 0 general)