示例#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
        }
示例#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
        }
示例#3
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
示例#4
0
文件: views.py 项目: hnejadi/EShop-2
    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
示例#5
0
    def handle(self, *args, **options): # pylint: disable=W0613
        """Actually executes the command
        """
        output = self.setupLogging(options)

        self.print_ts("Command started", output)

        max_days = int(config_value('ZONES_INFO', 'MAX_DAYS'))
        zones = Zone.objects.all()
        stale_shipments = []
        for zone in zones:
            shipments = Shipments(zone)
            stale_shipments.extend(
                [x for x in shipments.stale_shipments(max_days)])

        email = settings.EMAIL_NOTIFICATION
        site_name = settings.SITE_NAME
        fromemail = settings.DEFAULT_FROM_EMAIL
        self.send_notification(stale_shipments, email, site_name, fromemail)

        self.print_ts("Command ended", output)
        return 'OK\n'
示例#6
0
    def handle(self, *args, **options):  # pylint: disable=W0613
        """Actually executes the command
        """
        output = self.setupLogging(options)

        self.print_ts("Command started", output)

        max_days = int(config_value('ZONES_INFO', 'MAX_DAYS'))
        zones = Zone.objects.all()
        stale_shipments = []
        for zone in zones:
            shipments = Shipments(zone)
            stale_shipments.extend(
                [x for x in shipments.stale_shipments(max_days)])

        email = settings.EMAIL_NOTIFICATION
        site_name = settings.SITE_NAME
        fromemail = settings.DEFAULT_FROM_EMAIL
        self.send_notification(stale_shipments, email, site_name, fromemail)

        self.print_ts("Command ended", output)
        return 'OK\n'