def finalizeQuote(): if request.method == 'POST': """ Given a project ID and a boolean finalize. Turn finalize to false if finalize is False. Generate and save the quote and material expenses if finalize is True Customer quote is calculated for each fence by the following formula. quote = length * (style + height + base price + (border colour + panel colour) / 2) """ project_id = request.values.get('proj_id') # A dictionary with keywords and values of material_ids material_types = json.loads(request.values.get('material_types')) # A dictionary with keywords and values of the amount of material needed material_amounts = json.loads(request.values.get('material_amounts')) misc_modifier_label = request.values.get('misc_modifier_label') # A flat rate which allows the user to alter the subtotal of the quote misc_modifier = request.values.get('misc_modifier') if misc_modifier == "": misc_modifier = 0 else: misc_modifier = int(misc_modifier) payment = request.values.get('payment') notes = request.values.get('notes') description = request.values.get('description') project = dbSession.query(Project).filter( Project.project_id == project_id).one() if project is None: print('Project does not exist') return bad_request('Project does not exist') if material_types is None or material_amounts is None: print('Material Parameters not given') return bad_request('Material Parameters not given') if project.finalize: print('Project has already been finalized') return bad_request('Project has already been finalized') project.finalize = True try: newQuote = generateQuote(project, material_types, material_amounts, misc_modifier, payment, notes, misc_modifier_label, description) dbSession.add(newQuote) dbSession.commit() except BaseException as e: raise e print('Error in saving the quote') return bad_request('Error in saving the quote') return created_request('Quote has been generated') print('Request is not a POST request') return bad_request('Request is not a POST request')
def projectTestData(): newProject1 = Project(customer_id = 1, status_name = 'Not Reached', address = 'Bear St', end_date = None , note = 'A fun fencing project', project_name = "Kat's house fence", company_name = 'Fence', layout_selected = None, appearance_selected = None, project_id = 1 ) newProject2 = Project(customer_id = 1, status_name = 'Not Reached', address = 'Grand Ave', end_date = None, note = 'Dog lives here', project_name = "Kat's second house fence", company_name = 'Fence',layout_selected = None, appearance_selected = None, project_id = 2 ) #newProject3 = Project(customer_id = 3, status_name = 'Complete', address = 'Park St', end_date = None, note = 'Concrete fence', project_name = "Jason's fence for company building", company_name = 'Fence', project_id = 3, layout_selected = 3, appearance_selected = 1) dbSession.add(newProject1) dbSession.add(newProject2) #dbSession.add(newProject3) dbSession.commit()
def addCustomer(name, email, ph, addr, cname): """Add a customer to the database with the given field values""" customer = Customer(email=email, first_name=name, cellphone=ph, company_name=cname) dbSession.add(customer) dbSession.commit() return True
def user_registered_sighandler(app, user, confirm_token): """Deactivates new users""" changeUser = dbSession.query(User).filter(User.id == user.id).one() newCompany = Company(company_name=user.username, email=user.email) dbSession.add(newCompany) dbSession.commit() changeUser.company_name = user.username userDatastore.deactivate_user(user) userDatastore.add_role_to_user(user, 'primary') dbSession.commit()
def uploadPrice(): """ Parses the given csv file into fencing materials prices for a given company """ company_name = current_user.company_name if request.method == 'POST': priceFile = request.files['prices'] if not priceFile: return bad_request('Invalid price file uploaded') stream = io.StringIO(priceFile.stream.read().decode("UTF8"), newline=None) csv_input = csv.reader(stream) # Clear materials list? This will cause issues for appearances due to ForeignKeys dbSession.query(Material).filter( Material.company_name == current_user.company_name).delete() category = '' for row in csv_input: if row[2] == 'My Price' and row[4] == 'Pieces in Bundle': # Category category = row[0] if row[0] != '' and row[2] == '' and row[4] == '': # Category category = row[0] if row[1].startswith('$') and row[2].startswith('$'): # Material try: my_price = Decimal(row[2][1:]) except: print( 'My Price value could not be converted into a Decimal, default to 0' ) my_price = 0 try: pieces_in_bundle = Decimal(row[4]) except: print( 'Pieces in bundle value could not be converted into a number, default to 1' ) pieces_in_bundle = 1 material_name = row[0] note = row[5] # Insert data into db newMaterial = Material(material_name=material_name, my_price=my_price, pieces_in_bundle=pieces_in_bundle, category=category, note=note, company_name=current_user.company_name) dbSession.add(newMaterial) # Otherwise, ignore row dbSession.commit() return created_request('Prices were changed') return bad_request('Request is not a POST request')
def createLayout(project_id): """Creates the default draw io layout with green edit diagram button image""" newLayout = Layout( project_id=project_id, layout_name="Layout 1", layout_info= "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iNzAxcHgiIGhlaWdodD0iMzIxcHgiIH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T0iSGVsdmV0aWNhIj4mbHQ7Zm9udCBjb2xvcj0iI2ZmZmZmZiIgc3R5bGU9ImZvbnQtc2l6ZTogMTAwcHgiJmd0O0VkaXQgRGlhZ3JhbSZsdDsvZm9udCZndDs8L3RleHQ+PC9zd2l0Y2g+PC9nPjwvZz48L3N2Zz4=" ) dbSession.add(newLayout) dbSession.commit() return newLayout
def createAppearance(project_id): """Helper function for saveApperance""" newAppearance = Appearance(project_id=project_id, appearance_name="Appearance 1", style=None, height=None, border_colour=None, panel_colour=None, base_price=0) dbSession.add(newAppearance) dbSession.commit() return newAppearance
def testAppearanceData(): appearance = Appearance(appearance_name = 'Appearance', project_id = 1, panel_gap = 0.5, height = 0.5, appearance_id = 1 ) appearance1 = Appearance(appearance_name='Appearance1', project_id=1, panel_gap=0.6, height=6, appearance_id=2) appearance2 = Appearance(appearance_name='Appearance2', project_id=1, panel_gap=0.7, height=9, appearance_id=3) appearance3 = Appearance(appearance_name = 'Appearance3', project_id = 2, panel_gap = 0.8, height = 12, appearance_id = 4 ) appearance4 = Appearance(appearance_name = 'Appearance4', project_id = 2, panel_gap = 0.9, height = 13, appearance_id = 5 ) dbSession.add(appearance) dbSession.add(appearance1) dbSession.add(appearance2) dbSession.add(appearance3) dbSession.add(appearance4) dbSession.commit()
def userTestData(): newUser = User(id = 1, email = "*****@*****.**", username = "******", password = "******", company_name = "Fence", active = True) newUser1 = User(id = 2, email = "*****@*****.**", username = "******", password = "******", company_name = "Builder", active = True) newUser2 = User(id = 3, email = "*****@*****.**", username = "******", password = "******", company_name = "Fence", active = False) newUser3 = User(id = 4, email = "*****@*****.**", username = "******", password = "******", company_name = "Builder", active = False) dbSession.add(newUser) dbSession.add(newUser1) dbSession.add(newUser2) dbSession.add(newUser3) dbSession.commit()
def createProject(customerId, statusName, address, companyName, project_name): """Access mysql and add in project""" newProject = Project(customer_id=customerId, address=address, status_name=statusName, end_date=None, note='', project_name=project_name, company_name=companyName, finalize=False, layout_selected=None, appearance_selected=None) dbSession.add(newProject) dbSession.commit() newAppearance = Appearances.createAppearance(newProject.project_id) newProject.appearance_selected = newAppearance.appearance_id newLayout = Layouts.createLayout(newProject.project_id) newProject.layout_selected = newLayout.layout_id dbSession.commit() return newProject.project_id
def testLayoutData(): newLayout1 = Layout(layout_id = 1, project_id = 1, layout_name = "Layout 1", layout_info = "test") newLayout2 = Layout(layout_id = 2, project_id = 2, layout_name = "Layout 2", layout_info = "test") newLayout3 = Layout(layout_id = 3, project_id = 1, layout_name = "Layout 3", layout_info = "test") dbSession.add(newLayout1) dbSession.add(newLayout2) dbSession.add(newLayout3) dbSession.commit()
def pictureTestData(): newPic = Picture(picture_id = 1, file_name = "garden.jpg", thumbnail_name = "thumbnail_garden.png", project_id = 1) newPic1 = Picture(picture_id = 2, file_name = "corner.jpg", thumbnail_name = "thumbnail_corner.png", project_id = 1) newPic2 = Picture(picture_id = 3, file_name = "backyard.png", thumbnail_name = "thumbnail_backyard.png", project_id = 2) dbSession.add(newPic) dbSession.add(newPic1) dbSession.add(newPic2) dbSession.commit()
def customerTestData(): newCustomer1 = Customer(customer_id = 1, first_name = 'Kat', email = '*****@*****.**', cellphone = '541-689-4681', company_name = 'Fence') newCustomer2 = Customer(customer_id = 2, first_name = 'Davis', email = '*****@*****.**', cellphone = '761-158-2113', company_name = 'Builder') newCustomer3 = Customer(customer_id = 3, first_name = 'Jason', email = '*****@*****.**', cellphone = '688-946-8781', company_name = 'Fence') dbSession.add(newCustomer1) dbSession.add(newCustomer2) dbSession.add(newCustomer3) dbSession.commit()
def statusTestData(): status1 = Status(status_name = "Not Reached", status_number = 1) status2 = Status(status_name = "Paid", status_number = 2) status3 = Status(status_name = "Appraisal Booked", status_number = 3) dbSession.add(status1) dbSession.add(status2) dbSession.add(status3) dbSession.commit()
def quoteTestData(): newQuote = Quote(quote_id=2, project_id=1, amount=99439.12, amount_gst=100.00, amount_total=99539.12, material_expense=123, material_expense_gst=52, material_expense_total=172, gst_rate=0.5) newQuote1 = Quote(quote_id=1, project_id=1, amount=105.12, amount_gst=10.00, amount_total=115.12, material_expense=52.52, material_expense_gst=5.08, material_expense_total=57.60, gst_rate=0.5) newQuote2 = Quote(quote_id=3, project_id=2, amount=73.00, amount_gst=7.00, amount_total=80, material_expense=52.52, material_expense_gst=5.08, material_expense_total=57.60, gst_rate=0.5) newQuote3 = Quote(quote_id=4, project_id=1, amount=105.12, amount_gst=10.00, amount_total=116.12, material_expense=52.52, material_expense_gst=5.08, material_expense_total=57.60, gst_rate=0.5) dbSession.add(newQuote) dbSession.add(newQuote1) dbSession.add(newQuote2) dbSession.commit()
def testMaterialData(): newMaterial1 = Material(material_name = 'WPR6C* Pocket Rail 1.5"x 71.5" Clay' , my_price = 18.37, pieces_in_bundle = 144, category = "Privacy Fence Rails", note = "Clay", company_name = "Fence", material_id = 1) newMaterial2 = Material(material_name = "875U.16A .875x16' U Channel Almond" , my_price = 13.16, pieces_in_bundle = 36, category = "U-Channel (Plastic)", note = "Almond", company_name = "Fence", material_id = 2) newMaterial3 = Material(material_name = 'APSB4 4 x 1-7/8" Post Collar Adapter" 2pc', my_price = 4.75, pieces_in_bundle = 150, category = "Collars", note = "Adapter", company_name = "Fence", material_id = 3) newMaterial4 = Material(material_name = 'HSSDR36 36 Stainless Steel Drop Rod Black', my_price = 37.98, pieces_in_bundle = 6, category = "Gate Hardware", note = "Stainless Steel", company_name = "Fence", material_id = 4) newMaterial5 = Material(material_name = 'GAAKA Gate Assembly Kit -Almond ', my_price = 7.00, pieces_in_bundle = 1, category = "Gates", note = "issa gate", company_name = "Fence", material_id = 5) newMaterial6 = Material(material_name = 'ABLOCK THE BLOCK" Vinyl post pounding block"', my_price = 52.50, pieces_in_bundle = 1, category = "Accessories", note = "Its a pounding block", company_name = "Fence", material_id = 6) newMaterial7 = Material(material_name = 'Cap235FA 2x3.5" Flat Cap Almond', my_price = 1.13, pieces_in_bundle = 100, category = "Caps", note = "cappa", company_name = "Fence", material_id = 7) newMaterial8 = Material(material_name = 'W55.A* 5x5"x54" Post Almond', my_price = 19.36, pieces_in_bundle = 72, category = "Ranch Rail", note = "ranch sauce", company_name = "Fence", material_id = 8) dbSession.add(newMaterial1) dbSession.add(newMaterial2) dbSession.add(newMaterial3) dbSession.add(newMaterial4) dbSession.add(newMaterial5) dbSession.add(newMaterial6) dbSession.add(newMaterial7) dbSession.add(newMaterial8) dbSession.commit()
def companyTestData(): newCompany1 = Company(company_name = "Fence", email = "*****@*****.**") newCompany2 = Company(company_name = "Builder", email = "*****@*****.**") dbSession.add(newCompany1) dbSession.add(newCompany2) dbSession.commit()
def uploadPicture(): """ Saves the image and adds the picture name to a related project """ if request.method == 'POST': project_id = request.form['proj_id'] picture = request.files['picture'] # Parse file type and file name filename = secure_filename(picture.filename) filename, file_extension = os.path.splitext(filename) if filename != '': # Generate a unique file name to store the file filename = str(uuid.uuid4()) try: # Store filepath into the database newPicture = Picture(project_id=project_id, file_name=filename + file_extension, thumbnail_name=thumbnailPrefix + filename + thumbnailExt) dbSession.add(newPicture) # Save picture in the picture directory picturePath = os.path.join(app_root, pictureDir, filename + file_extension) picture.save(picturePath) # Create thumbnail of picture thumb = Image.open(picturePath) # Source: javiergodinez.blogspot.ca/2008/03/square-thumbnail-with-python-image.html width, height = thumb.size if width > height: delta = width - height left = int(delta / 2) upper = 0 right = height + left lower = height else: delta = height - width left = 0 upper = int(delta / 2) right = width lower = width + upper thumb = thumb.crop((left, upper, right, lower)) thumb.thumbnail(thumbnailSize, Image.ANTIALIAS) # Save thumbnail in the thumbnail directory thumbnailPath = os.path.join( app_root, thumbnailDir, thumbnailPrefix + filename + thumbnailExt) thumb.save(thumbnailPath) thumb.close() # Commit and return ok status dbSession.commit() return created_request("Picture was uploaded") except: return bad_request( "Invalid project id or an error when saving the file has occured" ) return bad_request("No file provided")
def setup_db(): """Create a user to test with only run once""" init_db() userDatastore.find_or_create_role(name='admin') userDatastore.find_or_create_role(name='primary') if not fieldExists(dbSession, Company.company_name, "Admin"): newCompany = Company(company_name="Admin", email="*****@*****.**") dbSession.add(newCompany) dbSession.commit() if not fieldExists(dbSession, User.id, 1): #primary newUser = User(id=1, email='*****@*****.**', username='******', password='******', company_name='Admin', active=1) dbSession.add(newUser) userDatastore.add_role_to_user(newUser, 'admin') userDatastore.activate_user(newUser) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Not Reached"): newStatus = Status(status_name="Not Reached", status_number=1) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Paid"): newStatus = Status(status_name="Paid", status_number=2) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Appraisal Booked"): newStatus = Status(status_name="Appraisal Booked", status_number=3) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Waiting for Appraisal"): newStatus = Status(status_name="Waiting for Appraisal", status_number=4) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Appraised"): newStatus = Status(status_name="Appraised", status_number=5) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Quote Sent"): newStatus = Status(status_name="Quote Sent", status_number=6) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Waiting for Alberta1Call"): newStatus = Status(status_name="Waiting for Alberta1Call", status_number=7) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Installation Pending"): newStatus = Status(status_name="Installation Pending", status_number=8) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "Installing"): newStatus = Status(status_name="Installing", status_number=9) dbSession.add(newStatus) dbSession.commit() if not fieldExists(dbSession, Status.status_name, "No Longer Interested"): newStatus = Status(status_name="No Longer Interested", status_number=10) dbSession.add(newStatus) dbSession.commit() Pictures.app_root = app.root_path Quotes.app_root = app.root_path Email.staticFolder = app.root_path + "/static/"
def testEstimateData(): # STYLE, COLOUR, HEIGHT, GATE newStyle = Style(style = "Full Privacy", value = 40, company_name = None, style_id = 1 ) newColor = Colour(colour = "White", value = 0, company_name = None, colour_id = 1) newHeight = Height(height = "6", value = 0, company_name = None, height_id = 1) newGate = Gate(gate = "Man gate 4'", value = 550, company_name = None, gate_id = 1) newStyle1 = Style(style = "Picket Top", value = 44, company_name = None, style_id = 2 ) newColor1 = Colour(colour = "Almond (Tan)", value = 4, company_name = None, colour_id = 2) newHeight1 = Height(height = "5", value = -3, company_name = None, height_id = 2) newGate1 = Gate(gate = "RV gate 12'", value = 1300, company_name = None, gate_id = 2) newStyle2 = Style(style = "Lattice Top", value = 44, company_name = None, style_id = 3 ) newColor2 = Colour(colour = "Clay", value = 8, company_name = None, colour_id = 3) newHeight2 = Height(height = "4", value = -3, company_name = None, height_id = 3) newStyle3 = Style(style = "Picket Fence", value = 40, company_name = None, style_id = 4 ) newColor3 = Colour(colour = "Pebblestone", value = 4, company_name = None, colour_id = 4) newHeight3 = Height(height = "3", value = -6, company_name = None, height_id = 4) dbSession.add(newStyle) dbSession.add(newColor) dbSession.add(newHeight) dbSession.add(newGate) dbSession.add(newStyle1) dbSession.add(newColor1) dbSession.add(newHeight1) dbSession.add(newGate1) dbSession.add(newStyle2) dbSession.add(newColor2) dbSession.add(newHeight2) dbSession.add(newStyle3) dbSession.add(newColor3) dbSession.add(newHeight3) dbSession.commit()