def product_seeder(amount): games_names = ['DOOM', 'DIABLO', 'DOTA', 'GTA', 'Rust', 'Grad', 'Need For Speed', 'The legend of Zelda', 'Half-Life', 'BioShock', 'The Witcher', 'Portal', 'Tetris', 'Mario', 'Halo'] movies_names = ['Hunters of the Forest', 'Girl in pink', 'Wolf and Bear forest friends', 'Some movie', 'King' 'Queen of the mexico', 'Green Land', 'Rome The Empire', 'Yakudza', 'Ice Cold', 'The Beast'] music = ['AppleMusic subscribe'] p_dict = { 'Action': games_names, 'MOVIE': movies_names, 'MUSIC': music } for _ in range(amount): price = randint(0, 100) category = choice(list(p_dict.keys())) product_dict = { 'title': choice(p_dict[category]), 'description': lorem.sentence(), 'price': price, 'new_price': price // 2, 'is_discount': choice([True, False]), 'category': Category.objects(title=category).get(), } product = Product(**product_dict) product.save()
def put(self, p_id): obj = Product.objects(id=p_id).get() if not request.json: if request.files: obj.update(**{'img': request.files['img'].read()}) data = json.loads(request.form['request']) if data.get('category'): category = data.pop('category') data['category'] = Category.objects(id=(category['id'])).get() obj.update(**data) else: if request.json.get('category'): category = request.json.pop('category') request.json['category'] = Category.objects( id=(category['id'])).get() obj.update(**request.json) return ProductScheme().dump(obj.reload())
def add_product(): if (session['add_product'] == False): return render_template('add-product.html', err=True) else: if request.method == 'POST': name = request.form['name'] description = request.form['description'] category = request.form['category'] price = request.form['price'] file = request.files['file'] if 'file' not in request.files: flash('No file part') return redirect(request.url) # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) product_id = name.replace(" ", "_").replace("-", "_").replace( "(", "_").replace(")", "_").lower() + "_" + category.replace( " ", "_").lower() product = Product(product_id, name, description, category, price, file.filename) db.session.add(product) db.session.commit() return redirect(url_for('products')) else: return render_template('add-product.html')
def add_collection(self): form = AccountForm.LoginForm(request.form) if self.request.method == 'GET': return render_template('add_collection.html', user=current_user, formLogin=form) elif self.request.method == 'POST': parsed_json = json.loads(self.request.data) print current_user product_id = None for data in parsed_json: print "the data is %s" % data if ('collection_title' in data): produc = Product( title=data['collection_title'], description=data['collection_description'], user_id=g.user.id) product_id = InsertRow(produc) elif (product_id is not None): prodItem = ProductItem( image_url=data['image_url'], image_description=data['image_description'], product_id=product_id) Item_id = InsertRow(prodItem) return self.request.data
def create_product(self, args): """ creates product with the given params :param args: params passed to update :return: if successful: True and product_id. if failed: False and error string. """ if args['name'] is None: return { "isSuccessful": False, "error": "You must specify the name" }, 401 product = Product(name=args['name'], seller_id=args['seller_id'], description1=args['description1'], description2=args['description2'], sku_id=args['sku_id'], price=args['price'], image_urls=args['image_urls'], video_urls=args['video_urls'], discount=args['discount'], coupons=args['coupons'], available_colors=args['available_colors'], weight=args['weight']) try: db.session.add(product) db.session.commit() return {"id": product.id, "isSuccessful": True}, 202 except SQLAlchemyError as e: db.session.rollback() logger.error(e) return {"error": str(e), "isSuccessful": False}, 401 finally: db.session.close()
def add(self, name, subgroup_id=None, seller_id=None, cart_id=None): product = Product() product.name = name product.subgroup_id = subgroup_id product.seller_id = seller_id product.cart_id = cart_id self.session.add(product)
def inline(message): print('sales') products = Product.objects(is_discount=True) for product in products: keyboard = InlineKeyboardMarkup(row_width=2) buttons = [ InlineKeyboardButton(f'{i}', callback_data=f'{key}_{product.id}') for key, i in keyboards.product_kb.items() ] keyboard.add(*buttons) bot.send_message(message.chat.id, text=f'{product.title} Цена: {product.get_price} 💵', reply_markup=keyboard)
def get_total(self): cart_contents_with_prices = dict() for code, quantity in self.cart.contents.iteritems(): product = get_product(code) # We don't want to repeat DB lookups when discounts are applied, so create a context # of the cart with current prices and quantities cart_contents_with_prices[code] = Product(code, product["description"], product["price"], quantity) return get_discounted_total(cart_contents_with_prices) / 100.0
def add_product(): name = request.json['name'] description = request.json['description'] price = request.json['price'] qty = request.json['qty'] image_url = request.json['image_url'] new_product = Product(name, description, price, qty, image_url) if Product.query.filter_by(name=name).first(): return jsonify({"msg": "product already exist"}) db.session.add(new_product) db.session.commit() return product_schema.jsonify(new_product)
def test_crud_operations(self): """ - create a product - fetch it - update it - delete it """ # Create Product dettol = get_product(dettol_details) resp = self.client.post('/products', data=json.dumps(dettol_details), content_type='application/json', headers=self.headers) dettol_id = json.loads(resp.data)['id'] self.assertEquals(resp.status_code, 202) # Gets product dettol_id_dict = {"id": dettol_id} dettol_get_resp = self.client.get('/products', query_string=dettol_id_dict, headers=self.headers) self.assertEquals(dettol_get_resp.status_code, 200) dettol_get_product = Product() dettol_data = json.loads(dettol_get_resp.data)['data'][0] for key, value in dettol_data.items(): setattr(dettol_get_product, key, value) self.assertEquals(self.check_for_equality(dettol, dettol_get_product), True) # update product lifebuoy_details['id'] = dettol_id resp = self.client.post('/products', data=json.dumps(lifebuoy_details), content_type='application/json', headers=self.headers) self.assertEquals(resp.status_code, 202) lifebuoy_id = json.loads(resp.data)['id'] self.assertEquals(dettol_id, lifebuoy_id) lifebuoy = get_product(lifebuoy_details) lifebuoy.id = dettol_id get_lifebuoy = Product.query.get(lifebuoy_id) self.assertEquals(self.check_for_equality(lifebuoy, get_lifebuoy), True) # delete product self.client.delete('/products', query_string=dettol_id_dict, headers=self.headers) pass
def add_product(): data_obtained = request.get_json() if Product.query.filter_by( product_name=data_obtained['product_name']).first(): return {"error": "Product is already added!"} # Converting base64 image file_binary_name = data_obtained['product_image'] response = cloudinary.uploader.upload(file_binary_name) # Saving to database product_object = Product(product_name=data_obtained['product_name'], product_price=data_obtained['product_price'], product_image=response['public_id']) db.session.add(product_object) db.session.commit() return {"message": "Product added successfully!"}
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 show_product_or_sub_category(call): obj_id = call.data.split('_')[1] category = models.Category.objects(id=obj_id).get() if category.is_parent: kb = keyboards.InlineKB( iterable=category.subcategory, lookup_fields='id', named_arg='category', ) kb.generate_kb() kb.add( InlineKeyboardButton(text=f'<<', callback_data=f'back_{category.id}')) bot.edit_message_text(text=category.title, chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=kb) else: products = Product.objects(category=obj_id) for product in products: photo = product.photo_product.read() keyboard = InlineKeyboardMarkup(row_width=2) buttons = [ InlineKeyboardButton(f'{i}', callback_data=f'{key}_{product.id}') for key, i in keyboards.product_kb.items() ] keyboard.add(*buttons) bot.send_photo( chat_id=call.message.chat.id, photo=photo, caption= f'<b>{product.title}</b> Цена: <i> {product.get_price} 💵 </i> ' f' <code> {product.description} </code>', reply_markup=keyboard, parse_mode='HTML')
def post(self): if not request.json: data = json.loads(request.form['request']) if request.files: data['img'] = request.files['img'].read() if data.get('category'): category = data.pop('category') data['category'] = Category.objects(id=(category['id'])).get() obj = Product(**data) else: category = request.json.pop('category') request.json['category'] = Category.objects( id=(category['id'])).get() obj = Product(**request.json) obj.save() return ProductScheme().dump(obj)
def Process(self, section): # Open a form in order to save or update if section == 'person.new': person = Person() person.id = 0 self.RenderFile('person/person.htm', { '_': config.i18n, 'person': person }) elif section == 'supplier.new': supplier = Supplier() supplier.id = 0 self.RenderFile('supplier/supplier.htm', { '_': config.i18n, 'supplier': supplier }) elif section == 'group.new': group = Group() group.id = 0 self.RenderFile('group/group.htm', { '_': config.i18n, 'group': group }) elif section == 'storage.new': storage = Storage() storage.id = 0 self.RenderFile('storage/storage.htm', { '_': config.i18n, 'storage': storage }) elif section == 'cost.new': cost = Cost() cost.id = 0 self.RenderFile('cost/cost.htm', {'_': config.i18n, 'cost': cost}) # Open a form with fields filled with data to update elif section == 'person.edit': id = self.IntReq('id') person = Person.get(Person.id == id) self.RenderFile('person/person.htm', { '_': config.i18n, 'person': person }) elif section == 'supplier.edit': id = self.IntReq('id') supplier = Supplier.get(Supplier.id == id) self.RenderFile('supplier/supplier.htm', { '_': config.i18n, 'supplier': supplier }) elif section == 'group.edit': id = self.IntReq('id') group = Group().get(Group.id == id) self.RenderFile('group/group.htm', { '_': config.i18n, 'group': group }) elif section == 'storage.edit': id = self.IntReq('id') storage = Storage().get(Storage.id == id) self.RenderFile('storage/storage.htm', { '_': config.i18n, 'storage': storage }) elif section == 'cost.edit': id = self.IntReq('id') cost = Cost().get(Cost.id == id) self.RenderFile('cost/cost.htm', {'_': config.i18n, 'cost': cost}) # Send save operation to the controler elif section == 'person.save': id = self.IntReq('id') try: p = Person.get(Person.id == id) except: p = Person() p.name = self.StringReq('name') p.city = self.StringReq('city') p.phone = self.StringReq('phone') p.email = self.StringReq('email') p.address = self.StringReq('address') p.save() self.RenderJSON({ 'Result': 'success', 'id': p.id }) elif section == 'supplier.save': id = self.IntReq('id') try: s = Supplier.get(Supplier.id == id) except: s = Supplier() s.name = self.StringReq('name') s.manager = self.StringReq('manager') s.tell = self.StringReq('tell') s.field = self.StringReq('field') s.save() self.RenderJSON({ 'Result': 'success', 'id': s.id }) elif section == 'group.save': id = self.IntReq('id') try: g = Group.get(Group.id == id) except: g = Group() g.name = self.StringReq('name') g.unit = self.StringReq('unit') g.save() self.RenderJSON({'Result': 'success', 'id': g.id}) elif section == 'storage.save': id = self.IntReq('id') try: st = Storage.get(Storage.id == id) except: st = Storage() st.name = self.StringReq('name') st.tell = self.StringReq('tell') st.address = self.StringReq('address') st.save() self.RenderJSON({'Result': 'success', 'id': st.id}) elif section == 'cost.save': id = self.IntReq('id') try: ct = Cost.get(Cost.id == id) except: ct = Cost() ct.regdate = self.StringReq('regdate') ct.regtime = self.StringReq('regtime') ct.title = self.StringReq('title') ct.invoiceno = self.StringReq('invoiceno') ct.amount = self.FloatReq('amount') ct.save() self.RenderJSON({'Result': 'success', 'id': ct.id}) elif section == 'person.check': self.output = '' elif section == 'person.filter': list = Person.select() args = {'data': list, '_': config.i18n} self.RenderFile('person/list.htm', args) # Delete section for each item elif section == 'group.delete': id = self.IntReq('id') group = Group.get(Group.id == id) group.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'supplier.delete': id = self.IntReq('id') supplier = Supplier.get(Supplier.id == id) supplier.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'storage.delete': id = self.IntReq('id') storage = Storage.get(Storage.id == id) storage.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'person.delete': id = self.IntReq('id') person = Person.get(Person.id == id) person.delete_instance() self.RenderJSON({'result': 'OK'}) elif section == 'cost.delete': id = self.IntReq('id') cost = Cost.get(Cost.id == id) cost.delete_instance() self.RenderJSON({'result': 'OK'}) # Manage section for items elif section == 'person.manage': self.RenderFile('person/manage.htm', { '_': config.i18n, 'persons': Person.select() }) elif section == 'supplier.manage': args = {'_': config.i18n, 'suppliers': Supplier.select()} self.RenderFile('supplier/manage.htm', args) elif section == 'group.manage': list = Group.select() args = {'groups': list, '_': config.i18n} self.RenderFile('group/manage.htm', args) elif section == 'storage.manage': list = Storage.select() args = {'storages': list, '_': config.i18n} self.RenderFile('storage/manage.htm', args) elif section == 'cost.manage': list = Cost.select() args = {'costs': list, '_': config.i18n} self.RenderFile('cost/manage.htm', args) elif section == 'person.history': id = self.IntReq('id') person = Person.get(Person.id == id) sales = Sale.select().where(Sale.customer == person) i = 1 for sale in sales: sale.index = i i += 1 args = {'person': person, 'sales': sales, '_': config.i18n} self.RenderFile('person/history.htm', args) elif section == 'group.goodlist': id = self.IntReq('id') g = Group.get(Group.id == id) args = { 'group': g, 'products': g.products.group_by(Product.name), '_': config.i18n } self.RenderFile('group/goodlist.htm', args) elif section == 'storage.goodlist': id = self.IntReq('id') is_JSON = (self.IntReq('json') != 0) s = Storage.get(Storage.id == id) args = {'_': config.i18n, 'storage': s, 'products': s.goodlist()} if is_JSON: ps = [] for p in s.goodlist(): pr = p.purchase_string() sl = p.sell_string() ps.append({ 'id': p.product.id, 'name': p.product.name, 'qty': p.storage_current(s), 'purchase': pr, 'sale': sl }) self.RenderJSON(ps) else: self.RenderFile('storage/goodlist.htm', args) elif section == 'supplier.purchaselist': id = self.IntReq('id') s = Supplier.get(Supplier.id == id) products = Product.select().join(Order).where(Order.supplier == s) i = 1 for p in products: p.index = i i = i + 1 args = {'supplier': s, 'products': products, '_': config.i18n} self.RenderFile('supplier/purchaselist.htm', args) elif section == 'person.instullment': id = self.IntReq('id') inst = SaleInstallment.get(SaleInstallment.id == id) inst.currentdate = getDate() args = {'inst': inst, '_': config.i18n} self.RenderFile('person/instullment.htm', args) elif section == 'person.instullment.save': id = self.IntReq('id') try: si = SaleInstallment.get(SaleInstallment.id == id) except: si = SaleInstallment() si.dateback = self.StringReq('dateback') si.amount = self.FloatReq('amount') si.save() sale = Sale.get(Sale.id == si.sale.id) sale.payment = float(sale.payment) + float(si.amount) sale.save() self.RenderJSON({ 'result': 'ok', 'id': si.id, 'amount': si.amount, 'dateback': si.dateback }) else: self.NotImplemented(section)
app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///product.db' db = SQLAlchemy(app) NUMBER_TO_GENERATE = 5 # Creating training data X, y, VOCAB_SIZE, ix_to_char = load_data('./services/producthunt.txt', 100) # Either load the model or create it. # Loading the trained weights print('Loading model') json_file = open('model.json', 'r', encoding='utf-8') model_json = json_file.read() json_file.close() model = model_from_json(model_json) model.load_weights('checkpoint_layer_2_hidden_500_epoch_40.hdf5') print("Loaded model from disk") generated = generate_text(model, NUMBER_TO_GENERATE, VOCAB_SIZE, ix_to_char) for string in generated: name = string.split(":")[0] tagline = ''.join(string.split(":")[1:]) db.session.add(Product(name=name, tagline=tagline)) db.session.commit()
def get(self, id=None): if not id: return ProductSchema().dump(Product.objects, many=True) return ProductSchema().dump(Product.objects(id=id).get())
def post(self): instance = Product(**request.json).save() return ProductSchema().dump(instance)
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'})
def put(self, id): obj = Product.objects(id=id).get() obj.update(**request.json) return ProductSchema().dump(obj.reload())
def get_product(details): product = Product() for key, value in details.items(): if value: setattr(product, key, value) return product
def delete(self, id): ProductSchema().dump(Product.objects(id=id).delete()) return jsonify(**{id: 'deleted'})
def get(self, p_id=None): if p_id: return ProductScheme().dump(Product.objects(id=p_id).get()) return ProductScheme().dump(Product.objects, many=True)
def delete(self, p_id): obj = Product.objects(id=p_id).get() obj.delete() return {p_id: 'DELETED'}
def add_from_csv(self, columns, values): product = Product() product.from_csv(columns, values) self.session.add(product)
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 })