コード例 #1
0
ファイル: run.py プロジェクト: fixitonline/flash_backup
def add_claims_to_jwt(identity):
    if UserModel.find_by_user(identity).is_admin == 'is_admin':  # instead of hard-coding, we should read from a config file to get a list of admins instead
        return {'is_admin': True,'active':True,'is_superuser':False}
    elif UserModel.find_by_user(identity).is_admin == 'is_superuser':
        return {'is_superuser': True,'is_admin':True,'active':True}
    elif UserModel.find_by_user(identity).status == 'active':
        return {'active': True,'is_admin':False,'is_superuser':False}
    return {'is_admin': False,'is_superuser':False,'active':False}
コード例 #2
0
    def delete(self, username):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'},400

        if not UserModel.find_by_user(username):
            return {'message':'This user does not exist in our system'},400

        parent_list = [parent.json()['child_of_code'] for parent in HierarchyModel.find_all_hierarchy()]

        if not username in parent_list:
            userDetail = UserModel.find_by_user(username)
            userDetail.delete_from_db()
            return {'message':'User has been deleted from our system'},200

        return {'message':'User still has children please assign children to other parent and then delete this user'},400
コード例 #3
0
ファイル: caitem.py プロジェクト: fixitonline/flash_backup
    def get(self):
        claims = get_jwt_claims()
        if not claims['active']:
            return {
                'message':
                'Error # 34 in Product Resource, You have not been activated by the admin'
            }, 400

        current_user = UserModel.find_by_user(get_jwt_identity())

        if not claims['is_superuser']:
            approved_zid_list = VbusinessModel.find_all_business_list()

            business_Id_list = [current_user.businessId]
            if current_user.businessId not in approved_zid_list:
                return {
                    'message':
                    'Error # 182 in Customer Resource, You have not been authorized to use this business'
                }, 400
        else:
            business_Id_list = VbusinessModel.find_all_business_list()

        category_list = CategoryModel.find_all_category_list()

        all_items = [
            item.json() for item in CaitemModel.find_by_zid_category(
                business_Id_list, category_list)
        ]

        product_count = len(all_items)
        return {'rowcount': product_count}, 200
コード例 #4
0
    def post(self):
        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'},400

        try:
            data = userLogSchema.load(json_data).data
        except ValidationError as err:
            return err.messages,400

        try:
            current_user = UserModel.find_by_user(data['username'])
        except KeyError:
            return {'message':'Sorry no username has been provided'},400

        if not current_user:
            return {'message': 'User {} doesn\'t exist'.format(data['username'])},400

        if current_user.status == 'inactive':
            return {'message': 'Your account has not been activated by the admin, please talk to your manager'},400

        try:
            logged_user = LoggedModel.find_by_user_businessid(current_user.username, current_user.businessId)
        except Exception as err:
            print(err)

        if logged_user:
            if current_user.username == logged_user.username:
                return {'message':'You are already logged in, only one session allowed per user'}, 400 

        if UserModel.verify_hash(data['password'],current_user.password):
            access_token = create_access_token(identity = data['username'])
            refresh_token = create_refresh_token(identity = data['username'])
            login_user = LoggedModel(
                    ztime = datetime.datetime.now(),
                    zutime = datetime.datetime.now(),
                    username = current_user.username,
                    businessId = current_user.businessId,
                    access_token = access_token,
                    refresh_token = refresh_token,
                    status = 'Logged In'
            )

            try:
                login_user.save_to_db()
            except Exception as err:
                return {'message':'Error # 171 could not save to logged user'}

            return {
                    'message': 'Logged in as {}'.format(current_user.username),
                    'access_token': access_token,
                    'refresh_token': refresh_token,
                    'businessId': current_user.businessId,
                    'employeeCode' : current_user.employeeCode,
                    'userRole': current_user.is_admin,
                    'employee_name':current_user.employee_name
                    },200
        else:
            return {'message': 'Wrong credentials'},400
コード例 #5
0
    def get(self):
        claims = get_jwt_claims()
        if not claims['active']:
            return {
                'message':
                'Error # 171 in Customer Resource, You have not been activated by the admin'
            }, 400

        username = UserModel.find_by_user(get_jwt_identity())

        if not claims['is_superuser']:
            approved_zid_list = VbusinessModel.find_all_business_list()

            if username.businessId not in approved_zid_list:
                return {
                    'message':
                    'Error # 182 in Customer Resource, You have not been authorized to use this business'
                }, 400
        else:
            employee_code_list = HrmstModel.find_all_employee_list()
            return {
                'Number of Customers':
                len([
                    cus.json() for cus in CacusModel.find_customers_by_sp(
                        employee_code_list)
                ])
            }, 200

        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'])

        return {
            'Number of Customers':
            len([
                cus.json()
                for cus in CacusModel.find_customers_by_sp(final_list)
            ])
        }, 200
