Coverage for apps/orders/signals.py: 84%
33 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-27 13:33 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-27 13:33 -0600
1from django.db.models import signals
2from django.dispatch import receiver
4from .models import Icon, Order, OrderIcon, OrderItem, OrderItemSize
7@receiver(signals.pre_save, sender=OrderItemSize)
8def update_order_item_size_status_on_reception(sender, instance, *args, **kwargs):
9 if instance.pending_amount == 0: 9 ↛ 10line 9 didn't jump to line 10, because the condition on line 9 was never true
10 instance.status = OrderItemSize.Status.DELIVERED
11 elif instance.delivered_amount > 0:
12 instance.status = OrderItemSize.Status.PARTIAL
15@receiver(signals.post_save, sender=OrderItemSize)
16def update_order_item_status_from_order_item_size(sender, instance, created, *args, **kwargs):
17 order_item = instance.order_item
19 status = order_item.sizes.values_list("status", flat=True)
21 if OrderItemSize.Status.PARTIAL in status:
22 order_item.status = OrderItem.Status.PARTIAL
23 elif OrderItemSize.Status.PENDING not in status: 23 ↛ 24line 23 didn't jump to line 24, because the condition on line 23 was never true
24 order_item.status = OrderItem.Status.DELIVERED
25 order_item.save()
28@receiver(signals.post_save, sender=OrderItem)
29def update_order_status_from_order_item(sender, instance, created, *args, **kwargs):
30 order = instance.order
32 status = order.items.values_list("status", flat=True)
34 if OrderItem.Status.PARTIAL in status:
35 order.status = Order.Status.PARTIAL
36 elif OrderItem.Status.PENDING not in status: 36 ↛ 37line 36 didn't jump to line 37, because the condition on line 36 was never true
37 order.status = Order.Status.DELIVERED
38 order.save()
41@receiver(signals.post_save, sender=Order)
42def set_order_icons_for_order(sender, instance, created, *args, **kwargs):
43 if created:
44 icons = Icon.objects.filter(is_default_on_order=True)
46 for icon in icons: 46 ↛ 47line 46 didn't jump to line 47, because the loop on line 46 never started
47 OrderIcon.objects.create(order=instance, icon=icon, is_active=icon.is_active_by_default)