Esempio n. 1
0
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
#        order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order, state='cancelled')

        product = self.order_items[0].seller_rate_chart.product
        qty = self.order_items[0].qty

        products_map = {}
        sellers_map = {}
        sellers_order_item_map = {}
        seller_total_map = {}
        seller_mrp_map = {}
        seller_discount_map = {}
        seller_shipping_charges_map = {}
        seller_product_map = {}
        seller_coupon_map = {}

        for item in self.order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product
            sellers_map[seller_id] = seller
            sellers_order_item_map[seller_id]  = 1
            if seller_id in seller_total_map:
                seller_total_map[seller_id] += (item.sale_price + item.shipping_charges)
            else:
                seller_total_map[seller_id] = (item.sale_price + item.shipping_charges)
            
            if seller_id in seller_shipping_charges_map:
                seller_shipping_charges_map[seller_id] += (item.shipping_charges)
            else:
                seller_shipping_charges_map[seller_id] = (item.shipping_charges)
            
            if seller_id in seller_mrp_map:
                seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price)
            else:
                seller_mrp_map[seller_id] =  (item.list_price if item.list_price else item.sale_price)

            if seller_id in seller_discount_map:
                seller_discount_map[seller.id] += (item.list_price - item.sale_price)
            else:
                seller_discount_map[seller.id] = (item.list_price - item.sale_price)

            if seller_id in seller_product_map:
                seller_product_map[seller_id].append(product)
            else:
                seller_product_map[seller_id] = [product]

        buyer_st = {}
        subject_st = {}
        buyer_sms_st = {}
        subject_sms_st = {}

        self.fill_attributes(self.order, product, buyer_st, subject_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map)

        self.fill_attributes(self.order, product, buyer_sms_st, subject_sms_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map)

        t_body = get_template('order/buyer_cancelled_order.email')
        t_sub = get_template('order/buyer_cancelled_order_sub.email')
        ctxt_body = buyer_st
        c_body = Context(ctxt_body)
        ctxt_sub = subject_st
        c_sub = Context(ctxt_sub)

        email_sent_from = "%s<order@%s>" % (self.order.client.name, self.order.client.clientdomain_name)
        email_body = t_body.render(c_body)
        email_subject = t_sub.render(c_sub)
        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            emails = emails.strip(',')
            email_to = emails
            email_bcc = "customerservice@%s" % self.order.client.clientdomain_name
        else:
            email_to = "customerservice@%s" % self.order.client.clientdomain_name 
            email_bcc = ""

        bemail = CEmail()
        bemail._from = email_sent_from
        bemail.body =  email_body
        bemail.subject = email_subject
        bemail.isHtml = True
        bemail.to = email_to
        bemail.bcc = email_bcc
        email_log = LEmail(client_domain = self.request.client,
                          order = self.order,
                          profile = self.order.user,
                          sent_to = email_to[:999],
                          bccied_to = email_bcc,
                          sent_from = email_sent_from,
                          subject = email_subject,
                          body = email_body,
                          status = 'in_queue',
                          type = 'buyer_order_cancellation')
        email_log.save()
        bemail.email_log_id = email_log.id
        notifications.append(bemail)

        sms = SMS()
        t_sms_body = get_template('order/buyer_cancelled_order.sms')
        ctxt_sms_body = buyer_sms_st
        c_sms_body = Context(ctxt_sms_body)
        sms.text = t_sms_body.render(c_sms_body)
        sms.to = buyer.primary_phone
        sms.mask = self.order.client.sms_mask
        notifications.append(sms)
        
        for seller_id in sellers_map:
            current_seller = sellers_map[seller_id]
            seller_body = {}
            seller_sub = {}
            self.fill_attributes(self.order, product, seller_body,\
                seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\
                seller_product_map, seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map)
            
            t_body = get_template('order/seller_cancelled_order.email')
            ctxt_body = seller_body
            c_body = Context(ctxt_body)
            t_sub = get_template('order/seller_cancelled_order_sub.email')
            ctxt_sub = seller_sub
            c_sub = Context(ctxt_sub)
            seller_emails = current_seller.get_confirmed_order_notification_email_addresses()

            email_sent_from = "%s<order@%s>" % (self.order.client.name, self.order.client.clientdomain_name) #self.order.client.pending_order_email
            email_body =  t_body.render(c_body)
            email_subject = t_sub.render(c_sub)
            email_bcc = ''
            if seller_emails:
                email_to = seller_emails
                email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name
            else:
                email_to = "fulfillment@%s" % self.order.client.clientdomain_name

            semail = CEmail()
            semail._from = email_sent_from
            semail.body = email_body
            semail.subject = email_subject
            semail.to = email_to
            semail.isHtml = True
            semail.bcc = email_bcc

            email_log = LEmail(client_domain = self.request.client,
                          order = self.order,
                          profile = self.order.user,
                          sent_to = email_to[:999],
                          bccied_to = email_bcc,
                          sent_from = email_sent_from,
                          subject = email_subject,
                          body = email_body,
                          status = 'in_queue',
                          type = 'seller_order_cancellation')
            email_log.save()
            semail.email_log_id = email_log.id
            notifications.append(semail)
        
        return notifications
