I have a customer that is using a excel price calculator embed on the website. The solution was simple and it worked but a bit backwards. So I dusted some dust of my python programing skills form school, the program was really simple when I type it in pycharm IDE, but when I was going to put it online the problem popped up since my skills are just beginner. So after hours with google i found Anvil.
It was easy to set the GUI, but implementing the code i have for pycharm was a bit more complicated. What i did was using the guessing game example in Anvil and from there i got my price calculator.
If the school is buying access for students this is how it works:
There are one min. price for students 20 or below that is 400. Between 21 and 50 it cost 20 for each extra student. From 51 to 100 the price is 8 and from from 101 to 300 the price is 3 for pr student. There are a max price that is set to 2000 without tax. So all over 300 is just 2000.
The result is here [https://4cft4edybqrcn7df.anvilapp.net/] Below is the code form the form:
from anvil import *
import anvil.server
class Form1(Form1Template):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
# Any code you write here will run when the form opens.
def button_1_click (self, **event_args):
# This method is called when the button is clicked
pris = int(self.pris.text)
response = str(anvil.server.call('price', pris))
mrespons = str(anvil.server.call('pris', pris))
self.outputt.text = "Pris uten MVA: " % pris
self.outputt.text += str(response)+",-"
self.mva.text = "Pris med MVA: " % pris
self.mva.text += str(mrespons)+",-"
And than I made two server modules to show the price with and without tax.
Code from with tax.
import anvil.server
@anvil.server.callable
def pris(pris):
if pris <=20:
print("pris = 400,- ")
print("with tax: ", 400 * 1.25)
return 400*1.25
elif pris >=21 and pris <=50:
print("pris = ", pris *20)
print("with tax: ", (pris * 20) * 1.25)
return (pris * 20) * 1.25
elif pris >=51 and pris <=100:
print("pris = ", pris *8+600)
print("mva: ",(pris *8+600)*1.25)
return (pris *8+600)*1.25
elif pris >=101 and pris <300:
print("pris = ", pris *3+1100)
print("mva: ", (pris * 3 + 1100) * 1.25)
return (pris * 3 + 1100) * 1.25
else:
print (“Din pris er 2000,-”)
return 2000 * 1.25
And code without tax:
@anvil.server.callable
def price(pris):
if pris <=20:
print("pris = 400,- ")
print("with tax: ", 400 * 1.25)
return 400
elif pris >=21 and pris <=50:
print("pris = ", pris *20)
print("with tax: ", (pris * 20) * 1.25)
return pris *20
elif pris >=51 and pris <=100:
print("pris = ", pris *8+600)
print("mva: ",(pris *8+600)*1.25)
return pris *8+600
elif pris >=101 and pris <300:
print("pris = ", pris *3+1100)
print("mva: ", (pris * 3 + 1100) * 1.25)
return pris *3+1100
else:
print ("Din pris er 2000,-")
return 2000
The code don’t need the print statement but I have it there for reference.