def generate(self): orderId = self.IntReq('Id') try: order = Order.get(Order.id == orderId) except: order = Order.get() self.headers.append(('Id', str(order.id))) self.headers.append(('SupplierId', str(order.supplier.id))) self.headers.append(('SupplierName', order.supplier.name)) self.headers.append(('Date', order.date)) self.headers.append(('Time', order.time)) self.headers.append(('DateTime', getDate() + ' ' + getTime())) self.headers.append(('Storage', order.storage.name)) self.headers.append(('UserName', order.user.fullname())) self.Echo('<Page>') for row in order.details: self.Echo('<Row>') self.EchoTag('ProductId', row.id) self.EchoTag('ProductName', row.name) self.EchoTag('Category', row.group.name) self.EchoTag('Quantity', row.quantity) self.EchoTag('UnitPrice', row.purchase) self.EchoTag('FullPrice', row.full_purchase()) self.Echo('</Row>') self.Echo('</Page>')
def Process(self, section): if section == 'instulments': today = datetime.today() enddate = today + timedelta(days=7) insts = SaleInstallment.select() \ .where((SaleInstallment.dateback.is_null(True)) & (SaleInstallment.date < enddate)) i = 1 for inst in insts: inst.index = i i += 1 self.RenderFile('dashboard/instulments.htm', { 'insts': insts, '_': config.i18n, 'today': today }) elif section == 'charts': users = User.select() storages = Storage.select() order = Order() inst = SaleInstallment() sale = Sale() self.RenderFile( 'dashboard/charts.htm', { 'users': users, 'storages': storages, 'order': order, 'inst': inst, 'sale': sale, '_': config.i18n }) else: users = User.select() storages = Storage.select() order = Order() inst = SaleInstallment() sale = Sale() self.RenderFile( 'dashboard/home.htm', { 'users': users, 'storages': storages, 'order': order, 'inst': inst, 'sale': sale, '_': config.i18n })
def hello_world(): db.drop_all() db.create_all() order = Order() n = Person(username="******", email="*****@*****.**") nutzerList = db.session.query(Person).filter_by(username=n.username).all() if not nutzerList: db.session.add(n) db.session.commit() product1 = Product(name="CD") order.product = product1 order.user = n db.session.add(order) db.session.commit() return "new inn ;-)"
def create_order(email, foods, address_id, remark, shop_id): user = User.query.filter_by(email=email).first() order = Order(status=0, remark=remark, address_id=address_id, shop_id=shop_id) for food in foods: order.food_numbers.append( FoodNumber(number=food.number, food_id=food.id)) user.orders.append(order) db.session.commit() return order
def Process(self, section): if section == 'new': order = Order() storages = Storage.select() suppliers = Supplier.select() groups = Group.select() order.id = 0 self.RenderFile( 'purchase/order.htm', { '_': config.i18n, 'order': order, 'storages': storages, 'suppliers': suppliers, 'group-list': groups }) elif section == 'edit': order = Order.get(Order.id == self.IntReq('id')) storages = Storage.select() suppliers = Supplier.select() groups = Group.select() products = order.details for sup in suppliers: if sup == order.supplier: sup.selected = True for stg in storages: if stg == order.storage: stg.selected = True self.RenderFile( 'purchase/order.htm', { '_': config.i18n, 'order': order, 'storages': storages, 'suppliers': suppliers, 'group-list': groups, 'products': products }) elif section == 'save': id = self.IntReq('id') storageId = self.IntReq('storageId') supplierId = self.IntReq('supplierId') try: order = Order.get(Order.id == id) except: order = Order() order.date = getDate() order.time = getTime() order.verified = False supplier = Supplier.get(Supplier.id == supplierId) storage = Storage.get(Storage.id == storageId) order.supplier = supplier order.storage = storage order.user = self.authentication.SessionObject.user order.save() form = self.getForm() row_ids = [] for key in form.keys(): if key[0] == 'g': id = self.ToInt(key[(key.find('[') + 1):key.find(']')]) row_ids.append(id) row_ids.sort() keep_rows = [] pids = [] # order.clearDetails() for row_id in row_ids: x = str(row_id) group_id = self.IntReq('g[' + x + ']') product_id = self.IntReq('i[' + x + ']') group = Group.get(Group.id == group_id) p = Product() if product_id > 0: p = Product.get(Product.id == product_id) p.order = order p.group = group p.name = self.StringReq('n[' + x + ']') p.purchase = self.FloatReq('p[' + x + ']') p.sale = self.FloatReq('s[' + x + ']') p.quantity = self.FloatReq('q[' + x + ']') p.save() pids.append(p.id) order.clearDetails(pids) self.RenderJSON({'Id': order.id}) elif section == 'manage': orders = Order.select() self.RenderFile('purchase/manage.htm', { '_': config.i18n, 'purchases': orders })
def Process(self, section): if section == 'purchase': purchases = Order.select().where(Order.verified == 0) self.RenderFile('confirm/purchase.htm', {'_': config.i18n, 'purchases': purchases}) elif section == 'purchase.details': id = self.IntReq('id') products = Product.select().where(Product.order == Order.get(Order.id == id)) self.RenderFile('confirm/purchase.details.htm', {'_': config.i18n, 'products': products}) elif section == 'purchse.confirm': id = self.IntReq('id') try: o = Order().get(Order.id == id) o.verified = 1 o.save() # update storage info products = Product.select().join(Order).where(Order.id == o.id) for product in products: try: sc = StorageChange.get( (StorageChange.product == product) & (StorageChange.storage == o.storage)) sc.enter += product.quantity except: sc = StorageChange() sc.storage = o.storage sc.product = product sc.date = getDate() sc.time = getTime() sc.enter = product.quantity sc.purchase = product.purchase sc.sell = product.sale sc.reftype = 1 sc.refid = o.id sc.save() self.RenderJSON({'result': 'OK'}) except: self.RenderJSON({'result': 'NO'}) elif section == 'sale': sales = Sale.select().where(Sale.verified == 0) self.RenderFile('confirm/sale.htm', {'_': config.i18n, 'sales': sales}) elif section == 'sale.details': sale = Sale.get(Sale.id == self.IntReq('id')) details = sale.details i = 1 for detail in details: detail.index = i i = i + 1 customers = Person.select() storages = Storage.select() for cus in customers: if cus == sale.customer: cus.selected = True self.RenderFile('confirm/sale.details.htm', { '_': config.i18n, 'Sale': sale, 'Sale_details': details, 'Storages': storages, 'Customers': customers }) elif section == 'sale.confirm': id = self.IntReq('id') try: s = Sale().get(Sale.id == id) s.verified = 1 s.save() # update storage info # saledetails = SaleDetails.select().join(Sale).where(Sale.id == s.id) # for sd in saledetails: # try: # sc = StorageChange.get((StorageChange.product == sd.product) & (StorageChange.storage == sd.storage)) # sc.export += sd.quantity # sc.sell = sd.saleprice # sc.purchase = sd.product.purchase # sc.save() # except: # self.RenderJSON({'result':'NO'}) self.RenderJSON({'result': 'OK'}) except: self.RenderJSON({'result': 'NO'})