Changeset - 8ae4de7d5939
[Not reviewed]
docs/api/index.rst
Show inline comments
 
@@ -15,11 +15,15 @@ attributes and method signatures etc.
 
   rattail/autocomplete/base
 
   rattail/autocomplete/customers
 
   rattail/batch/custorder
 
   rattail/batch/handheld
 
   rattail/batch/handlers
 
   rattail/batch/pricing
 
   rattail/batch/product
 
   rattail/batch/purchase
 
   rattail/board
 
   rattail/bouncer/index
 
   rattail/clientele
 
   rattail/commands.batch
 
   rattail/config
 
   rattail/csvutil
 
   rattail/custorders
docs/api/rattail/batch/handheld.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.batch.handheld``
 
==========================
 

	
 
.. automodule:: rattail.batch.handheld
 
   :members:
docs/api/rattail/batch/pricing.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.batch.pricing``
 
=========================
 

	
 
.. automodule:: rattail.batch.pricing
 
   :members:
docs/api/rattail/batch/product.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.batch.product``
 
=========================
 

	
 
.. automodule:: rattail.batch.product
 
   :members:
docs/api/rattail/commands.batch.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.commands.batch``
 
==========================
 

	
 
.. automodule:: rattail.commands.batch
 
   :members:
docs/api/rattail/db/index.rst
Show inline comments
 
@@ -19,7 +19,11 @@
 
   changes
 
   model
 
   model.batch
 
   model.batch.handheld
 
   model.batch.inventory
 
   model.batch.labels
 
   model.batch.pricing
 
   model.batch.product
 
   model.batch.purchase
 
   model.batch.vendorcatalog
 
   model.datasync
docs/api/rattail/db/model.batch.handheld.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.db.model.batch.handheld``
 
===================================
 

	
 
.. automodule:: rattail.db.model.batch.handheld
 
  :members:
docs/api/rattail/db/model.batch.inventory.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.db.model.batch.inventory``
 
====================================
 

	
 
.. automodule:: rattail.db.model.batch.inventory
 
  :members:
docs/api/rattail/db/model.batch.pricing.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.db.model.batch.pricing``
 
==================================
 

	
 
.. automodule:: rattail.db.model.batch.pricing
 
  :members:
docs/api/rattail/db/model.batch.product.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.db.model.batch.product``
 
==================================
 

	
 
.. automodule:: rattail.db.model.batch.product
 
  :members:
rattail/batch/handheld.py
Show inline comments
 
@@ -2,7 +2,7 @@
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2021 Lance Edgar
 
#  Copyright © 2010-2022 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
@@ -30,10 +30,9 @@ import csv
 
import decimal
 

	
 
import six
 
from sqlalchemy import orm
 

	
 
from rattail.db import api, model
 
from rattail.batch import BatchHandler, get_batch_handler
 
from rattail.batch import BatchHandler
 
from rattail.gpc import GPC
 
from rattail.time import make_utc
 
from rattail.wince import parse_batch_file as parse_wince_file
 
@@ -156,7 +155,7 @@ class HandheldBatchHandler(BatchHandler):
 
            row.status_code = row.STATUS_PRODUCT_NOT_FOUND
 
            return
 

	
 
        session = orm.object_session(row)
 
        session = self.app.get_session(row)
 
        product = api.get_product_by_upc(session, row.upc)
 
        if not product:
 
            row.status_code = row.STATUS_PRODUCT_NOT_FOUND
 