Esempio n. 2
0
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
        order_items = OrderItem.objects.select_related(
            'seller_rate_chart').filter(order=self.order)
        product = order_items[0].seller_rate_chart.product
        qty = order_items[0].qty

        products_map = {}

        for item in order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product

        email_body_ctxt = {}
        email_subject_ctxt = {}
        sms_body_ctxt = {}
        sms_subject_ctxt = {}

        self.fill_attributes(self.order, product, email_body_ctxt, email_subject_ctxt,\
            buyer, products_map, qty)

        self.fill_attributes(self.order, product, sms_body_ctxt, sms_subject_ctxt,\
            buyer, products_map, qty)

        t_body = get_template('notifications/order/shipped_order.email')
        t_sub = get_template('notifications/order/shipped_order_sub.email')
        ctxt_body = email_body_ctxt
        c_body = Context(ctxt_body)
        ctxt_sub = email_subject_ctxt
        c_sub = Context(ctxt_sub)

        email_body = t_body.render(c_body)
        email_subject = t_sub.render(c_sub)
        email_sent_from = "%s<fulfillment@%s>" % (
            self.order.client.name, self.order.client.clientdomain_name)
        email_bcc, email_to = '', ''

        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            email_to = emails.strip(',')
            email_bcc = "customerservice@%s" % self.order.client.clientdomain_name
        else:
            email_to = "customerservice@%s" % self.order.client.clientdomain_name
            email_bcc = ""

        bemail = NEmail()
        bemail.body = email_body
        bemail.subject = email_subject
        bemail.to = email_to
        bemail._from = email_sent_from
        bemail.bcc = email_bcc
        bemail.isHtml = True
        email_log = LEmail(client_domain=self.request.client,
                           order=self.order,
                           profile=self.order.user,
                           sent_to=email_to[:999],
                           bccied_to=email_bcc,
                           sent_from=email_sent_from,
                           subject=email_subject,
                           body=email_body,
                           status='in_queue',
                           type='shipped_order')
        email_log.save()
        bemail.email_log_id = email_log.id
        notifications.append(bemail)

        if buyer.get_primary_phones():
            sms = SMS()
            t_sms_body = get_template('notifications/order/shipped_order.sms')
            ctxt_sms_body = sms_body_ctxt
            c_sms_body = Context(ctxt_sms_body)
            sms.text = t_sms_body.render(c_sms_body)
            sms.to = buyer.get_primary_phones()[0].phone
            sms.mask = self.order.client.sms_mask
            notifications.append(sms)

        return notifications
