예제 #1
0
    def request_returning_label(self):
        if self.returning_mail_label:
            return True, None
        endicia = Endicia(**settings.ENDICIA_CONF)
        res = endicia.get_postage_label(
            weight=self.get_weight(),
            image_format=ImageFormat.GIF,
            mail_class=MailClass.First if self.get_weight() <= decimal.Decimal('7.0') else MailClass.MediaMail,
            mailpiece_shape=MailpieceShape.Parcel,
            stealth=False,
            rubber_stamp='CUSTOMER ID: %08d\nORDER # %s' % (self.order.user.id, self.order.order_no()),
            services={
                'delivery_confirmation': False,
            },
            reference_id='Trade',
            description='Trade Returning Label',
            partner_customer_id='%08d' % self.order.user.id,
            partner_transaction_id='%08d' % self.id,
            to={
                'name': ' '.join((self.order.first_name, self.order.last_name)),
                'address1': self.order.shipping_address1,
                'address2': self.order.shipping_address2,
                'city': self.order.shipping_city,
                'state': self.order.shipping_state,
                'postal_code': split_zip(self.order.shipping_zip_code)[0],
                'zip4': split_zip(self.order.shipping_zip_code)[1],
                'delivery_point': '00',
            },
            frm={
                'name': 'GAMEMINE',
                'city': 'Delray Beach',
                'state': 'FL',
                'postal_code': '33482',
                'zip4': '9901',
            },
            return_address='P.O. Box 6487',
            postage_price=True)
        if res.Status == '0':
            self.returning_endicia_data = res._dict['LabelRequestResponse']

            label_file = ContentFile(base64.decodestring(res.Base64LabelImage))
            if self.returning_mail_label:
                self.returning_mail_label.delete(False)
            self.returning_mail_label.save('%08d.gif' % self.id, label_file)
        else:
            self.returning_endicia_data = ''
        return res.Status == '0', res.ErrorMessage if res.Status != '0' else 'OK'
예제 #2
0
    def do_update_shipped_statuses(self):
        def parse_time(s):
            try:
                s = re.search(
                    r"(?P<time>\d{2}:\d{2} (AM|PM) on \d{2}/\d{2}/\d{4})",
                    s
                ).groupdict()["time"]
                d = datetime.strptime(s, "%I:%M %p on %m/%d/%Y")
            except Exception, e:
                debug(e)
                d = datetime.datetime.now()
            debug(d)
            return d

        endicia = Endicia(**settings.ENDICIA_CONF)
        info(
            "Checking mail shipped statuses...",
            extra={"url": "task://rent/update_shipped_statuses"})
        for order in RentOrder.objects.filter(
            status=RentOrderStatus.Shipped, date_delivered=None
        ):
            try:
                pic = order.outgoing_tracking_number
                if not pic:
                    # warn("No PLANET ID (outgoing) for this order",
                    #      extra={"url": reverse(
                    #             "staff:rent_order_details", args=[order.id])
                    #             })
                    continue
                res = endicia.status_request(pic)