@@ -192,18 +191,58 @@ class HandheldBatchHandler(BatchHandler):
 
            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)
 
    def make_inventory_batch(self, handheld_batches, user, progress=None,
 
                             **kwargs):
 
        """
 
        Make a new Inventory Batch from the given Handheld Batch(es).
 

	
 
        :param handheld_batches: Sequence of one or more
 
           :class:`~rattail.db.model.batch.handheld.HandheldBatch`
 
           instances from which a new inventory batch should be made.
 

	
 
        :param user: :class:`~rattail.db.model.users.User` who is
 
           responsible for this action.
 

	
 
        :returns: A new
 
           :class:`~rattail.db.model.batch.inventory.InventoryBatch`
 
           instance, populated from the given handheld batch(es).
 
        """
 
        handler = self.app.get_batch_handler(
 
            'inventory', default='rattail.batch.inventory:InventoryBatchHandler')
 
        session = self.app.get_session(handheld_batches[0])
 
        batch = handler.make_batch(session, created_by=user,
 
                                   handheld_batches=handheld_batches,
 
                                   **kwargs)
 
        handler.do_populate(batch, user, progress=progress)
 
        return batch
 

	
 
    def make_label_batch(self, handheld_batches, user, progress=None):
 
        handler = get_batch_handler(self.config, 'labels',
 
                                    default='rattail.batch.labels:LabelBatchHandler')
 
        session = orm.object_session(handheld_batches[0])
 
        batch = handler.make_batch(session, created_by=user, handheld_batches=handheld_batches)
 
    def make_label_batch(self, handheld_batches, user, progress=None,
 
                         **kwargs):
 
        """
 
        Make a new Label Batch from the given Handheld Batch(es).
 

	
 
        :param handheld_batches: Sequence of one or more
 
           :class:`~rattail.db.model.batch.handheld.HandheldBatch`
 
           instances from which a new label batch should be made.
 

	
 
        :param user: :class:`~rattail.db.model.users.User` who is
 
           responsible for this action.
 

	
 
        :returns: A new
 
           :class:`~rattail.db.model.batch.labels.LabelBatch`
 
           instance, populated from the given handheld batch(es).
 
        """
 
        handler = self.app.get_batch_handler(
 
            'labels', default='rattail.batch.labels:LabelBatchHandler')
 
        session = self.app.get_session(handheld_batches[0])
 
        if len(handheld_batches) > 1:
 
            # TODO: need to implement this
 
            raise NotImplementedError("Multiple handheld batches not (yet) "
 
                                      "supported when converting to label batch.  "
 
                                      "Please try again with only a single "
 
                                      "handheld batch")
 
        batch = handler.make_batch(session, created_by=user,
 
                                   handheld_batch=handheld_batches[0],
 
                                   **kwargs)
 
        handler.do_populate(batch, user, progress=progress)
 
        return batch
rattail/batch/product.py
Show inline comments
 
@@ -2,7 +2,7 @@
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2021 Lance Edgar
 
#  Copyright © 2010-2022 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
@@ -26,10 +26,8 @@ Handler for generic product batches
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from sqlalchemy import orm
 

	
 
from rattail.db import model
 
from rattail.batch import BatchHandler, get_batch_handler
 
from rattail.batch import BatchHandler
 

	
 

	
 
class ProductBatchHandler(BatchHandler):
 
@@ -56,7 +54,7 @@ class ProductBatchHandler(BatchHandler):
 
                row.status_code = row.STATUS_MISSING_KEY
 
                return
 

	
 
            session = orm.object_session(row)
 
            session = self.app.get_session(row)
 
            # nb. we prefer a GPC lookup if one is present
 
            row.product = self.locate_product_for_entry(session,
 
                                                        row.upc or row.item_entry)
 