コード例 #6
0
    def get(self):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'},400

        current_user = UserModel.find_by_user(get_jwt_identity())
        data = [statusL.json() for statusL in UserModel.find_by_status(current_user.businessId,'inactive')]
        return data,200
コード例 #7
0
    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
コード例 #8
0
    def post(self):
        current_user = UserModel.find_by_user(get_jwt_identity())
        logged_user = LoggedModel.find_by_user_businessid(current_user.username, current_user.businessId)
        logged_user.delete_from_db()

        jti = get_raw_jwt()['jti']
        try:
            BLACKLIST.add(jti)
            return {'message':'You have been Successfully Logged Out'},200
        except Exception as e:
            print (e)
            return {'message':'Sorry Something went wrong with our server'},400
コード例 #9
0
    def delete(self, username):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'}, 400

        current_user = UserModel.find_by_user(get_jwt_identity())
        user = UserModel.find_by_user(username)

        if not user:
            return {'message': 'This user does not exist in our system'}, 400

        if current_user.username == HierarchyModel.find_by_hierarchy(
                username).username:
            return {'message': 'You are not allowed to delete yourself'}, 400

        if not current_user.businessId == HierarchyModel.find_by_hierarchy(
                username).business_Id:
            return {'message': 'You are not the admin for this user'}, 400

        parent_list = [
            parent.json()['child_of_code']
            for parent in HierarchyModel.find_all_hierarchy()
        ]

        if not user.employeeCode in parent_list:
            hierarchyDetail = HierarchyModel.find_by_hierarchy(username)
            hierarchyDetail.delete_from_db()
            userDetail = UserModel.find_by_user(username)
            userDetail.status = 'inactive'
            userDetail.save_to_db()
            return {
                'message': 'User has been deleted from your hierarchy'
            }, 200
        else:
            return {
                'message':
                'You cannot delete this user, please replace child first'
            }
コード例 #10
0
ファイル: caitem.py プロジェクト: fixitonline/flash_backup
    def get(self):
        claims = get_jwt_claims()
        if not claims['active']:
            return {
                'message':
                'Error # 34 in Product Resource, You have not been activated by the admin'
            }, 400

        current_user = UserModel.find_by_user(get_jwt_identity())

        if not claims['is_superuser']:
            approved_zid_list = VbusinessModel.find_all_business_list()

            business_Id_list = [current_user.businessId]
            if current_user.businessId not in approved_zid_list:
                return {
                    'message':
                    'Error # 182 in Customer Resource, You have not been authorized to use this business'
                }, 400
        else:
            business_Id_list = VbusinessModel.find_all_business_list()

        category_list = CategoryModel.find_all_category_list()

        all_items = [{
            'product_Code': item.json()['product_Code'],
            'product_Name': item.json()['product_Name'],
            'product_Category': item.json()['product_Category'],
            'Sales_Price': item.json()['Sales_Price'],
            'Unit': item.json()['Unit']
        }
                     for item in CaitemModel.find_by_zid_category(
                         business_Id_list, category_list)]

        all_priceCat = [{
            'productCatCode': cat.json()['productCatCode'],
            'sp_priceQty': cat.json()['sp_priceQty'],
            'discountAmount': cat.json()['discountAmount']
        } for cat in OpspprcModel.find_by_priceCat_all(business_Id_list)]

        for i in all_items:
            i['sp_priceQty'] = 0
            i['discountAmount'] = 0
            for j in all_priceCat:
                if i['product_Code'] == j['productCatCode']:
                    i['sp_priceQty'] = j['sp_priceQty']
                    i['discountAmount'] = j['discountAmount']

        return all_items, 200
コード例 #11
0
    def post(self):
        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'},400

        try:
            data = userFreshSchema.load(json_data).data
        except ValidationError as err:
            return err.messages,400

        current_user = UserModel.find_by_user(get_jwt_identity())
        if UserModel.verify_hash(data['password'],current_user.password):
            access_token = create_access_token(identity = current_user.username, fresh = True)
            return {'access_token':access_token},200
        else:
            return {'message':'The Password you entered is incorrect'},400
