Example #1
0
def bill_get(id):
	receipt = None
	if id:
		bill = Bill.query.filter_by(site_id=g.sid, branch_id=g.bid, id=id).first()
		receipt = Receipt.query.filter_by(bill_id=bill.id).first()
	else:
		no = db.session.query(db.func.max(Bill.no)).filter_by(site_id=g.sid, branch_id=g.bid).scalar() or 0
		ref_no = no + 1
		bill_no = strftime('%Y%m') + '-' + str(ref_no).zfill(g.bigit)
		bill = Bill(site_id=g.sid, branch_id=g.bid)
		bill.no = ref_no
		bill.bill_no = bill_no
	receipt_data = {}
	if receipt:
		receiptSchema = ReceiptSchema()
		receipt_data = receiptSchema.dump(receipt).data
	schema = BillSchema()
	return jsonify({
		'bill': schema.dump(bill).data,
		'receipt': receipt_data
	})
Example #2
0
def bill_new():
	no = db.session.query(db.func.max(Bill.no)).filter_by(site_id=g.sid, branch_id=g.bid).scalar() or 0
	ref_no = no + 1
	bill_no = strftime('%Y%m') + '-' + str(ref_no).zfill(g.bigit)
	status = Status.query.filter_by(name='new', module='bill').first()

	bill = Bill(site_id=g.sid, branch_id=g.bid)
	bill.no = ref_no
	bill.bill_no = bill_no
	bill.status_id = status.id
	bill.currency = g.currency
	bill.user_id = g.uid
	bill.tax_rate = g.tax
	bill.discount_rate = g.discount_rate

	bill_count = Bill.query.filter_by(site_id=g.sid, branch_id=g.bid, status_id=status.id).count()
	data, error = BillSchema().dump(bill)
	return jsonify({
		'bill': data,
		'hold_bill_count': bill_count
	})