def closeBulkInvoice(id): session = g.session bi = db.getBulkInvoice(session, id) bi.close() res = jsonify(bulkInvoiceSchema.dump(bi)) session.commit() return res
def getInvoices(id): session = g.session bi = db.getBulkInvoice(session, id) if bi.status == 'draft': return make_response( jsonify(code=HTTPStatus.METHOD_NOT_ALLOWED, message=HTTPStatus.METHOD_NOT_ALLOWED.phrase + ": bulk needs to be issued."), HTTPStatus.METHOD_NOT_ALLOWED) # jsonify the dump of the list of invoices res = jsonify(items=invoicesSchema.dump(db.getInvoiceList(session, id))) return res
def issueBulkInvoice(id): logger.info('id: {id}'.format(id=id)) session = g.session bi = db.getBulkInvoice(session, id) if bi.status != 'draft': return make_response( jsonify(code=HTTPStatus.METHOD_NOT_ALLOWED, message=HTTPStatus.METHOD_NOT_ALLOWED.phrase), HTTPStatus.METHOD_NOT_ALLOWED) bi.issue() res = jsonify(bulkInvoiceSchema.dump(bi)) session.commit() return res
def generateBulkInvoiceZip(id): session = g.session bi = db.getBulkInvoice(session, id) data = io.BytesIO() with zipfile.ZipFile(data, mode='w') as z: for name, string in bi.generate(): name = name + ".pdf" z.writestr(name, string) data.seek(0) return send_file(data, mimetype='application/zip', as_attachment=True, attachment_filename='data.zip')
def updateBulkInvoice(id): session = g.session # Get BulkInvoice bi = db.getBulkInvoice(session, id) if bi.status != 'draft': return make_response( jsonify( code=HTTPStatus.METHOD_NOT_ALLOWED, message= "A bulks can no longer be updated once it has been issued."), HTTPStatus.METHOD_NOT_ALLOWED) # Get json paramters, default to old if not supplied title = request.json.get('title', bi.title) mailing_list = request.json.get('mailing_list', bi.mailing_list) text_mail = request.json.get('text_mail', bi.text_mail) text_invoice = request.json.get('text_invoice', bi.text_invoice) text_reminder = request.json.get('text_reminder', bi.text_reminder) if bi.status == 'issued': if bi.mailing_list != mailing_list: return make_response( jsonify( code=HTTPStatus.BAD_REQUEST, message= "The mailing list of an issued bulk can not be changed."), HTTPStatus.BAD_REQUEST) # Update the attributes bi.title = title bi.mailing_list = mailing_list bi.text_mail = text_mail bi.text_invoice = text_invoice bi.text_reminder = text_reminder # Dump the data, commit and close the session res = jsonify(bulkInvoiceSchema.dump(bi)) session.commit() return res
def sendBulkInvoice(id): session = g.session force = bool(request.args.get('force', 0, type=int)) include_invoice = bool(request.args.get('include_invoice', 0, type=int)) mail_body = request.json['mail_body'] bi = db.getBulkInvoice(session, id) sent_count = 0 for success, result in bi.complete_messages( mail_body, generator=True, force=force, include_invoice=include_invoice): if success: mail.send(result) sent_count += 1 res = jsonify(sent_count=sent_count) session.commit() return res
def generateBulkInvoicePDF(id): session = g.session check_only = bool(request.args.get('check_only', 0, type=int)) bi = db.getBulkInvoice(session, id) data = io.BytesIO() merger = PdfFileMerger() for _, string in bi.generate(check_only=check_only): if not check_only: merger.append(PdfFileReader(io.BytesIO(string))) if check_only: return make_response( jsonify(code=HTTPStatus.OK, message=HTTPStatus.OK.phrase), HTTPStatus.OK) merger.write(data) data.seek(0) return send_file(data, mimetype='application/pdf', as_attachment=False, attachment_filename='data.pdf')
def getBulkInvoice(id): session = g.session # jsonify the dump of the bulk invoice res = jsonify(bulkInvoiceSchema.dump(db.getBulkInvoice(session, id))) return res