コード例 #12
0
    def get(self):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'},400

        current_user = UserModel.find_by_user(get_jwt_identity())
        zid = current_user.businessId
        dataActive = [statusL.json() for statusL in UserModel.find_by_status(zid,'active')]
        dataHierarchy = [hierarchy.json() for hierarchy in HierarchyModel.find_all_hierarchy()]

        for i in dataActive:
            i['child_of_code'] = ''
            i['child_of_name'] = ''
            for j in dataHierarchy:
                if i['employeeCode'] == j['employee_code']:
                    i['child_of_code'] = j['child_of_code']
                    i['child_of_name'] = j['child_of_name']

        return dataActive,200
コード例 #13
0
    def put(self):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'}, 400

        current_user = UserModel.find_by_user(get_jwt_identity())

        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'}, 400

        try:
            data = hierarchyUpdateSchema.load(json_data).data
        except ValidationError as err:
            return err.messages, 400

        print(data)

        if not current_user.businessId == data['business_Id']:
            return {'message': 'You are not the admin for this user'}, 400

        employee_to_change = HierarchyModel.find_by_employee_code(
            data['employee_code'])

        if employee_to_change.child_of_code == data['child_of_code']:
            return {
                'message':
                'You cannot change the parent to the already existing parent'
            }, 400

        employee_to_change.child_of_code = data['child_of_code']
        employee_to_change.child_of_name = data['child_of_name']

        try:
            employee_to_change.save_to_db()
            return {'message': 'Employee hierarchy has been updated'}, 200
        except:
            return {
                'message':
                'Something went wrong while updating information to your server'
            }, 400
コード例 #14
0
ファイル: caitem.py プロジェクト: fixitonline/flash_backup
    def get(self):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'}, 400

        current_user = UserModel.find_by_user(get_jwt_identity())

        if not claims['is_superuser']:
            approved_zid_list = VbusinessModel.find_all_business_list()

            business_Id_list = [current_user.businessId]
            if current_user.businessId not in approved_zid_list:
                return {
                    'message':
                    'Error # 182 in Customer Resource, You have not been authorized to use this business'
                }, 400
        else:
            business_Id_list = VbusinessModel.find_all_business_list()

        category_list = CategoryModel.find_all_category_list()

        all_category = [{
            'businessId': category.json()['businessId'],
            'product_Category': category.json()['product_Category']
        } for category in CaitemModel.find_product_category(business_Id_list)]
        approved_category = [
            category.json() for category in CategoryModel.find_all_category()
        ]

        non_approved_category = [
            i for i in all_category if i not in approved_category
        ]

        return {
            'all_category': all_category,
            'approved_category': approved_category,
            'non_approved_category': non_approved_category
        }, 200
コード例 #15
0
ファイル: caitem.py プロジェクト: fixitonline/flash_backup
    def delete(self, businessId, approvedCategory):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {
                'message':
                'Error # 213 in Product Resource, admin prevelige required'
            }, 400

        approved_zid_list = VbusinessModel.find_all_business_list()

        current_user = UserModel.find_by_user(get_jwt_identity())

        if (current_user.businessId
                not in approved_zid_list) or (businessId
                                              not in approved_zid_list):
            return {
                'message':
                'Error # 180 in Product Resource, You have not been authorized to use this business'
            }, 400

        if not CaitemModel.find_by_zid_category([businessId],
                                                [approvedCategory]):
            return {
                'message':
                'Error # 131 in Product Resources, this category or business ID does not exist in our System'
            }, 400

        categoryDetail = CategoryModel.find_by_zid_category(
            current_user.businessId, approvedCategory)

        if categoryDetail:
            categoryDetail.delete_from_db()

        return {
            'message':
            'Response # 225 in Product Resources, Category has been deleted'
        }, 200
コード例 #16
0
    def put(self):
        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'},400

        try:
            data = updateUserSchema.load(json_data).data
        except ValidationError as err:
            return err.messages,400

        current_user = UserModel.find_by_user(get_jwt_identity())

        if current_user:
            current_user.password=UserModel.generate_hash(data['password'])
            current_user.email=data['email']
            current_user.mobile=data['mobile']

        try:
            current_user.save_to_db()
            return {'message':'Your Information was Successfully Updated'},200
        except Exception as e:
            print (e)
            return {"message":"An error update the customer"},400
コード例 #17
0
    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
