def test_ht_computing(): # test based on a real world problem that raised the error kmtype = ExpenseKmType(amount=0.38, label="", code="") kmlines = [] for km in [ 3000, 2800, 280, 200, 540, 2800, 3600, 3000, 3000, 4400, 2000, 3000, 4600 ]: kmlines.append(ExpenseKmLine(km=km, description="", type_object=kmtype)) teltype = ExpenseTelType(percentage=50, label="", code="") telline = ExpenseLine(ht=2666, tva=533, description="", type_object=teltype) km_lines_total = sum(l.total for l in kmlines) km_lines_rounded_total = int(sum(l.total_ht for l in kmlines)) km_lines_linerounded_total = sum(int(l.total_ht) for l in kmlines) telline_total = telline.total telline_rounded_total = int(telline.total_tva) + int(telline.total_ht) last_rounded_total = int(km_lines_total + telline_total) byproduct_rounded_total = km_lines_rounded_total + telline_rounded_total byline_rounded_total = km_lines_linerounded_total + telline_rounded_total # Option 1 assert last_rounded_total == byline_rounded_total # Option 2 assert last_rounded_total == byproduct_rounded_total
def add_expense_type(type_, **kwargs): if type_ == 'km': e = ExpenseKmType(**kwargs) elif type_ == 'tel': e = ExpenseTelType(**kwargs) else: e = ExpenseType(**kwargs) session = DBSESSION() session.add(e) session.flush()
def get_tel_column(self): """ Return the columns associated to telephonic expenses """ teltype = ExpenseTelType.query().first() col = None if teltype: # Tel expenses should be visible col = TypedColumn(teltype, label=u"Téléphonie") if teltype.initialize: col.force_visible = True return col
def get_new_expense_sheet(year, month, cid, uid): """ Return a new expense sheet for the given 4-uple """ expense = ExpenseSheet() expense.name = get_expense_sheet_name(month, year) expense.year = year expense.month = month expense.company_id = cid expense.user_id = uid query = ExpenseTelType.query() query = query.filter(ExpenseTelType.active == True) teltypes = query.filter(ExpenseTelType.initialize == True) for type_ in teltypes: line = ExpenseLine(type_id=type_.id, ht=0, tva=0, description=type_.label) expense.lines.append(line) return expense