def gen_invoices(): if not 'year' in request.args and 'month' in request.args: abort(403) year = int(request.args['year']) month = int(request.args['month']) invoice_date = date(year, month, 1) projs = active_projects(year, month) count = 0 for project in projs: if not len(Invoice.query.filter( Invoice.project==project).filter( Invoice.date==invoice_date).all()): # If the invoice exists already, don't bother inv = Invoice() inv.project = project inv.date = invoice_date db.session.add(inv) db.session.commit() count += 1 return jsonify(new_invoices=count, status="Success")