コード例 #18
0
ファイル: caitem.py プロジェクト: fixitonline/flash_backup
    def post(self, businessId):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'}, 400

        approved_zid_list = VbusinessModel.find_all_business_list()

        current_user = UserModel.find_by_user(get_jwt_identity())

        if (current_user.businessId
                not in approved_zid_list) or (businessId
                                              not in approved_zid_list):
            return {
                'message':
                'Error # 180 in Product Resource, You have not been authorized to use this business'
            }, 400

        json_data = request.get_json()

        if not json_data:
            return {
                'message':
                'Error # 186 in Product Resource, No input data provided'
            }, 400

        try:
            data = categorySchema.load(json_data).data
        except ValidationError as err:
            return err.messages, 400

        data['approvedCategory'] = html.unescape(data['approvedCategory'])
        if not CaitemModel.find_by_zid_category([businessId],
                                                [data['approvedCategory']]):
            return {
                'message':
                'Error # 131 in Product Resources, this category or business ID does not exist in our System'
            }, 400

        if CategoryModel.find_by_zid_category(current_user.businessId,
                                              data['approvedCategory']):
            return {
                'message':
                'Error # 194 in Product Resources, this category has already been approved'
            }, 400

        categoryDetail = CategoryModel(
            zid=businessId,
            approvedCategory=data['approvedCategory'],
            xtra1=None,
            xtra2=None,
            xtra3=None,
            xtra4=None,
            xtra5=None)

        try:
            categoryDetail.save_to_db()
        except Exception as e:
            print(e)
            return {
                "message":
                "Error # 205 in Product Resource, An error occured while saving the product category"
            }, 400

        return categoryDetail.json(), 200
コード例 #19
0
    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
