Ejemplo n.º 1
0
class EventHandler(processing.EventHandler):
    def handle_shipping_event(self, order, event_type, lines, line_quantities,
                              **kwargs):
        changes = False
        new_status = event_type.name
        try:
            if order.status != new_status:
                changes = True
            order.set_status(new_status)
            for line in lines:
                if line.status != new_status:
                    changes = True
                line.set_status(new_status)
        except (InvalidOrderStatus, InvalidLineStatus), e:
            raise InvalidShippingEvent(str(e))

        if not changes:
            raise InvalidShippingEvent(
                'The select order lines are already marked as %s' % new_status)

        super(EventHandler,
              self).handle_shipping_event(order, event_type, lines,
                                          line_quantities, **kwargs)

        if event_type.name == 'Shipped':
            EmailTemplate.send('order_shipped', [order.email],
                               order=order,
                               lines=lines)
Ejemplo n.º 2
0
 def _check_previous_events_are_complete(self):
     """
     Checks whether previous shipping events have passed
     """
     # Quantity of the proposd event must have occurred for
     # the previous events in the sequence.
     previous_event_types = self.event.event_type.get_prerequisites()
     for event_type in previous_event_types:
         quantity = ShippingEventQuantity._default_manager.filter(
             line=self.line,
             event__event_type=event_type).aggregate(Sum('quantity'))['quantity__sum']
         if quantity is None or quantity < int(self.quantity):
             raise InvalidShippingEvent("This shipping event is not permitted")
Ejemplo n.º 3
0
 def handle_shipping_event(self, order, event_type, lines, line_quantities,
                           **kwargs):
     changes = False
     new_status = event_type.name
     try:
         if order.status != new_status:
             changes = True
         order.set_status(new_status)
         for line in lines:
             if line.status != new_status:
                 changes = True
             line.set_status(new_status)
     except (InvalidOrderStatus, InvalidLineStatus), e:
         raise InvalidShippingEvent(str(e))