diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 5a11273209bed290b1c5b804f5e3b764a099dc7a..947508ad5f64a57688d623136e52014a7757eb39 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -50,7 +50,12 @@ class CustomerOrderBatchHandler(BatchHandler): 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): """ diff --git a/rattail/db/model/custorders.py b/rattail/db/model/custorders.py index 9eb7a581987c5eb74105303da3daf872002be2b7..3e414ad88ab519af9e251b092152b31d33192dec 100644 --- a/rattail/db/model/custorders.py +++ b/rattail/db/model/custorders.py @@ -136,10 +136,14 @@ class CustomerOrder(CustomerOrderBase, Base): 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: