Changeset - d9051322361d
[Not reviewed]
0 2 0
Lance Edgar (lance) - 3 years ago 2021-09-21 13:47:47
lance@edbob.org
Some tweaks for customer orders

- improve how case size is determined
- auto-delete items when order is deleted
2 files changed with 14 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -41,25 +41,30 @@ class CustomerOrderBatchHandler(BatchHandler):
 
    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
 
        if product.case_size:
 
            return product.case_size
 

	
 
        cost = product.cost
 
        if cost:
 
            return cost.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):
rattail/db/model/custorders.py
Show inline comments
 
@@ -127,28 +127,32 @@ class CustomerOrder(CustomerOrderBase, Base):
 
    Date and time when the order/batch was first created.
 
    """)
 

	
 
    created_by_uuid = sa.Column(sa.String(length=32), nullable=True)
 
    created_by = orm.relationship(
 
        User,
 
        doc="""
 
        Reference to the user who initially created the order/batch.
 
        """)
 

	
 
    status_code = sa.Column(sa.Integer(), nullable=False)
 

	
 
    items = orm.relationship('CustomerOrderItem', back_populates='order',
 
                             collection_class=ordering_list('sequence', count_from=1), doc="""
 
    Sequence of :class:`CustomerOrderItem` instances which belong to the order.
 
    """)
 
    items = orm.relationship(
 
        'CustomerOrderItem',
 
        back_populates='order',
 
        collection_class=ordering_list('sequence', count_from=1),
 
        cascade='all, delete-orphan',
 
        doc="""
 
        Sequence of :class:`CustomerOrderItem` instances which belong to the order.
 
        """)
 

	
 
    def __str__(self):
 
        if self.id:
 
            return "#{}".format(self.id)
 
        return "(pending)"
 

	
 

	
 
@six.python_2_unicode_compatible
 
class CustomerOrderItemBase(object):
 
    """
 
    Base class for customer order line items.
 
    """
0 comments (0 inline, 0 general)