Subversion Repositories SmartDukaan

Rev

Rev 1341 | Rev 1382 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1341 Rev 1351
Line 24... Line 24...
24
from sqlalchemy.sql.expression import and_
24
from sqlalchemy.sql.expression import and_
25
from shop2020.model.v1 import order
25
from shop2020.model.v1 import order
26
from shop2020.clients.LogisticsClient import LogisticsClient
26
from shop2020.clients.LogisticsClient import LogisticsClient
27
from shop2020.clients.InventoryClient import InventoryClient
27
from shop2020.clients.InventoryClient import InventoryClient
28
from shop2020.clients.UserClient import UserClient
28
from shop2020.clients.UserClient import UserClient
-
 
29
from shop2020.clients.HelperClient import HelperClient
29
 
30
 
30
def get_new_transaction():
31
def get_new_transaction():
31
    transaction = Transaction()
32
    transaction = Transaction()
32
    transaction.createdOn = datetime.datetime.now()
33
    transaction.createdOn = datetime.datetime.now()
33
    transaction.status = TransactionStatus.INIT
34
    transaction.status = TransactionStatus.INIT
Line 161... Line 162...
161
            order.tracking_id = order.airwaybill_no
162
            order.tracking_id = order.airwaybill_no
162
            order.expected_delivery_time = datetime.datetime.now() + datetime.timedelta(days=logistics_info.deliveryTime)
163
            order.expected_delivery_time = datetime.datetime.now() + datetime.timedelta(days=logistics_info.deliveryTime)
163
            
164
            
164
            catalog_client = InventoryClient().get_client()
165
            catalog_client = InventoryClient().get_client()
165
            catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
166
            catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
-
 
167
 
166
            item_pricing = catalog_client.getItemPricing(item_id, order.warehouse_id)
168
            item_pricing = catalog_client.getItemPricing(item_id, order.warehouse_id)
167
            order.lineitems[0].transfer_price = item_pricing.transferPrice
169
            order.lineitems[0].transfer_price = item_pricing.transferPrice
168
        
170
        
169
        try:
171
        try:
170
            #Email the information of order placed to customer
172
            #Email the information of order placed to customer
Line 234... Line 236...
234
#    formated_order_date = strftime("%B %d, %Y %H:%M %p", time.strptime(order_date, "%Y-%m-%d %H:%M:%S"))
236
#    formated_order_date = strftime("%B %d, %Y %H:%M %p", time.strptime(order_date, "%Y-%m-%d %H:%M:%S"))
235
    formated_order_date = order_date
237
    formated_order_date = order_date
236
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date))
238
    email_header = Template(html_header).substitute(dict(order_date = formated_order_date))
237
    email_footer = Template(html_footer).substitute(dict(total_amount = total_amount))
239
    email_footer = Template(html_footer).substitute(dict(total_amount = total_amount))
238
    
240
    
-
 
241
    try:
239
    user_client = UserClient().get_client()
242
        user_client = UserClient().get_client()
240
    user = user_client.getUserById(transaction.customer_id)
243
        user = user_client.getUserById(transaction.customer_id)
241
    sendMail(Email(email_header + html_table + email_footer, "Saholic - Order Details", user.email))
-
 
242
    return True
-
 
243
 
-
 
244
class Email:
-
 
245
    def __init__(self, message, subject, to):
-
 
246
        self.data = message
-
 
247
        self.sender = ''
-
 
248
        self.subject = subject
-
 
249
        self.to = [to]
-
 
250
 
-
 
251
def sendMail(mail):
-
 
252
    if not mail:
-
 
253
        raise Exception(101, "mail not present")
-
 
254
    #msg = MIMEMultipart()
-
 
255
    #mail = Mail()
-
 
256
    if mail.sender:
-
 
257
        mail.data = "This mail is sent by " + mail.sender + "\n" + mail.data
-
 
258
        
-
 
259
    msg = MIMEText(mail.data, 'html')
-
 
260
    msg['To'] = ', '.join( mail.to )
-
 
261
    if mail.sender:
-
 
262
        msg['From'] = mail.sender
-
 
263
    else:    
-
 
264
        msg['From'] = "help@saholic.com"
-
 
265
    msg['Subject'] = mail.subject
-
 
266
    #msg.attach(mail.data)
-
 
267
    
244
    
268
    for to in mail.to:
-
 
269
        mail.sender = "help@shop2020.in"
245
        helper_client = HelperClient().get_client()
270
        mail.password = "5h0p2o2o"
246
        mail = Mail(user.email, "Saholic - Order Details", email_header + html_table + email_footer, None, None, None)
271
        mailServer = smtplib.SMTP("smtp.gmail.com", 587)
247
        helper_client.sendMail(mail)
272
        mailServer.ehlo()
248
        return True
273
        mailServer.starttls()
249
    except Exception as e:
274
        mailServer.ehlo()
250
        print e
275
        mailServer.login(mail.sender, mail.password)
-
 
276
        mailServer.sendmail(mail.password, to, msg.as_string())
-
 
277
        # Should be mailServer.quit(), but that crashes...
-
 
278
        mailServer.close()
251
        return False
279
 
252
 
280
def get_order(order_id):
253
def get_order(order_id):
281
    order = Order.get_by(id=order_id)
254
    order = Order.get_by(id=order_id)
282
    if not order:
255
    if not order:
283
        raise TransactionServiceException(108, "no such order")
256
        raise TransactionServiceException(108, "no such order")