Esempio n. 3
0
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
        #        order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order, state='cancelled')

        product = self.order_items[0].seller_rate_chart.product
        qty = self.order_items[0].qty

        products_map = {}
        sellers_map = {}
        sellers_order_item_map = {}
        seller_total_map = {}
        seller_mrp_map = {}
        seller_discount_map = {}
        seller_shipping_charges_map = {}
        seller_product_map = {}
        seller_coupon_map = {}

        for item in self.order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product
            sellers_map[seller_id] = seller
            sellers_order_item_map[seller_id] = 1
            if seller_id in seller_total_map:
                seller_total_map[seller_id] += (item.sale_price +
                                                item.shipping_charges)
            else:
                seller_total_map[seller_id] = (item.sale_price +
                                               item.shipping_charges)

            if seller_id in seller_shipping_charges_map:
                seller_shipping_charges_map[seller_id] += (
                    item.shipping_charges)
            else:
                seller_shipping_charges_map[seller_id] = (
                    item.shipping_charges)

            if seller_id in seller_mrp_map:
                seller_mrp_map[seller_id] += (
                    item.list_price if item.list_price else item.sale_price)
            else:
                seller_mrp_map[seller_id] = (item.list_price if item.list_price
                                             else item.sale_price)

            if seller_id in seller_discount_map:
                seller_discount_map[seller.id] += (item.list_price -
                                                   item.sale_price)
            else:
                seller_discount_map[seller.id] = (item.list_price -
                                                  item.sale_price)

            if seller_id in seller_product_map:
                seller_product_map[seller_id].append(product)
            else:
                seller_product_map[seller_id] = [product]

        buyer_st = {}
        subject_st = {}
        buyer_sms_st = {}
        subject_sms_st = {}

        self.fill_attributes(self.order, product, buyer_st, subject_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map)

        self.fill_attributes(self.order, product, buyer_sms_st, subject_sms_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map)

        t_body = get_template('order/buyer_cancelled_order.email')
        t_sub = get_template('order/buyer_cancelled_order_sub.email')
        ctxt_body = buyer_st
        c_body = Context(ctxt_body)
        ctxt_sub = subject_st
        c_sub = Context(ctxt_sub)

        email_sent_from = "%s<order@%s>" % (
            self.order.client.name, self.order.client.clientdomain_name)
        email_body = t_body.render(c_body)
        email_subject = t_sub.render(c_sub)
        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            emails = emails.strip(',')
            email_to = emails
            email_bcc = "customerservice@%s" % self.order.client.clientdomain_name
        else:
            email_to = "customerservice@%s" % self.order.client.clientdomain_name
            email_bcc = ""

        bemail = CEmail()
        bemail._from = email_sent_from
        bemail.body = email_body
        bemail.subject = email_subject
        bemail.isHtml = True
        bemail.to = email_to
        bemail.bcc = email_bcc
        email_log = LEmail(client_domain=self.request.client,
                           order=self.order,
                           profile=self.order.user,
                           sent_to=email_to[:999],
                           bccied_to=email_bcc,
                           sent_from=email_sent_from,
                           subject=email_subject,
                           body=email_body,
                           status='in_queue',
                           type='buyer_order_cancellation')
        email_log.save()
        bemail.email_log_id = email_log.id
        notifications.append(bemail)

        sms = SMS()
        t_sms_body = get_template('order/buyer_cancelled_order.sms')
        ctxt_sms_body = buyer_sms_st
        c_sms_body = Context(ctxt_sms_body)
        sms.text = t_sms_body.render(c_sms_body)
        sms.to = buyer.primary_phone
        sms.mask = self.order.client.sms_mask
        notifications.append(sms)

        for seller_id in sellers_map:
            current_seller = sellers_map[seller_id]
            seller_body = {}
            seller_sub = {}
            self.fill_attributes(self.order, product, seller_body,\
                seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\
                seller_product_map, seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map)

            t_body = get_template('order/seller_cancelled_order.email')
            ctxt_body = seller_body
            c_body = Context(ctxt_body)
            t_sub = get_template('order/seller_cancelled_order_sub.email')
            ctxt_sub = seller_sub
            c_sub = Context(ctxt_sub)
            seller_emails = current_seller.get_confirmed_order_notification_email_addresses(
            )

            email_sent_from = "%s<order@%s>" % (
                self.order.client.name, self.order.client.clientdomain_name
            )  #self.order.client.pending_order_email
            email_body = t_body.render(c_body)
            email_subject = t_sub.render(c_sub)
            email_bcc = ''
            if seller_emails:
                email_to = seller_emails
                email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name
            else:
                email_to = "fulfillment@%s" % self.order.client.clientdomain_name

            semail = CEmail()
            semail._from = email_sent_from
            semail.body = email_body
            semail.subject = email_subject
            semail.to = email_to
            semail.isHtml = True
            semail.bcc = email_bcc

            email_log = LEmail(client_domain=self.request.client,
                               order=self.order,
                               profile=self.order.user,
                               sent_to=email_to[:999],
                               bccied_to=email_bcc,
                               sent_from=email_sent_from,
                               subject=email_subject,
                               body=email_body,
                               status='in_queue',
                               type='seller_order_cancellation')
            email_log.save()
            semail.email_log_id = email_log.id
            notifications.append(semail)

        return notifications
