Example #1
0
 def test_abandoned_basket_email(self):
     """ Make sure the abandoned basket email is being sent correctly"""
     
     # GET AN UNPAID ORDER IN ENGLISH
     order = Order.objects.filter(
             owner__language='en', 
             reminder_email_sent=False, 
             date_paid__isnull=False
     ).order_by('?')[0]
     
     # TEST IT            
     self.assertEqual(abandoned_basket(order.pk), True)
     self.assertEquals(len(mail.outbox), 1)
     email_subject_line = _("Do you want to finish your order on %s?") % settings.SITE_NAME
     self.assertEquals(mail.outbox[0].subject, email_subject_line)      
     mail.outbox = []
     
     
     # GET A GERMAN ORDER
     translation.activate('de')
     order = Order.objects.filter(owner__language='de', reminder_email_sent=False, date_paid__isnull=False).order_by('?')[0]
     
     # TEST AGAIN IN GERMAN
     self.assertEqual(abandoned_basket(order.pk), True)
     self.assertEquals(len(mail.outbox), 1)
     # self.assertEquals(mail.outbox[0].subject, 'War es etwas, was wir gesagt haben?')      
     mail.outbox = []
    def handle_noargs(self, **options):
        
        # SET A DATE RANGE OF 1 DAY
        start_date = (datetime.now() - timedelta(days=1)) 
        end_date = datetime.now()
                
        seen = {}
        items = []
        
        # MAKE A LIST OF ORDERS THAT WERE MADE IN THE LAST DAY (PAID OR NOT, WE DON'T CARE)
        orders = Order.objects.filter(
            date_confirmed__range=(start_date, end_date),
        ).order_by('-date_confirmed')

        
        # UNIQUE-IFY THE LIST AGAINST EMAIL ADDRESS SO WE ONLY HAVE THE MOST RECENT ONE
        for o in orders:
            marker = o.owner.email
            if marker in seen: continue
            seen[marker] = 1
            items.append(o) 
         
                
        # NOW WE HAVE THE MOST RECENT ORDER. IF IT ISN'T PAID, AND HASNT ALREADY 
        # HAD AN EMAIL, LET'S EMAIL THEM.
        sent = []
        for i in items:
            
            if i.date_paid: 
                continue
                
            if i.status == Order.STATUS_PAYMENT_FLAGGED or i.status == Order.STATUS_PAID:
                continue
                        
            if i.reminder_email_sent == True: 
                continue

            abandoned_basket(i) # send the email
            i.reminder_email_sent = True # update the order
            i.save()
            sent.append(i) 
        
        
        if sent:
            _admin_cron_update(data=sent, subject_line="ABANDONED BASKET emails sent today")      
    def handle_noargs(self, **options):

        # SET A DATE RANGE OF 1 DAY
        start_date = (datetime.now() - timedelta(days=1))
        end_date = datetime.now()

        seen = {}
        items = []

        # MAKE A LIST OF ORDERS THAT WERE MADE IN THE LAST DAY (PAID OR NOT, WE DON'T CARE)
        orders = Order.objects.filter(
            date_confirmed__range=(start_date,
                                   end_date), ).order_by('-date_confirmed')

        # UNIQUE-IFY THE LIST AGAINST EMAIL ADDRESS SO WE ONLY HAVE THE MOST RECENT ONE
        for o in orders:
            marker = o.owner.email
            if marker in seen: continue
            seen[marker] = 1
            items.append(o)

        # NOW WE HAVE THE MOST RECENT ORDER. IF IT ISN'T PAID, AND HASNT ALREADY
        # HAD AN EMAIL, LET'S EMAIL THEM.
        sent = []
        for i in items:

            if i.date_paid:
                continue

            if i.status == Order.STATUS_PAYMENT_FLAGGED or i.status == Order.STATUS_PAID:
                continue

            if i.reminder_email_sent == True:
                continue

            abandoned_basket(i)  # send the email
            i.reminder_email_sent = True  # update the order
            i.save()
            sent.append(i)

        if sent:
            _admin_cron_update(
                data=sent, subject_line="ABANDONED BASKET emails sent today")