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 == 'new': customers = Person.select() storages = Storage.select() sale = Sale() sale.id = 0 sale.advance = 0 sale.date = getDate() self.RenderFile( 'sale/sale.htm', { '_': config.i18n, 'Customers': customers, 'Storages': storages, 'Sale': sale }) elif section == 'edit': sale = Sale.get(Sale.id == self.IntReq('id')) details = sale.details i = 1 for detail in details: detail.index = i i = i + 1 i = 1 installments = sale.installments for si in installments: si.index = i i = i + 1 customers = Person.select() storages = Storage.select() for cus in customers: if cus == sale.customer: cus.selected = True self.RenderFile( 'sale/sale.htm', { '_': config.i18n, 'Sale': sale, 'Sale_details': details, 'Sale_installments': installments, 'Storages': storages, 'Customers': customers }) elif section == 'save': id = self.IntReq('id') pays = self.IntReq('pays') prepaid = self.FloatReq('prepaid') customerId = self.IntReq('customerId') try: sale = Sale.get(Sale.id == id) except: sale = Sale() sale.date = getDate() sale.time = getTime() sale.user = self.authentication.SessionObject.user sale.verified = False customer = Person.get(Person.id == customerId) sale.customer = customer sale.installment = pays sale.advance = prepaid sale.payment = 0 sale.fullsale = 0 sale.save() form = self.getForm() row_ids = [] srow_ids = [] for key in form.keys(): if key[0] == 'g': id = self.ToInt(key[(key.find('[') + 1):key.find(']')]) row_ids.append(id) elif key[0] == 'b': id = self.ToInt(key[(key.find('[') + 1):key.find(']')]) srow_ids.append(id) row_ids.sort() srow_ids.sort() sale.clearDetails() full_sale = 0 for row_id in row_ids: x = str(row_id) storage_id = self.IntReq('g[' + x + ']') product_id = self.IntReq('p[' + x + ']') sale_price = self.FloatReq('s[' + x + ']') sale_qty = self.FloatReq('q[' + x + ']') full_sale += sale_price * sale_qty detail = SaleDetails() detail.sale = sale detail.product = Product.get(Product.id == product_id) detail.quantity = sale_qty detail.saleprice = sale_price detail.storage = Storage.get(Storage.id == storage_id) detail.save() schange = StorageChange() schange.storage = detail.storage schange.product = detail.product schange.enter = 0 schange.export = sale_qty schange.purchase = detail.product.purchase schange.sell = sale_price schange.date = sale.date schange.time = sale.time schange.reftype = 2 schange.refid = sale.id schange.save() for row_id in srow_ids: x = str(row_id) date = self.StringReq('b_d[' + x + ']') pay = self.FloatReq('y_p[' + x + ']') sins = SaleInstallment() sins.sale = sale sins.date = date sins.amount = pay sins.save() sale.fullsale = full_sale sale.save() self.RenderJSON({'Id': sale.id}) elif section == 'manage': sales = Sale.select() self.RenderFile('sale/manage.htm', { '_': config.i18n, 'sales': sales }) elif section == 'return': self.output = 'Return' elif section == 'installments': saleId = self.IntReq('SaleId') pqty = self.IntReq('Pays') sale = Sale.get(Sale.id == saleId) if pqty != sale.installment: sale.installment = pqty sale.save() sale.createInstallments() i = 0 for ins in sale.installments: i = i + 1 ins.index = i self.RenderFile('sale/installments.htm', { '_': config.i18n, 'sale': sale })