コード例 #20
0
    def post(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())
        approved_zid_list = VbusinessModel.find_all_business_list()

        if username.businessId not in approved_zid_list:
            return {
                'message':
                'Error # 182 in Customer Resource, You have not been authorized to use this business'
            }, 400

        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'}, 400

        try:
            data = opmobSchemas.load(json_data).data
        except ValidationError as err:
            return err.messages, 400

        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'])

        for d in data:
            cacusSp = CacusModel.find_by_customerId(d['zid'], d['xcus']).json()

            sp_list = [
                cacusSp['cus_salesman'], cacusSp['cus_salesman1'],
                cacusSp['cus_salesman2'], cacusSp['cus_salesman3']
            ]

            if len(set(sp_list).intersection(set(final_list))) == 0:
                return {
                    'message':
                    'You are not allowed to place an order for this customer'
                }, 400

        ztime = datetime.datetime.now()
        xdate = datetime.datetime.now().date()

        xsl = clean(str(OpmobModel.find_last_xsl().xsl))
        if xsl == 'None':
            xsl = 0
        else:
            xsl = int(xsl)

        invoicesl = clean(str(OpmobModel.find_last_invoicesl().invoicesl))
        if invoicesl == 'None':
            invoicesl = 0
        else:
            invoicesl = int(invoicesl)

        mainList = []
        for d in data:
            invoicesl = invoicesl + 1
            xroword = 1
            for i in (d['order']):
                #update all static values
                i['xcus'] = d['xcus']

                try:
                    i['xlat'] = d['xlat']
                except:
                    i['xlat'] = 0

                try:
                    i['xlong'] = d['xlong']
                except:
                    i['xlong'] = 0

                approved_zid_list = VbusinessModel.find_all_business_list()

                if d['zid'] not in approved_zid_list:
                    return {
                        'message':
                        'Error # 182 in Customer Resource, You have not been authorized to use this business'
                    }, 400

                i['zid'] = d['zid']
                i['ztime'] = self.myconverter(ztime)
                i['zutime'] = self.myconverter(ztime)
                i['xdate'] = self.myconverter2(xdate)
                i['username'] = username.username
                i['xterminal'] = username.terminal
                i['xroword'] = xroword
                xroword = xroword + 1
                xsl = xsl + 1
                i['xsl'] = xsl
                i['invoicesl'] = invoicesl
                i['invoiceno'] = str(username.terminal) + str(invoicesl)
                # i['xemp'] = [item['xemp'] for item in busIdempCodeList if item.get('zid','') == i['zid']][0]
                i['xemp'] = username.employeeCode
                i['xcusname'] = CacusModel.query.filter_by(
                    zid=i['zid']).filter_by(xcus=i['xcus']).first().xorg
                i['xcusadd'] = CacusModel.query.filter_by(
                    zid=i['zid']).filter_by(xcus=i['xcus']).first().xadd1

                i['xdesc'] = CaitemModel.query.filter_by(
                    zid=i['zid']).filter_by(xitem=i['xitem']).first().xdesc

                xstdprice = CaitemModel.query.filter_by(
                    zid=i['zid']).filter_by(xitem=i['xitem']).first().xstdprice
                xpricecat = CaitemModel.query.filter_by(
                    zid=i['zid']).filter_by(xitem=i['xitem']).first().xpricecat

                print(xstdprice, 'xstdprice')
                print(xpricecat, 'xpricecat')

                try:
                    xqtycat = OpspprcModel.query.filter_by(
                        zid=i['zid']).filter_by(
                            xpricecat=xpricecat).first().xqty
                except:
                    xqtycat = 0

                try:
                    xdisc = OpspprcModel.query.filter_by(
                        zid=i['zid']).filter_by(
                            xpricecat=xpricecat).first().xdisc
                except:
                    xdisc = 0

                print(xqtycat, 'xqtycat')
                print(xdisc, 'xdisc')

                if i['xqty'] >= xqtycat:
                    i['xprice'] = xstdprice - xdisc
                else:
                    i['xprice'] = xstdprice

                i['xlinetotal'] = i['xprice'] * i['xqty']
                print(i['xprice'], 'xprice')
                print(i['xqty'], 'xqty')
                print(i['xlinetotal'], 'xlinetotal')
                i['xstatusord'] = "New"
                i['xordernum'] = ""
                mainList.append(i)

        #########################################
        orders_json_list = []
        #########################################

        for orders in mainList:
            orderDetail = OpmobModel(zid=orders['zid'],
                                     ztime=orders['ztime'],
                                     zutime=orders['zutime'],
                                     invoiceno=orders['invoiceno'],
                                     invoicesl=orders['invoicesl'],
                                     username=orders['username'],
                                     xemp=orders['xemp'],
                                     xcus=orders['xcus'],
                                     xcusname=orders['xcusname'],
                                     xcusadd=orders['xcusadd'],
                                     xitem=orders['xitem'],
                                     xdesc=orders['xdesc'],
                                     xqty=orders['xqty'],
                                     xprice=orders['xprice'],
                                     xstatusord=orders['xstatusord'],
                                     xordernum=orders['xordernum'],
                                     xroword=orders['xroword'],
                                     xterminal=orders['xterminal'],
                                     xdate=orders['xdate'],
                                     xsl=orders['xsl'],
                                     xlat=orders['xlat'],
                                     xlong=orders['xlong'],
                                     xlinetotal=orders['xlinetotal'],
                                     xtra1=None,
                                     xtra2=None,
                                     xtra3=None,
                                     xtra4=None,
                                     xtra5=None)

            try:
                orderDetail.save_to_db()
                orders_json_list.append(orderDetail.get_json_for_celery_db())
            except Exception as e:
                print(e)
                return {
                    "message": "An error occured inserting the customer"
                }, 400
        ####################################
        add_all_rows_to_client_db_by_celery.delay(orderDetail.__tablename__,
                                                  orders_json_list)
        ####################################
        return mainList, 200
コード例 #21
0
    def post(self):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'admin previlege required'}, 400

        current_user = UserModel.find_by_user(get_jwt_identity())

        approved_zid_list = VbusinessModel.find_all_business_list()

        if (current_user.businessId not in approved_zid_list):
            return {
                'message':
                'Error # 180 in Product Resource, You have not been authorized to use this business'
            }, 400

        json_data = request.get_json()

        if not json_data:
            return {'message': 'No input data provided'}, 400

        try:
            data = hierarchySchema.load(json_data).data
        except ValidationError as err:
            return err.messages, 400

        if not UserModel.find_by_user(data['username']):
            return {'message': 'This user has not registered yet'}, 400

        if not HrmstModel.find_by_EmployeeDetail(data['business_Id'],
                                                 data['employee_code']):
            return {
                'message':
                'The employee code you provided does not exist in our system'
            }, 400

        if not current_user.businessId == data['business_Id']:
            return {'message': 'You are not the admin for this user'}, 400

        if HierarchyModel.find_by_hierarchy(data['username']):
            return {
                'message':
                'This user name has already been activated by the admin'
            }, 400

        new_user = HierarchyModel(username=data['username'],
                                  business_Id=data['business_Id'],
                                  employee_code=data['employee_code'],
                                  employee_name=data['employee_name'],
                                  child_of_code=data['child_of_code'],
                                  child_of_name=data['child_of_name'])

        try:
            new_user.save_to_db()
            activeUser = UserModel.find_by_user(data['username'])
            activeUser.status = 'active'
            activeUser.save_to_db()
            return {
                'message': 'User has been added to hierarchy and activated'
            }, 200
        except:
            return {'message': 'Something went wrong'}, 400