Esempio n. 4
0
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
        #if self.order.payment_mode in ['cash-at-store', 'card-at-store']:
            # Skip notifications for cash and card at store now
            # Might need to reenable them. Need to move this
            # checking to domain payment options.
        #    return []
        order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order)
        product = order_items[0].seller_rate_chart.product
        qty = order_items[0].qty

        products_map = {}
        sellers_map = {}
        sellers_order_item_map = {}
        seller_total_map = {}
        seller_mrp_map = {}
        seller_offer_price_map = {}
        seller_discount_map = {}
        seller_cashback_map ={}
        seller_shipping_charges_map = {}
        seller_product_map = {}
        seller_coupon_map = {}
        for item in order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product
            sellers_map[seller_id] = seller
            sellers_order_item_map[seller_id]  = 1
            if seller_id in seller_total_map:
                seller_total_map[seller_id] += (item.sale_price + item.shipping_charges)
            else:
                seller_total_map[seller_id] = (item.sale_price + item.shipping_charges)
            
            if seller_id in seller_shipping_charges_map:
                seller_shipping_charges_map[seller_id] += (item.shipping_charges)
            else:
                seller_shipping_charges_map[seller_id] = (item.shipping_charges)
            
            if seller_id in seller_mrp_map:
                seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price)
            else:
                seller_mrp_map[seller_id] =  (item.list_price if item.list_price else item.sale_price)
            if seller_id in seller_offer_price_map:
                seller_offer_price_map[seller_id] += item.sale_price
            else:
                seller_offer_price_map[seller_id] =  item.sale_price
            if seller_id in seller_discount_map:
                seller_discount_map[seller.id] += (item.list_price - item.sale_price)
            else:
                seller_discount_map[seller.id] = (item.list_price - item.sale_price)

            if seller_id in seller_cashback_map:
                seller_cashback_map[seller.id] += item.cashback_amount
            else:
                seller_cashback_map[seller.id] = item.cashback_amount
                
            if seller_id in seller_product_map:
                seller_product_map[seller_id].append(product)
            else:
                seller_product_map[seller_id] = [product]
            


        buyer_st = {}
        subject_st = {}
        buyer_sms_st = {}
        subject_sms_st = {}

        self.fill_attributes(self.order, order_items[0], product, buyer_st, subject_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

        self.fill_attributes(self.order, order_items[0], product, buyer_sms_st, subject_sms_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

        t_body = get_template('notifications/order/buyer_pending_order.email')
        t_sub = get_template('notifications/order/buyer_pending_order_sub.email')
        ctxt_body = buyer_st
        ctxt_body['clientdomain_name'] = 'www.%s' % self.order.client.clientdomain_name
        c_body = Context(ctxt_body)
        ctxt_sub = subject_st
        c_sub = Context(ctxt_sub)
        log.info('emails %s' % buyer.get_primary_emails())

        email_sent_from =  "%s<lead@%s>" % (self.order.client.name,
            self.order.client.clientdomain_name)
        email_body = t_body.render(c_body)
        email_subject = t_sub.render(c_sub)
        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            emails = emails.strip(',')
            email_to = emails
            log.info('to%s' % email_to)
            email_bcc = "presales@%s" % self.order.client.clientdomain_name
        else:
            email_to = "presales@%s" % self.order.client.clientdomain_name
            email_bcc = ''

        bemail = NEmail()
        bemail._from = email_sent_from
        bemail.body =  email_body
        bemail.subject = email_subject
        bemail.isHtml = True
        bemail.to = email_to
        bemail.bcc = email_bcc
        email_to = email_to[:1000] 
        email_log = LEmail(client_domain = self.request.client,
                          order = self.order,
                          profile = self.order.user,
                          sent_to = email_to[:999],
                          bccied_to = email_bcc,
                          sent_from = email_sent_from,
                          subject = email_subject,
                          body = email_body,
                          status = 'in_queue',
                          type = 'buyer_pending_order')
        email_log.save()
        bemail.email_log_id = email_log.id

        if 'buyer' in self.groups:
            notifications.append(bemail)
#        elif 'admin' in self.groups:
#            bemail.to = "presales@%s" % self.order.client.clientdomain_name
#            notifications.append(bemail)

        if 'buyer' in self.groups:
            if buyer.get_primary_phones():
                bsms = SMS()
                t_sms_body = get_template('notifications/order/buyer_pending_order.sms')
                ctxt_sms_body = buyer_sms_st
                c_sms_body = Context(ctxt_sms_body)
                bsms.text = t_sms_body.render(c_sms_body)
                bsms.to = buyer.get_primary_phones()[0].phone
                bsms.mask = self.order.client.sms_mask
                notifications.append(bsms)

        for seller_id in sellers_map:
            current_seller = sellers_map[seller_id]
            seller_body = {}
            seller_sub = {}
            self.fill_attributes(self.order, order_items[0], product, seller_body,\
                seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\
                seller_product_map, seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)
            
            t_body = get_template('notifications/order/seller_pending_order.email')
            ctxt_body = seller_body
            c_body = Context(ctxt_body)
            t_sub = get_template('notifications/order/seller_pending_order_sub.email')
            ctxt_sub = seller_sub
            c_sub = Context(ctxt_sub)
            seller_emails = current_seller.get_pending_order_notification_email_addresses()

            email_sent_from = "%s<lead@%s>" % (self.order.client.name,
                self.order.client.clientdomain_name)
            email_body =  t_body.render(c_body)
            email_subject = t_sub.render(c_sub)
            email_bcc = '' 
            if seller_emails:
                email_to = seller_emails
                email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name
            else:
                email_to = "fulfillment@%s" % self.order.client.clientdomain_name

            semail = NEmail()
            semail._from = email_sent_from
            semail.body = email_body
            semail.subject = email_subject
            semail.to = email_to
            semail.isHtml = True
            semail.bcc = email_bcc

            email_log = LEmail(client_domain = self.request.client,
                          order = self.order,
                          profile = self.order.user,
                          sent_to = email_to[:999],
                          bccied_to = email_bcc,
                          sent_from = email_sent_from,
                          subject = email_subject,
                          body = email_body,
                          status = 'in_queue',
                          type = 'seller_pending_order')
            email_log.save()
            semail.email_log_id = email_log.id

            if 'seller' in self.groups:
                notifications.append(semail)
#            elif 'admin' in self.groups:
#                notifications.append(semail)
                
        return notifications
Esempio n. 5
0
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
        order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order)
        product = order_items[0].seller_rate_chart.product
        qty = order_items[0].qty

        products_map = {}

        for item in order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product

        email_body_ctxt = {}
        email_subject_ctxt = {}
        sms_body_ctxt = {}
        sms_subject_ctxt = {}

        self.fill_attributes(self.order, product, email_body_ctxt, email_subject_ctxt,\
            buyer, products_map, qty)

        self.fill_attributes(self.order, product, sms_body_ctxt, sms_subject_ctxt,\
            buyer, products_map, qty)

        t_body = get_template('notifications/order/shipped_order.email')
        t_sub = get_template('notifications/order/shipped_order_sub.email')
        ctxt_body = email_body_ctxt
        c_body = Context(ctxt_body)
        ctxt_sub = email_subject_ctxt
        c_sub = Context(ctxt_sub)

        email_body = t_body.render(c_body)
        email_subject =  t_sub.render(c_sub)
        email_sent_from =  "%s<fulfillment@%s>" % (self.order.client.name, 
            self.order.client.clientdomain_name)
        email_bcc, email_to = '', ''

        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            email_to = emails.strip(',')
            email_bcc = "customerservice@%s" % self.order.client.clientdomain_name
        else:
            email_to = "customerservice@%s" % self.order.client.clientdomain_name
            email_bcc = ""

        bemail = NEmail()
        bemail.body = email_body
        bemail.subject = email_subject
        bemail.to = email_to
        bemail._from = email_sent_from
        bemail.bcc = email_bcc
        bemail.isHtml = True
        email_log = LEmail(client_domain = self.request.client,
                          order = self.order,
                          profile = self.order.user,
                          sent_to = email_to[:999],
                          bccied_to = email_bcc,
                          sent_from = email_sent_from,
                          subject = email_subject,
                          body = email_body,
                          status = 'in_queue',
                          type = 'shipped_order')
        email_log.save()
        bemail.email_log_id = email_log.id
        notifications.append(bemail)
        
        if buyer.get_primary_phones():
            sms = SMS()
            t_sms_body = get_template('notifications/order/shipped_order.sms')
            ctxt_sms_body = sms_body_ctxt
            c_sms_body = Context(ctxt_sms_body)
            sms.text = t_sms_body.render(c_sms_body)
            sms.to = buyer.get_primary_phones()[0].phone
            sms.mask = self.order.client.sms_mask
            notifications.append(sms)
        
        return notifications
Esempio n. 6
0
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
        #if self.order.payment_mode in ['cash-at-store', 'card-at-store']:
        # Skip notifications for cash and card at store now
        # Might need to reenable them. Need to move this
        # checking to domain payment options.
        #    return []
        order_items = OrderItem.objects.select_related(
            'seller_rate_chart').filter(order=self.order)
        product = order_items[0].seller_rate_chart.product
        qty = order_items[0].qty

        products_map = {}
        sellers_map = {}
        sellers_order_item_map = {}
        seller_total_map = {}
        seller_mrp_map = {}
        seller_offer_price_map = {}
        seller_discount_map = {}
        seller_cashback_map = {}
        seller_shipping_charges_map = {}
        seller_product_map = {}
        seller_coupon_map = {}
        for item in order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product
            sellers_map[seller_id] = seller
            sellers_order_item_map[seller_id] = 1
            if seller_id in seller_total_map:
                seller_total_map[seller_id] += (item.sale_price +
                                                item.shipping_charges)
            else:
                seller_total_map[seller_id] = (item.sale_price +
                                               item.shipping_charges)

            if seller_id in seller_shipping_charges_map:
                seller_shipping_charges_map[seller_id] += (
                    item.shipping_charges)
            else:
                seller_shipping_charges_map[seller_id] = (
                    item.shipping_charges)

            if seller_id in seller_mrp_map:
                seller_mrp_map[seller_id] += (
                    item.list_price if item.list_price else item.sale_price)
            else:
                seller_mrp_map[seller_id] = (item.list_price if item.list_price
                                             else item.sale_price)
            if seller_id in seller_offer_price_map:
                seller_offer_price_map[seller_id] += item.sale_price
            else:
                seller_offer_price_map[seller_id] = item.sale_price
            if seller_id in seller_discount_map:
                seller_discount_map[seller.id] += (item.list_price -
                                                   item.sale_price)
            else:
                seller_discount_map[seller.id] = (item.list_price -
                                                  item.sale_price)

            if seller_id in seller_cashback_map:
                seller_cashback_map[seller.id] += item.cashback_amount
            else:
                seller_cashback_map[seller.id] = item.cashback_amount

            if seller_id in seller_product_map:
                seller_product_map[seller_id].append(product)
            else:
                seller_product_map[seller_id] = [product]

        buyer_st = {}
        subject_st = {}
        buyer_sms_st = {}
        subject_sms_st = {}

        self.fill_attributes(self.order, order_items[0], product, buyer_st, subject_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

        self.fill_attributes(self.order, order_items[0], product, buyer_sms_st, subject_sms_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

        t_body = get_template('notifications/order/buyer_pending_order.email')
        t_sub = get_template(
            'notifications/order/buyer_pending_order_sub.email')
        ctxt_body = buyer_st
        ctxt_body[
            'clientdomain_name'] = 'www.%s' % self.order.client.clientdomain_name
        c_body = Context(ctxt_body)
        ctxt_sub = subject_st
        c_sub = Context(ctxt_sub)
        log.info('emails %s' % buyer.get_primary_emails())

        email_sent_from = "%s<lead@%s>" % (self.order.client.name,
                                           self.order.client.clientdomain_name)
        email_body = t_body.render(c_body)
        email_subject = t_sub.render(c_sub)
        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            emails = emails.strip(',')
            email_to = emails
            log.info('to%s' % email_to)
            email_bcc = "presales@%s" % self.order.client.clientdomain_name
        else:
            email_to = "presales@%s" % self.order.client.clientdomain_name
            email_bcc = ''

        bemail = NEmail()
        bemail._from = email_sent_from
        bemail.body = email_body
        bemail.subject = email_subject
        bemail.isHtml = True
        bemail.to = email_to
        bemail.bcc = email_bcc
        email_to = email_to[:1000]
        email_log = LEmail(client_domain=self.request.client,
                           order=self.order,
                           profile=self.order.user,
                           sent_to=email_to[:999],
                           bccied_to=email_bcc,
                           sent_from=email_sent_from,
                           subject=email_subject,
                           body=email_body,
                           status='in_queue',
                           type='buyer_pending_order')
        email_log.save()
        bemail.email_log_id = email_log.id

        if 'buyer' in self.groups:
            notifications.append(bemail)
#        elif 'admin' in self.groups:
#            bemail.to = "presales@%s" % self.order.client.clientdomain_name
#            notifications.append(bemail)

        if 'buyer' in self.groups:
            if buyer.get_primary_phones():
                bsms = SMS()
                t_sms_body = get_template(
                    'notifications/order/buyer_pending_order.sms')
                ctxt_sms_body = buyer_sms_st
                c_sms_body = Context(ctxt_sms_body)
                bsms.text = t_sms_body.render(c_sms_body)
                bsms.to = buyer.get_primary_phones()[0].phone
                bsms.mask = self.order.client.sms_mask
                notifications.append(bsms)

        for seller_id in sellers_map:
            current_seller = sellers_map[seller_id]
            seller_body = {}
            seller_sub = {}
            self.fill_attributes(self.order, order_items[0], product, seller_body,\
                seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\
                seller_product_map, seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

            t_body = get_template(
                'notifications/order/seller_pending_order.email')
            ctxt_body = seller_body
            c_body = Context(ctxt_body)
            t_sub = get_template(
                'notifications/order/seller_pending_order_sub.email')
            ctxt_sub = seller_sub
            c_sub = Context(ctxt_sub)
            seller_emails = current_seller.get_pending_order_notification_email_addresses(
            )

            email_sent_from = "%s<lead@%s>" % (
                self.order.client.name, self.order.client.clientdomain_name)
            email_body = t_body.render(c_body)
            email_subject = t_sub.render(c_sub)
            email_bcc = ''
            if seller_emails:
                email_to = seller_emails
                email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name
            else:
                email_to = "fulfillment@%s" % self.order.client.clientdomain_name

            semail = NEmail()
            semail._from = email_sent_from
            semail.body = email_body
            semail.subject = email_subject
            semail.to = email_to
            semail.isHtml = True
            semail.bcc = email_bcc

            email_log = LEmail(client_domain=self.request.client,
                               order=self.order,
                               profile=self.order.user,
                               sent_to=email_to[:999],
                               bccied_to=email_bcc,
                               sent_from=email_sent_from,
                               subject=email_subject,
                               body=email_body,
                               status='in_queue',
                               type='seller_pending_order')
            email_log.save()
            semail.email_log_id = email_log.id

            if 'seller' in self.groups:
                notifications.append(semail)
#            elif 'admin' in self.groups:
#                notifications.append(semail)

        return notifications
    def getNotifications(self):
        notifications = []
        buyer = self.order.user
        #if self.order.payment_mode in ['cash-at-store', 'card-at-store']:
            # Skip notifications for cash and card at store now
            # Might need to reenable them. Need to move this
            # checking to domain payment options.
        #    return []
        order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order)
        product = order_items[0].seller_rate_chart.product
        qty = order_items[0].qty

        products_map = {}
        sellers_map = {}
        sellers_order_item_map = {}
        seller_total_map = {}
        seller_mrp_map = {}
        seller_offer_price_map = {}
        seller_discount_map = {}
        seller_cashback_map ={}
        seller_shipping_charges_map = {}
        seller_product_map = {}
        seller_coupon_map = {}
        for item in order_items:
            seller = item.seller_rate_chart.seller
            seller_id = seller.id
            product = item.seller_rate_chart.product
            products_map[product.id] = product
            sellers_map[seller_id] = seller
            sellers_order_item_map[seller_id]  = 1
            if seller_id in seller_total_map:
                seller_total_map[seller_id] += (item.sale_price + item.shipping_charges)
            else:
                seller_total_map[seller_id] = (item.sale_price + item.shipping_charges)
            
            if seller_id in seller_shipping_charges_map:
                seller_shipping_charges_map[seller_id] += (item.shipping_charges)
            else:
                seller_shipping_charges_map[seller_id] = (item.shipping_charges)
            
            if seller_id in seller_mrp_map:
                seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price)
            else:
                seller_mrp_map[seller_id] =  (item.list_price if item.list_price else item.sale_price)
            if seller_id in seller_offer_price_map:
                seller_offer_price_map[seller_id] += item.sale_price
            else:
                seller_offer_price_map[seller_id] =  item.sale_price
            if seller_id in seller_discount_map:
                seller_discount_map[seller.id] += (item.list_price - item.sale_price)
            else:
                seller_discount_map[seller.id] = (item.list_price - item.sale_price)

            if seller_id in seller_cashback_map:
                seller_cashback_map[seller.id] += item.cashback_amount
            else:
                seller_cashback_map[seller.id] = item.cashback_amount
                
            if seller_id in seller_product_map:
                seller_product_map[seller_id].append(product)
            else:
                seller_product_map[seller_id] = [product]
            


        buyer_st = {}
        subject_st = {}
        buyer_sms_st = {}
        subject_sms_st = {}

        self.fill_attributes(self.order, order_items[0], product, buyer_st, subject_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

        self.fill_attributes(self.order, order_items[0], product, buyer_sms_st, subject_sms_st,\
            buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\
            seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map)

        t_body = get_template('order/buyer_payment_reminder.email')
        t_sub = get_template('order/buyer_payment_reminder_sub.email')
        ctxt_body = buyer_st
        # We will cancel the order 4 days after booking.
        cancel_time = self.order.timestamp + timedelta(days=4)
        now = datetime.now()
        if now > cancel_time:
            raise Exception(
                "Cannot send payment reminder after cancellation due date")
        remaining = (cancel_time - now)
        if remaining.days:
            ctxt_body['time_remaining'] = '%s days remaining' % remaining.days
        if remaining.days == 1:
            ctxt_body['time_remaining'] = '%s day remaining' % remaining.days
        if remaining.days == 0:
            ctxt_body['time_remaining'] = 'Last day'
        ctxt_body['clientdomain_name'] = 'www.%s' % self.order.client.clientdomain_name
        c_body = Context(ctxt_body)
        ctxt_sub = subject_st
        ctxt_sub['time_remaining'] = ctxt_body['time_remaining']
        c_sub = Context(ctxt_sub)
        log.info('emails %s' % buyer.get_primary_emails())

        email_sent_from =  "%s<lead@%s>" % (self.order.client.name,
            self.order.client.clientdomain_name)
        email_body = t_body.render(c_body)
        email_subject = t_sub.render(c_sub)
        if buyer.get_primary_emails():
            emails = ''
            for email in buyer.get_primary_emails():
                emails += email.email + ','
            emails = emails.strip(',')
            email_to = emails
            log.info('to%s' % email_to)
            email_bcc = "presales@%s" % self.order.client.clientdomain_name
        else:
            email_to = "presales@%s" % self.order.client.clientdomain_name
            email_bcc = ''

        bemail = NEmail()
        bemail._from = email_sent_from
        bemail.body =  email_body
        bemail.subject = email_subject
        bemail.isHtml = True
        bemail.to = email_to
        bemail.bcc = email_bcc
        email_to = email_to[:1000] 
        try:
            cd = ClientDomain.objects.get(client=self.order.client,
                domain = 'www.%s' % self.order.client.clientdomain_name)
            email_log = LEmail(client_domain = cd,
                              order = self.order,
                              profile = self.order.user,
                              sent_to = email_to,
                              bccied_to = email_bcc,
                              sent_from = email_sent_from,
                              subject = email_subject,
                              body = email_body,
                              status = 'in_queue',
                              type = 'buyer_payment_reminder')
            email_log.save()
            bemail.email_log_id = email_log.id
        except Exception:
            log.exception('Error saving payment_reminder log for %s' % self.order.id)

        if 'buyer' in self.groups:
            notifications.append(bemail)

        '''
        if 'buyer' in self.groups:
            if buyer.get_primary_phones():
                bsms = SMS()
                t_sms_body = get_template('order/buyer_pending_order.sms')
                ctxt_sms_body = buyer_sms_st
                c_sms_body = Context(ctxt_sms_body)
                bsms.text = t_sms_body.render(c_sms_body)
                bsms.to = buyer.get_primary_phones()[0].phone
                bsms.mask = self.order.client.sms_mask
                notifications.append(bsms)
        '''      
        return notifications