def invoice_form(): invoice_details = InvoiceDetails.query.one_or_none() positions_form = PositionsForm(prefix='positions') invoice_form = InvoiceForm(prefix='invoice', obj=invoice_details) if request.method == 'POST': if positions_form.validate_on_submit(): unit = positions_form.unit.data amount = positions_form.amount.data price = positions_form.price.data description = positions_form.description.data total = amount * price new_position = Positions(unit=unit, amount=amount, price=price, description=description, total=total) new_position.insert() flash('Position succesfully added!', 'success') elif invoice_form.validate_on_submit(): form_invoice_details = invoice_form.data form_invoice_details.pop('csrf_token', None) if invoice_details is None: invoice_details = InvoiceDetails(**form_invoice_details) invoice_details.insert() else: invoice_details.update(**form_invoice_details) positions = Positions.query.all() total = 0 for position in positions: total += position.total created = datetime.date.today() payment_due = created + datetime.timedelta(days=14) return render_template('/invoice_details.html', title='Invoice Details', invoice_details=invoice_details, positions=positions, created=created, payment_due=payment_due, total=total) else: flash('Please check your form input!', 'error') positions = Positions.query.all() return render_template('/invoice_form.html', title='Invoice Form', active_page='form', positions_form=positions_form, invoice_form=invoice_form, positions=positions)
def main(): print("Загружаю главную страницу") form1 = InvoiceForm() if form1.validate_on_submit(): print("Обнаружены данные из формы") controller.add_item(form1) items_data = db.get_all_items() items = [(item.id, item.name, item.size_x, item.size_y, item.size_z, item.weight, item.stowage_id) for item in items_data] stowages_data = db.get_all_stowages() stowages = [(stowage.id, stowage.row, stowage.level, stowage.size_x, stowage.size_y, stowage.size_z, stowage.json, stowage.empty) for stowage in stowages_data] print("Загрузка главной страницы") return render_template('main.html', items=items, stowages=stowages, form1=form1)
def check(): form = InvoiceForm() if form.validate_on_submit(): invoice = Invoice( form.data['amount'], form.data['currency'], form.data['description'] ) db.session.add(invoice) db.session.commit() app.logger.info(u"invoice created: {}".format(invoice)) # hack for passing signature check amount = int(invoice.amount) if ( int(invoice.amount) == float(invoice.amount)) else invoice.amount payload = { "shop_id": SHOP_ID, "amount": amount, "currency": invoice.currency, 'shop_invoice_id': invoice.id, "description": invoice.description } if invoice.currency == '980': payload["payway"] = 'w1_uah' sign = _get_sign(payload, INVOICE_KEYS) payload['sign'] = sign resp = requests.post(UAH_INVOICE_URL, json=payload) data = json.loads(resp.content)['data'] app.logger.info("data: {}".format(data)) if not data: return jsonify(json.loads(resp.content)) url = data['source'] data = data['data'] elif invoice.currency == '643': sign = _get_sign(payload, TIP_KEYS) payload['sign'] = sign data = payload url = TIP_URL else: return jsonify({'result': 'error', 'message': 'Wrong currency'}) app.logger.info("data sent: {}".format(data)) return jsonify({'result': 'ok', 'data': data, 'url': url}) return jsonify({'result': 'error', 'message': 'Form validation error'})
def invoice(): form = InvoiceForm() if form.validate_on_submit(): return redirect(url_for('pdf_template')) return render_template('invoice_form2.html', title='SF online', form=form)