def handle_factuur_create(params, json_data): log.debug('Start factuur_create') log.debug('Input data:%s', json_data) if not hasPermission(params, 'factuur_create', None): return {'error': 'insufficient permissions'} facturen = [] #Start transaction try: facturen.append(parse_factuur(json_data)) except MalformedDataException: return {'error': 'incorrectly structured data'} try: for factuur in facturen: start_transaction() verify_factuur(factuur) fac_id = process_factuur(factuur) policy.process_factuur(factuur, fac_id) commit() except NonExistingProductException, e: rollback() return { 'error': 'No such product {0}: {1}'.format(e.product_id, e.product_name), 'product_id': e.product_id, 'product_name': e.product_name }
def handle_factuur_create(params, json_data): log.debug('Start factuur_create') log.debug('Input data:%s', json_data) if not hasPermission(params,'factuur_create',None): return {'error': 'insufficient permissions'} facturen = [] #Start transaction try: facturen.append(parse_factuur(json_data)) except MalformedDataException: return {'error': 'incorrectly structured data'} try: for factuur in facturen: start_transaction() verify_factuur(factuur) fac_id = process_factuur(factuur) policy.process_factuur(factuur, fac_id) commit() except NonExistingProductException, e: rollback() return {'error': 'No such product {0}: {1}'.format(e.product_id, e.product_name), 'product_id': e.product_id, 'product_name': e.product_name}
def handle_budget(params, json_data): if 'budget_id' not in params: return [] budget_data = [] try: q = Query( 'SELECT bdgt_id, bdgt_naam, bdgt_minimum, bdgt_current, bdgt_ver_id FROM tblbudget WHERE bdgt_id = %s' ) except DatabaseError: raise InternalServerError for budget_id in params['budget_id']: try: q.run((budget_id, )) cur_result = q.rows() except DatabaseError: raise InternalServerError for row in cur_result: if not hasPermission(params, 'budget', row[4]): continue budget_data.append({ 'id': row[0], 'vereniging_id': row[4], 'naam': row[1], 'current': row[3], 'minimum': row[2] }) return budget_data
def handle_budget(params, json_data): if 'budget_id' not in params: return [] budget_data = [] try: q = Query('SELECT bdgt_id, bdgt_naam, bdgt_minimum, bdgt_current, bdgt_ver_id FROM tblbudget WHERE bdgt_id = %s') except DatabaseError: raise InternalServerError for budget_id in params['budget_id']: try: q.run((budget_id,)) cur_result = q.rows() except DatabaseError: raise InternalServerError for row in cur_result: if not hasPermission(params, 'budget', row[4]): continue budget_data.append({ 'id': row[0], 'vereniging_id': row[4], 'naam': row[1], 'current': row[3], 'minimum': row[2]}) return budget_data
def convert_factuur_rows(params, regels): if len(regels) == 0: return [] result = [] for i in range(0, len(regels)): if not hasPermission(params, 'factuur', regels[i][4]): continue if len(result) == 0 or result[-1]['id'] != regels[i][0]: huidige_factuur = { 'id': regels[i][0], 'type': policy.factuur_name_mapping[regels[i][2]], 'volgnummer': regels[i][5], 'factuurdatum': str(regels[i][6]), 'leverdatum': str(regels[i][7]), 'regels': [] } if regels[i][10] is not None: huidige_factuur['saldo_basis'] = regels[i][10] huidige_factuur['saldo_basis_na'] = regels[i][12] if regels[i][3] is not None: huidige_factuur['vereniging_id'] = regels[i][3] if regels[i][4] is not None: huidige_factuur['leverancier'] = regels[i][4] if regels[i][8] is not None: huidige_factuur['verantwoordelijke'] = regels[i][8] if regels[i][9] is not None: huidige_factuur['saldo_speciaal'] = regels[i][9] huidige_factuur['saldo_speciaal_na'] = regels[i][11] result.append(huidige_factuur) if regels[i][13] is None: continue huidige_regel = { 'aantal': regels[i][16], 'stukprijs': regels[i][17], 'totaalprijs': regels[i][18], 'btw': regels[i][19] } if regels[i][14] is not None: huidige_regel['naam'] = regels[i][14] if regels[i][15] is not None: huidige_regel['naam'] = regels[i][15] if regels[i][20] is not None: huidige_regel['prd_id'] = regels[i][20] result[-1]['regels'].append(huidige_regel) return result
def handle_voorraad(params, json_data): if 'product_id' not in params: return [] if not hasPermission(params, 'voorraad', None): return [] result = [] for prd_id in params['product_id']: voorraad = query_voorraad(prd_id) voorraad = map(_convert_datum, voorraad) result.append({'id': prd_id, 'voorraad': voorraad}) return result
def _convert_vereniging_rows(rows): ver_overview = [] for row in rows: if not hasPermission(params, 'vereniging', row[0]): continue ver_overview.append({ 'id': row[0], 'naam': row[1], 'email': row[2], 'basis_budget': row[3] }) return ver_overview
def handle_voorraad(params, json_data): if 'product_id' not in params: return [] if not hasPermission(params, 'voorraad', None): return [] result = [] for prd_id in params['product_id']: voorraad = query_voorraad(prd_id) voorraad = map(_convert_datum, voorraad) result.append({ 'id': prd_id, 'voorraad': voorraad }) return result
def handle_verenigingen(params, json_data): try: q = Query("""SELECT ver_id, ver_naam, ver_email, ver_basis_budget_id FROM tblvereniging""") q.run(); rows = q.rows() except DatabaseError: raise InternalServerError ver_overview = [] for row in rows: if not hasPermission(params, 'vereniging', row[0]): continue ver_overview.append({ 'id': row[0], 'naam': row[1], 'email': row[2], 'basis_budget': row[3] }) return ver_overview
def handle_verenigingen(params, json_data): try: q = Query("""SELECT ver_id, ver_naam, ver_email, ver_basis_budget_id FROM tblvereniging""") q.run() rows = q.rows() except DatabaseError: raise InternalServerError ver_overview = [] for row in rows: if not hasPermission(params, 'vereniging', row[0]): continue ver_overview.append({ 'id': row[0], 'naam': row[1], 'email': row[2], 'basis_budget': row[3] }) return ver_overview
def handle_factuur_edit(params, json_data): log.debug('Start factuur_edit') log.debug('Input data:%s', json_data) if not hasPermission(params,'factuur_create',None): return {'error': 'insufficient permissions'} factuur_id = params['factuur_id'] try: regels = parse_factuur_regels(json_data['regels']) factuur = handle_factuur(params, {}) except MalformedDataException: return {'error': 'Incorrect input formatting'} try: start_transaction() vrd_aantallen = {} for regel in regels: verify_factuur_regel(regel, vrd_aantallen) edit_factuur(factuur_id, factuur, regels) commit() except NonExistingProductException, e: rollback() return {'error': 'No such product {0}: {1}'.format(e.product_id, e.product_name), 'product_id': e.product_id, 'product_name': e.product_name}