コード例 #22
0
    def post(self):
        json_data = request.get_json()
        print(json_data,'json_data')
        if not json_data:
            return {'message': 'Error # 27 User Resources, No input data provided'},400

        try:
            data = userRegSchema.load(json_data).data
        except ValidationError as err:
            return err.messages,400


        if data['is_admin'] != '':
            if UserModel.verify_secret_key(data['is_admin']) == 'is_superuser':
                pass
            elif UserModel.verify_secret_key(data['is_admin']) == 'is_admin':
                pass
            else:
                return {'message':'Please provide the correct encryption key'},400
        
        print(data,'data')


        if UserModel.find_by_user(data['username']):
            return {'message':'Response # 35 User Resources, User {} already exists'. format(data['username'])},400

        if not UserModel.verify_secret_key(data['is_admin']) == 'is_superuser':

            approved_zid_list = VbusinessModel.find_all_business_list()

            approved_zid_length = len(approved_zid_list)

            if approved_zid_length == 0:
                return {'message':'Error # 44 in User Resources, Super user has not registered any business for you to use'},400

            if (data['businessId'] != 0 and data['employeeCode'] != "" and approved_zid_length > 0):

                if data['businessId'] not in approved_zid_list:
                    return {'message':'Error # 56 User Resources, This business is not authorized in your system please talk to your IT administrator'},400

                if UserModel.find_by_busIdempCode(data['username'],data['businessId'],data['employeeCode']):
                    return {'message': 'Error # 59 User Resources, This Business ID and Employee Code already exists talk to your adminstrator to Provide you with a new businessId'},400

                if not HrmstModel.find_by_EmployeeDetail(data['businessId'],data['employeeCode']):
                    return {'message':'Error # 62 User Resources, Your Employee Code for Business ID provided does not exist in our system or does not match!'},400

            terminalMax = str(db.session.query(func.max(UserModel.terminal)).first())
            terminalMax = re.sub('[(",)]','',terminalMax)
            terminalMax = terminalMax.replace("'","")

            if terminalMax == 'Super':
                terminalId = 'T0001'
            else:
                terminalId = str(terminalMax)
                terminalId = increment(terminalId)

            employee_name = HrmstModel.find_by_EmployeeDetail(data['businessId'],data['employeeCode']).xname
        else:
            data['username'] = '******'
            employee_name = 'Superuser'
            data['businessId'] = 1
            data['employeeCode'] = 'Super'
            terminalId = 'Super'

        new_user = UserModel(
                            username = data['username'],
                            password = UserModel.generate_hash(data['password']),
                            employee_name = employee_name,
                            email = data['email'],
                            mobile = data['mobile'],
                            businessId = data['businessId'],
                            employeeCode = data['employeeCode'],
                            terminal = terminalId,
                            is_admin = UserModel.verify_secret_key(data['is_admin']),
                            status = UserModel.verify_active_user(data['is_admin'])
                            )
        try:
            new_user.save_to_db()
            if UserModel.verify_secret_key(data['is_admin']) == 'is_admin':
                adminHierarchyDetail = HierarchyModel(
                                                    username=data['username'],
                                                    business_Id=data['businessId'],
                                                    employee_code = data['employeeCode'],
                                                    employee_name = employee_name,
                                                    child_of_code = 'Super',
                                                    child_of_name = 'Superuser'
                                                    )
                adminHierarchyDetail.save_to_db()

            access_token = create_access_token(identity = data['username'])
            refresh_token = create_refresh_token(identity = data['username'])
            current_user = UserModel.find_by_user(data['username'])

            return {
                    'message': 'Response # 148 User Resources, User {} was created'.format(data['username']),
                    'access_token':access_token,
                    'refresh_token':refresh_token,
                    'businessId': current_user.businessId,
                    'employeeCode':current_user.employeeCode,
                    'userRole': current_user.is_admin
                    },200
        except Exception as err:
            return {'message':'Error # 155 User Resources, Issues with saving to database'},400