Exemplo n.º 1
0
    def expectedDelivery(self, contact=None):
        """Performs calculation on the next available shipping, condiering
        calendars and zones
        """
        if not contact:
            contact = self.contact
        zone = contact.contactzone.zone
        shipments = Shipments(zone)
        e_date, e_mission = shipments.projected_shipment()
        start = e_mission.starts
        end = e_mission.ends
        humanize_times = HumanizeTimes()
        date_str = humanize_times.humanizeTimeDiffLeft(e_date)
        start_str = start.strftime(time_format)
        end_str = end.strftime(time_format)
        remaining_shipments = e_mission.remaining_shipments(e_date)

        rs = _(u'(remaining %(slots)s free slot)') % {
            'slots': remaining_shipments
        }

        if remaining_shipments > 1:
            rs = _(u'(remaining %(slots)s free slots)') % {
                'slots': remaining_shipments
            }

        return u"%(date)s, %(start)s - %(end)s " \
                u"<strong class='%(class)s'>%(rs)s</strong>" % {
            'date': date_str,
            'start': start_str,
            'end': end_str,
            'class': remaining_shipments < 2 and 'cslot bit' or 'cslot',
            'rs': rs
        }
Exemplo n.º 2
0
def shipping_extimated_date(self):
    order = self
    method = shipping_method_by_key(order.shipping_model)
    if method.valid():
        expected_delivery = method.expectedDelivery(order.contact)

    try:
        shipment = Shipment.objects.get(order=order)
        humanize_times = HumanizeTimes()
        start = shipment.mission.starts
        end = shipment.mission.ends
        start_str = start.strftime("%H:%M")
        end_str = end.strftime("%H:%M")
        now = datetime.datetime.utcnow().date()
        if now < shipment.date:
            expected_delivery = humanize_times.humanizeTimeDiffLeft(
                shipment.date)
        else:
            expected_delivery = humanize_times.humanizeTimeDiffAgo(
                shipment.date)

        return u"%(date)s, %(start)s - %(end)s" % {
            'date': expected_delivery,
            'start': start_str,
            'end': end_str
        }

    except Shipment.DoesNotExist:
        pass

    return expected_delivery
Exemplo n.º 3
0
    def expectedDelivery(self, contact=None):
        """Performs calculation on the next available shipping, condiering
        calendars and zones
        """
        if not contact:
            contact = self.contact
        zone = contact.contactzone.zone
        shipments = Shipments(zone)
        e_date, e_mission = shipments.projected_shipment()
        start = e_mission.starts
        end = e_mission.ends
        humanize_times = HumanizeTimes()
        date_str = humanize_times.humanizeTimeDiffLeft(e_date)
        start_str = start.strftime(time_format)
        end_str = end.strftime(time_format)
        remaining_shipments = e_mission.remaining_shipments(e_date)

        rs = _(u'(remaining %(slots)s free slot)') % {
                'slots': remaining_shipments
        }

        if remaining_shipments > 1:
            rs = _(u'(remaining %(slots)s free slots)') % {
                'slots': remaining_shipments
            }

        return u"%(date)s, %(start)s - %(end)s " \
                u"<strong class='%(class)s'>%(rs)s</strong>" % {
            'date': date_str,
            'start': start_str,
            'end': end_str,
            'class': remaining_shipments < 2 and 'cslot bit' or 'cslot',
            'rs': rs
        }
Exemplo n.º 4
0
def shipping_extimated_date(self):
    order = self
    method = shipping_method_by_key(order.shipping_model)
    if method.valid():
        expected_delivery = method.expectedDelivery(order.contact)

    try:
        shipment = Shipment.objects.get(order=order)
        humanize_times = HumanizeTimes()
        start = shipment.mission.starts
        end = shipment.mission.ends
        start_str = start.strftime("%H:%M")
        end_str = end.strftime("%H:%M")
        now = datetime.datetime.utcnow().date()
        if now < shipment.date:
            expected_delivery = humanize_times.humanizeTimeDiffLeft(
                                                            shipment.date)
        else:
            expected_delivery = humanize_times.humanizeTimeDiffAgo(
                                                            shipment.date)

        return u"%(date)s, %(start)s - %(end)s" % {
            'date': expected_delivery,
            'start': start_str,
            'end': end_str}

    except Shipment.DoesNotExist:
        pass

    return expected_delivery
Exemplo n.º 5
0
    def get_stale_shipments(self):
        zones = Zone.objects.all()
        risky_count = 0
        stale_shipments = []
        now = datetime.utcnow().date()
        for zone in zones:
            shipments = Shipments(zone)
            for shipment in shipments.stale_shipments(self.max_days):
                # check if this shipment is "risky"
                e_date, e_mission = shipments.projected_shipment()
                diff_days = e_date - now
                if diff_days.days < 3:
                    # risky stale shipment
                    risky_count += 1

                # storing shipment
                humanize_times = HumanizeTimes()
                shipment_vocab = {
                    'id':
                    shipment.id,
                    'order_id':
                    shipment.order.id,
                    'zone':
                    shipment.zone,
                    'booked_on':
                    humanize_times.humanizeTimeDiffAgo(shipment.booked_on),
                    'ship_on':
                    self.get_ship_date_label(e_date, e_mission),
                    'booking_date':
                    shipment.booked_on,
                    'delivery_date':
                    self.get_delivery_date(e_date, e_mission),
                    'contact':
                    shipment.order.contact.full_name,
                    'contact_email':
                    shipment.order.contact.email,
                    'primary_phone':
                    shipment.order.contact.primary_phone
                }

                if self.contact_name:
                    if self.contact_name in \
                            shipment.order.contact.full_name.lower():
                        stale_shipments.append(shipment_vocab)
                else:
                    stale_shipments.append(shipment_vocab)

        self.total_shipments = len(stale_shipments)
        if self.limit:
            stale_shipments = stale_shipments[:self.limit]
        self.stale_shipments = self.order_shipment(stale_shipments)
        self.risky_count = risky_count
Exemplo n.º 6
0
    def get_stale_shipments(self):
        zones = Zone.objects.all()
        risky_count = 0
        stale_shipments = []
        now = datetime.utcnow().date()
        for zone in zones:
            shipments = Shipments(zone)
            for shipment in shipments.stale_shipments(self.max_days):
                # check if this shipment is "risky"
                e_date, e_mission = shipments.projected_shipment()
                diff_days = e_date - now
                if diff_days.days < 3:
                    # risky stale shipment
                    risky_count += 1

                # storing shipment
                humanize_times = HumanizeTimes()
                shipment_vocab = {
                    'id': shipment.id,
                    'order_id': shipment.order.id,
                    'zone': shipment.zone,
                    'booked_on': humanize_times.humanizeTimeDiffAgo(shipment.booked_on),
                    'ship_on': self.get_ship_date_label(e_date, e_mission),
                    'booking_date': shipment.booked_on,
                    'delivery_date': self.get_delivery_date(e_date, e_mission),
                    'contact': shipment.order.contact.full_name,
                    'contact_email': shipment.order.contact.email,
                    'primary_phone': shipment.order.contact.primary_phone}

                if self.contact_name:
                    if self.contact_name in \
                            shipment.order.contact.full_name.lower():
                        stale_shipments.append(shipment_vocab)
                else:
                    stale_shipments.append(shipment_vocab)

        self.total_shipments = len(stale_shipments)
        if self.limit:
            stale_shipments = stale_shipments[:self.limit]
        self.stale_shipments = self.order_shipment(stale_shipments)
        self.risky_count = risky_count