def get(self): claims = get_jwt_claims() if not claims['active']: return { 'message': 'Error # 25 in Order Resource, You have not been activated by the admin' }, 400 username = UserModel.find_by_user(get_jwt_identity()) ztime = datetime.datetime.now().date() ztime_31 = ztime - datetime.timedelta(31) try: child_list = HierarchyModel.find_by_child_of_code_single_user( username.employeeCode) child_list = [hier.json()['employee_code'] for hier in child_list] except Exception as e: print(e) if len(child_list) == 0: final_list = [username.employeeCode] else: try: full_list = HierarchyModel.find_all_hierarchy() full_list = [{ 'child': hier.json()['employee_code'], 'parent': hier.json()['child_of_code'] } for hier in full_list] except Exception as e: print(e) final_list = [username.employeeCode] for i in final_list: for j in full_list: if i == j['parent']: final_list.append(j['child']) terminal_list = UserModel.find_by_user_list(final_list) terminal_list = [term.json()['terminal'] for term in terminal_list] try: confirmedOrders = OpmobModel.find_confirmed( terminal_list, ztime_31) except Exception as e: print(e) return {'message': 'No orders created under your name'}, 400 invoice_no = '' count = 0 for orders in confirmedOrders: if invoice_no != orders.json()['invoice_no']: count += 1 invoice_no = orders.json()['invoice_no'] else: continue return {'Number_of_confirmedOrders': count}, 200
def get(self): claims = get_jwt_claims() if not claims['active']: return { 'message': 'Error # 25 in Order Resource, You have not been activated by the admin' }, 400 username = UserModel.find_by_user(get_jwt_identity()) ztime = datetime.datetime.now().date() ztime_31 = ztime - datetime.timedelta(31) try: child_list = HierarchyModel.find_by_child_of_code_single_user( username.employeeCode) child_list = [hier.json()['employee_code'] for hier in child_list] except Exception as e: print(e) if len(child_list) == 0: final_list = [username.employeeCode] else: try: full_list = HierarchyModel.find_all_hierarchy() full_list = [{ 'child': hier.json()['employee_code'], 'parent': hier.json()['child_of_code'] } for hier in full_list] except Exception as e: print(e) final_list = [username.employeeCode] for i in final_list: for j in full_list: if i == j['parent']: final_list.append(j['child']) terminal_list = UserModel.find_by_user_list(final_list) terminal_list = [term.json()['terminal'] for term in terminal_list] try: notConfirmedOrders = OpmobModel.find_not_confirmed( terminal_list, ztime_31) except Exception as e: print(e) return {'message': 'No orders created under your name'}, 400 reOrders = [] invoice_no = '' for orders in notConfirmedOrders: print(invoice_no) if invoice_no != orders.json()['invoice_no']: newOrderDict = {} newOrderDict['Entry_Date'] = orders.json()['Entry_Date'] newOrderDict['employeeCode'] = orders.json()['employeeCode'] newOrderDict['businessId'] = orders.json()['businessId'] newOrderDict['invoice_no'] = orders.json()['invoice_no'] newOrderDict['customerCode'] = orders.json()['customerCode'] newOrderDict['customerName'] = orders.json()['customerName'] products = [] orderTotal = 0 for ordersProduct in OpmobModel.find_by_invoiceno( orders.json()['invoice_no']): orderTotal += ordersProduct.json()['orderLineTotal'] invoice_product = { 'productCode': ordersProduct.json()['productCode'], 'productName': ordersProduct.json()['productName'], 'orderQty': ordersProduct.json()['orderQty'], 'orderPrice': ordersProduct.json()['orderPrice'], 'orderLineTotal': ordersProduct.json()['orderLineTotal'] } products.append(invoice_product) newOrderDict['orderTotal'] = orderTotal newOrderDict['products'] = products invoice_no = orders.json()['invoice_no'] reOrders.append(newOrderDict) else: continue return reOrders, 200
def delete(self, invoiceno): claims = get_jwt_claims() if not claims['active']: return { 'message': 'Error # 25 in Order Resource, You have not been activated by the admin' }, 400 username = UserModel.find_by_user(get_jwt_identity()) try: child_list = HierarchyModel.find_by_child_of_code_single_user( username.employeeCode) child_list = [hier.json()['employee_code'] for hier in child_list] except Exception as e: print(e) if len(child_list) == 0: final_list = [username.employeeCode] else: try: full_list = HierarchyModel.find_all_hierarchy() full_list = [{ 'child': hier.json()['employee_code'], 'parent': hier.json()['child_of_code'] } for hier in full_list] except Exception as e: print(e) final_list = [username.employeeCode] for i in final_list: for j in full_list: if i == j['parent']: final_list.append(j['child']) terminal_list = UserModel.find_by_user_list(final_list) terminal_list = [term.json()['terminal'] for term in terminal_list] if OpmobModel.find_by_invoiceno( invoiceno)[0].xterminal not in terminal_list: return {'message': 'You are not allowed to delete this order'}, 400 orderNum = [ ordernum.xordernum for ordernum in OpmobModel.find_by_invoiceno(invoiceno) ] if '' not in orderNum: return { 'message': 'You cannot delete this Order as it has already been confirmed' }, 400 orderDetail = OpmobModel.find_by_invoiceno(invoiceno) for orders in orderDetail: orders.delete_from_db() #################################### delete_key_value_pair_list = [('invoiceno', invoiceno)] #################################### delete_from_client_db_with_custom_key_by_celery.delay( OpmobModel.__tablename__, delete_key_value_pair_list) return {'message': 'Your order has been deleted'}, 200