def email_log(message): msg = Message("%s Notice Fitboard" % (message), recipients=["*****@*****.**"]) msg.body = "NOTICE %s \n Logile Attached \n" % (message) with app.open_resource("fitboard.log") as fp: msg.attach("fitboard.log", "text/plain", fp.read()) mail.send(msg) return
def email_log(message): msg = Message("%s Notice Fitboard" % (message), recipients=["*****@*****.**"]) msg.body = "NOTICE %s \n Logile Attached \n" % (message) with app.open_resource("fitboard.log") as fp: msg.attach("fitboard.log", "text/plain", fp.read()) mail.send(msg) return
def post(self): """ create order for selling items components: schemas: Orders: properties: bill_amount: type: string c_address: type: string c_id: format: int32 type: integer c_mobileno: format: int32 type: integer customer_name: type: string i_id: format: int32 type: integer id: format: int32 type: integer sale_quantity: type: string required: - c_id - i_id - sale_quantity type: object """ response_obj = Response(mimetype='application/json') data = get_request_data(request) order_data = data.get('order', None) if not order_data: return {'message': 'No input data provided'}, 400 data, errors = order_schema.load(order_data) if errors: return {"status": "error", "data": errors}, 422 try: customer = Customer.query.filter_by(c_id=int(data['c_id'])).first() if not customer: response_obj.data = json.dumps({"msg": "please enter valid customer ID"}) item = Items.query.filter_by(i_id=int(data['i_id'])).first() if not item: response_obj.data = json.dumps({"msg": "please enter valid Item ID"}) total_quantity = item.item_quantity #print(total_quantity,"total qantity................") sale_quantity = data['sale_quantity'] #print(sale_quantity, "....sale_quantity") #print(sale_quantity,"sale_quantity") if int(sale_quantity) < 0: response_obj.data = json.dumps({"msg": "please enter positive sale quantity"}) else: if int(total_quantity) > 0 and int(sale_quantity) <= int(total_quantity): import random x=random.randint(1000000, 10000000) sale_item = SalesItems(x,customer.c_id, item.i_id, sale_quantity) item.item_quantity = int(total_quantity) - int(sale_quantity) ''' After selling item update Items table ''' db.session.add_all([sale_item,item]) db.session.commit() bill_amount = int(sale_quantity) * int(item.item_price) s_id = SalesItems.query.filter_by(i_id=item.i_id).first() print(s_id.id, "................id") bill = Bill(customer.c_id, item.i_id, x, bill_amount) """ send bill to the customer """ """" code for image Generation """ (x, y) = (100, 100) message = f"Invoice Details: \n\n Shop Name : Techno Hub \n\n Customer Name: {customer.customer_name}" \ f"\n\n Email : {customer.c_email} \n\n Item name: {item.item_name} \n\n" \ f" Quantity: {sale_quantity} \n\n Total amount: {bill_amount}" color = 'rgb(102, 255, 102)' draw.text((x, y), message, fill=color, font=font) image.save('bill.png',optimize=True, quality=40) """ End Image Bill Code """ msg = Message('Item Invoice', sender='*****@*****.**', recipients=[customer.c_email]) msg.body = "This is Your Item Invoice" with open("bill.png",'rb') as fp: msg.attach("bill.png", "image/png", fp.read()) #mail.send(msg) #print(f"Item name:{item.item_name} \n Item Quantity:{sale_quantity} \n Total Bill:{bill_amount}") db.session.add(bill) db.session.commit() item_cust_info = order_schema.dump(sale_item).data bill_info = bill_schema.dump(bill).data item_info = item_schema.dump(item).data """ Generate Yaml file """ #spec.components.schema("Orders", schema=OrderSchema) #print(spec.to_yaml()) response_obj.data = json.dumps(({"status": 'success', "Order": [{"Item_info":item_info},{"Sale-Item-Customer":item_cust_info},{"bill":bill_info},]})) else: response_obj.data = json.dumps({"msg":"please select less sale quantity from available quantity"}) except Exception as e: print(e) return response_obj