@@ -109,24 +107,56 @@ class ProductBatchHandler(BatchHandler):
 

	
 
        return result
 

	
 
    def make_label_batch(self, product_batch, user, progress=None):
 
        handler = get_batch_handler(self.config, 'labels',
 
                                    default='rattail.batch.labels:LabelBatchHandler')
 
        session = orm.object_session(product_batch)
 
    def make_label_batch(self, product_batch, user, progress=None,
 
                         **kwargs):
 
        """
 
        Make a new Label Batch from the given Product Batch.
 

	
 
        :param product_batch: Reference to a
 
           :class:`~rattail.db.model.batch.product.ProductBatch`
 
           instance from which a new label batch should be made.
 

	
 
        :param user: :class:`~rattail.db.model.users.User` who is
 
           responsible for this action.
 

	
 
        :returns: A new
 
           :class:`~rattail.db.model.batch.labels.LabelBatch`
 
           instance, populated from the given product batch.
 
        """
 
        handler = self.app.get_batch_handler(
 
            'labels', default='rattail.batch.labels:LabelBatchHandler')
 
        session = self.app.get_session(product_batch)
 
        kwargs.setdefault('description', product_batch.description)
 
        kwargs.setdefault('notes', product_batch.notes)
 
        label_batch = handler.make_batch(session, created_by=user,
 
                                         description=product_batch.description,
 
                                         notes=product_batch.notes)
 
                                         **kwargs)
 
        label_batch.product_batch = product_batch
 
        handler.do_populate(label_batch, user, progress=progress)
 
        return label_batch
 

	
 
    def make_pricing_batch(self, product_batch, user, progress=None):
 
        handler = get_batch_handler(self.config, 'pricing',
 
                                    default='rattail.batch.pricing:PricingBatchHandler')
 
        session = orm.object_session(product_batch)
 
    def make_pricing_batch(self, product_batch, user, progress=None,
 
                           **kwargs):
 
        """
 
        Make a new Pricing Batch from the given Product Batch.
 

	
 
        :param product_batch: Reference to a
 
           :class:`~rattail.db.model.batch.product.ProductBatch`
 
           instance from which a new pricing batch should be made.
 

	
 
        :param user: :class:`~rattail.db.model.users.User` who is
 
           responsible for this action.
 

	
 
        :returns: A new
 
           :class:`~rattail.db.model.batch.pricing.PricingBatch`
 
           instance, populated from the given product batch.
 
        """
 
        handler = self.app.get_batch_handler(
 
            'pricing', default='rattail.batch.pricing:PricingBatchHandler')
 
        session = self.app.get_session(product_batch)
 
        kwargs.setdefault('description', product_batch.description)
 
        kwargs.setdefault('notes', product_batch.notes)
 
        pricing_batch = handler.make_batch(session, created_by=user,
 
                                           description=product_batch.description,
 
                                           notes=product_batch.notes)
 
                                           **kwargs)
 
        pricing_batch.product_batch = product_batch
 
        handler.do_populate(pricing_batch, user, progress=progress)
 
        return pricing_batch
rattail/commands/batch.py
Show inline comments
 
@@ -2,7 +2,7 @@
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2020 Lance Edgar
 
#  Copyright © 2010-2022 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
@@ -51,11 +51,25 @@ class BatchHandlerCommand(Subcommand):
 
                            "occur, but rollback (abort) the transaction at the end.")
 

	
 
    def get_handler(self, args):
 
        from rattail.batch import get_batch_handler
 

	
 
        handler = get_batch_handler(self.config, args.batch_type)
 
        assert handler
 
        return handler
 
        """
 
        Must return the batch handler to use, per the given ``args``
 
        object.
 

	
 
        Default logic assumes that ``args`` has a ``batch_type``
 
        attribute, which determines which batch handler should be
 
        used.  That is figured out by calling
 
        :meth:`~rattail.app.AppHandler.get_batch_handler()` on the app
 
        handler.
 

	
 
        :param args: Reference to the
 
           :class:`python:argparse.Namespace` instance, which was the
 
           result of parsing the command line args.
 

	
 
        :returns: Must return the batch handler.  This will be an
 
           instance of some class which derives from
 
           :class:`~rattail.batch.handlers.BatchHandler`.
 
        """
 
        return self.app.get_batch_handler(args.batch_type)
 

	
 
    def run(self, args):
 
        handler = self.get_handler(args)
tests/batch/__init__.py
Show inline comments
 
new file 100644
tests/batch/test_handheld.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from unittest import TestCase
 

	
 
import sqlalchemy as sa
 

	
 
from rattail.batch import handheld as mod
 
from rattail.config import make_config
 
from rattail.db import Session
 

	
 

	
 
class TestHandheldBatchHandler(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.handler = self.make_handler()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def make_handler(self):
 
        return mod.HandheldBatchHandler(self.config)
 

	
 
    def test_make_inventory_batch(self):
 
        engine = sa.create_engine('sqlite://')
 
        model = self.config.get_model()
 
        model.Base.metadata.create_all(bind=engine)
 
        session = Session(bind=engine)
 

	
 
        # prep data
 
        betty = model.User(username='betty')
 
        handbatch = model.HandheldBatch(id=1, created_by=betty)
 
        session.add(handbatch)
 
        session.commit()
 

	
 
        # make basic inventory batch
 
        invbatch = self.handler.make_inventory_batch([handbatch], betty, id=2)
 
        self.assertIsNotNone(invbatch)
 
        self.assertEqual(invbatch.id, 2)
 

	
 
    def test_make_label_batch(self):
 
        engine = sa.create_engine('sqlite://')
 
        model = self.config.get_model()
 
        model.Base.metadata.create_all(bind=engine)
 
        session = Session(bind=engine)
 

	
 
        # prep data
 
        betty = model.User(username='betty')
 
        handbatch = model.HandheldBatch(id=1, created_by=betty)
 
        session.add(handbatch)
 
        session.commit()
 

	
 
        # make basic label batch
 
        lblbatch = self.handler.make_label_batch([handbatch], betty, id=2)
 
        self.assertIsNotNone(lblbatch)
 
        self.assertEqual(lblbatch.id, 2)
tests/batch/test_product.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from unittest import TestCase
 

	
 
import sqlalchemy as sa
 

	
 
from rattail.batch import product as mod
 
from rattail.config import make_config
 
from rattail.db import Session
 

	
 

	
 
class TestProductBatchHandler(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.handler = self.make_handler()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def make_handler(self):
 
        return mod.ProductBatchHandler(self.config)
 

	
 
    def test_make_label_batch(self):
 
        engine = sa.create_engine('sqlite://')
 
        model = self.config.get_model()
 
        model.Base.metadata.create_all(bind=engine)
 
        session = Session(bind=engine)
 

	
 
        # prep data
 
        betty = model.User(username='betty')
 
        prodbatch = model.ProductBatch(id=1, created_by=betty)
 
        session.add(prodbatch)
 
        session.commit()
 

	
 
        # make basic label batch
 
        lblbatch = self.handler.make_label_batch(prodbatch, betty, id=2)
 
        self.assertIsNotNone(lblbatch)
 
        self.assertEqual(lblbatch.id, 2)
 

	
 
    def test_make_pricing_batch(self):
 
        engine = sa.create_engine('sqlite://')
 
        model = self.config.get_model()
 
        model.Base.metadata.create_all(bind=engine)
 
        session = Session(bind=engine)
 

	
 
        # prep data
 
        betty = model.User(username='betty')
 
        prodbatch = model.ProductBatch(id=1, created_by=betty)
 
        session.add(prodbatch)
 
        session.commit()
 

	
 
        # make basic pricing batch
 
        prcbatch = self.handler.make_pricing_batch(prodbatch, betty, id=2)
 
        self.assertIsNotNone(prcbatch)
 
        self.assertEqual(prcbatch.id, 2)
tests/commands/test_batch.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8; -*-
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from unittest import TestCase
 

	
 
import sqlalchemy as sa
 

	
 
from rattail.commands import batch as mod
 
from rattail.config import make_config
 
from rattail.commands import Command
 
from rattail.db import Session
 
from rattail.core import Object
 

	
 

	
 
class TestBatchHandlerCommand(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.command = self.make_command()
 
        self.subcommand = self.make_subcommand()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def make_command(self):
 
        command = Command()
 
        command.config = self.config
 
        return command
 

	
 
    def make_subcommand(self):
 
        return mod.BatchHandlerCommand(parent=self.command,
 
                                       config=self.config)
 

	
 
    def test_get_handler(self):
 
        engine = sa.create_engine('sqlite://')
 
        model = self.config.get_model()
 
        model.Base.metadata.create_all(bind=engine)
 
        session = Session(bind=engine)
 

	
 
        # TODO: these things should self-register somehow instead
 
        self.config.setdefault('rattail.batch', 'handheld.handler',
 
                               'rattail.batch.handheld:HandheldBatchHandler')
 

	
 
        # subcommand makes its own handler, for e.g. handheld batch
 
        args = Object(batch_type='handheld')
 
        handler = self.subcommand.get_handler(args)
 
        self.assertIsNotNone(handler)
 
        self.assertEqual(handler.batch_key, 'handheld')
0 comments (0 inline, 0 general)