Example #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
        }
Example #2
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
        }
Example #3
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
Example #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