def cal_tax() -> 'html': income = int(request.form['income']) insurance = int(request.form['insurance']) exemption = int(request.form['exemption']) before = income - insurance - exemption free = 5000 # 免征额 rule = [(80000, 0.45, 15160), (55000, 0.35, 7160), (35000, 0.3, 4410), (25000, 0.25, 2660), (12000, 0.2, 1410), (3000, 0.1, 210), (0, 0.03, 0)] title = '个税计算结果' mytax = tax.calc_tax(before, free, rule) aftertax_income = income - insurance - mytax return render_template('results.html', the_title=title, the_income=str(income), the_insurance=str(insurance), the_exemption=str(exemption), the_tax=str(mytax), the_aftertax_income=str(aftertax_income))
def test_calc_tax_no_input(larry): larry.assertEqual(calc_tax(), 0)
def test_calc_tax_twenty_percent_and_sixty_six_age(self): self.assertAlmostEqual(calc_tax(60000, 0.2, 66), 8000)
def cal_tax() -> 'html': try: # income = int(request.form['income']) income = int(request.args.get('income', 0)) insurance = int(request.args.get('insurance', 0)) exemption = int(request.args.get('exemption', 0)) # insurance = int(request.form['insurance']) # exemption = int(request.form['exemption']) before = income - insurance - exemption free = 5000 rule = [(80000, 0.45, 15160), (55000, 0.35, 7160), (35000, 0.3, 4410), (25000, 0.25, 2660), (12000, 0.2, 1410), (3000, 0.1, 210), (0, 0.03, 0)] title = '个税计算结果' mytax = tax.calc_tax(before, free, rule) aftertax_income = income - insurance - mytax return render_template('results.html', the_title=title, the_income=str(income), the_insurance=str(insurance), the_exemption=str(exemption), the_tax=str(mytax), the_aftertax_income=str(aftertax_income)) except ValueError: print('------------error-------------\n\n') def safe_jinja(s): # 替换括号 s = s.replace('()', '') s = s.replace('[]', '') blacklist = [ 'import', 'os', 'sys', 'commands', 'subprocess', 'open', 'eval' ] for bl in blacklist: s = s.replace(bl, "") return s title = "输入参数的值有错" # income = request.form['income'] # income = request.form['income'] # insurance = request.form['insurance'] # exemption = request.form['exemption'] income = request.args.get('income', 0) insurance = request.args.get('insurance', 0) exemption = request.args.get('exemption', 0) print(safe_jinja(exemption)) template = ''' <!doctype html> <html> <head> <title>%s</title> <link rel="stylesheet" href="static/hf.css" /> </head> <body> </body> </html> <h2>%s</h2> <table> <p>请检查输入的信息:</p> <tr><td>税前月收入:</td><td>%s</td></tr> <tr><td>四险一金:</td><td>%s</td></tr> <tr><td>专项附加扣除:</td><td>%s</td></tr> </table> ''' % (title, title, safe_jinja(income), safe_jinja(insurance), safe_jinja(exemption)) t = Template(template) return t.render()
def test_calc_tax_twenty_percent_and_sixty_five_age(self): self.assertAlmostEqual(calc_tax(60000, 0.2, 65), 12000)
def test_calc_tax_twenty_percent_and_nineteen_age(self): self.assertAlmostEqual(calc_tax(60000, 0.2, 19), 12000)
def test_calc_tax_twenty_percent_and_eighteen_age(self): self.assertAlmostEqual(calc_tax(60000, 0.2, 18), 5000)
def test_calc_tax_with_fourteen_percent_with_almost_equal(self): self.assertAlmostEqual(14, calc_tax(100, 0.14))
def test_calc_tax_with_ten_percent(self): self.assertAlmostEqual(10, calc_tax(100, 0.1))