Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add Queryset for OrderLine
Maciej Korycinskib0d4f4a5c14f
diff --git a/saleor/order/models.py b/saleor/order/models.pyindex a9eaf6f823..94b2fe0134 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -286,6 +286,18 @@ class Order(models.Model):return self.weight+class OrderLineQueryset(models.QuerySet):+ def digital(self):+ for line in self.all():+ if line.is_digital:+ yield line++ def physical(self):+ for line in self.all():+ if not line.is_digital:+ yield line++class OrderLine(models.Model):order = models.ForeignKey(Order, related_name='lines', editable=False, on_delete=models.CASCADE)@@ -314,6 +326,8 @@ class OrderLine(models.Model):tax_rate = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal('0.0'))+ objects = OrderLineQueryset.as_manager()+class Meta:ordering = ('pk', )diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 153398ef0e..260a9d195f 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -38,10 +38,7 @@ def order_line_needs_automatic_fulfillment(line: OrderLine) -> bool:def order_needs_automatic_fullfilment(order: Order) -> bool:"""Check if order has digital products which should be automaticallyfulfilled"""- digital_lines = [line for line in order if line.is_digital]- if not digital_lines:- return False- for line in digital_lines:+ for line in order.lines.digital():if order_line_needs_automatic_fulfillment(line):return Truereturn False