Changeset - 16d8bd879a04
[Not reviewed]
0 2 1
Lance Edgar (lance) - 3 years ago 2021-09-09 19:14:39
lance@edbob.org
Add way to customize product autocomplete for new custorder
3 files changed with 24 insertions and 0 deletions:
0 comments (0 inline, 0 general)
docs/api/index.rst
Show inline comments
 
@@ -8,12 +8,13 @@ attributes and method signatures etc.
 

	
 
.. toctree::
 
   :maxdepth: 1
 

	
 
   rattail
 
   rattail/app
 
   rattail/batch/custorder
 
   rattail/batch/handlers
 
   rattail/batch/purchase
 
   rattail/config
 
   rattail/csvutil
 
   rattail/datasync/index
 
   rattail/datasync/consumers
docs/api/rattail/batch/custorder.rst
Show inline comments
 
new file 100644
 

	
 
``rattail.batch.custorder``
 
===========================
 

	
 
.. automodule:: rattail.batch.custorder
 
   :members:
rattail/batch/custorder.py
Show inline comments
 
@@ -36,18 +36,35 @@ from rattail.batch import BatchHandler
 
class CustomerOrderBatchHandler(BatchHandler):
 
    """
 
    Handler for all "customer order" batches, regardless of "mode".  The
 
    handler must inspect the
 
    :attr:`~rattail.db.model.batch.custorder.CustomerOrderBatch.mode` attribute
 
    of each batch it deals with, in order to determine which logic to apply.
 

	
 
    .. attribute:: has_custom_product_autocomplete
 

	
 
       If true, this flag indicates that the handler provides custom
 
       autocomplete logic for use when selecting a product while
 
       creating a new order.
 
    """
 
    batch_model_class = model.CustomerOrderBatch
 
    has_custom_product_autocomplete = False
 

	
 
    def get_case_size_for_product(self, product):
 
        return product.case_size
 

	
 
    def custom_product_autocomplete(self, session, term, **kwargs):
 
        """
 
        For the given term, this should return a (possibly empty) list
 
        of products which "match" the term.  Each element in the list
 
        should be a dict with "label" and "value" keys.
 
        """
 
        raise NotImplementedError("Please define the "
 
                                  "{}.custom_product_autocomplete() "
 
                                  "method.".format(__class__.__name__))
 

	
 
    def refresh_row(self, row):
 
        if not row.product:
 
            if row.item_entry:
 
                session = orm.object_session(row)
 
                # TODO: should do more than just query for uuid here
 
                product = session.query(model.Product).get(row.item_entry)
0 comments (0 inline, 0 general)