def _new(self): data = json.loads(request.params['invoice']) person_id = int(data['person_id']) due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y') invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None) for item in data['items']: invoice_item = InvoiceItem() if item.has_key('product_id') and item['product_id']: product = Product.find_by_id(item['product_id']) category = product.category invoice_item.product = product invoice_item.description = product.category.name + ' - ' + product.description else: invoice_item.description = item['description'] invoice_item.cost = int(item['cost']) invoice_item.qty = int(item['qty']) invoice.items.append(invoice_item) meta.Session.add(invoice) meta.Session.commit() return dict(r=dict(invoice_id=invoice.id))
def save_new_invoice(self): """ """ import json debug = "" data = request.params['invoice'] data = json.loads(data) person_id = int(data['person_id'],10) due_date = datetime.datetime.strptime(data['due_date'], '%d/%m/%Y') invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None) for invoice_item in data['invoice_items']: item = InvoiceItem() if invoice_item.has_key('description') and invoice_item['description']: item.description = invoice_item['description'] else: product = Product.find_by_id(invoice_item['product_id']) category = product.category item.product = product item.description = product.category.name + ' - ' + product.description item.cost = float(invoice_item['cost']) item.qty = int(invoice_item['qty'],10) invoice.items.append(item) meta.Session.add(invoice) meta.Session.commit() debug += str(invoice.id) return debug
def _new(self): results = self.form_result['invoice'] del(results['item_count']) items = results['items'] results['items'] = [] c.invoice = Invoice(**results) for i in items: item = InvoiceItem() if i['description'] != "": item.description = i['description'] else: product = Product.find_by_id(i['product'].id) category = product.category item.product = i['product'] item.description = product.category.name + ' - ' + product.description item.cost = i['cost'] item.qty = i['qty'] c.invoice.items.append(item) c.invoice.manual = True c.invoice.void = None meta.Session.add(c.invoice) meta.Session.commit() h.flash("Manual invoice created") return redirect_to(action='view', id=c.invoice.id)
def _new(self): data = json.loads(request.params["invoice"]) person_id = int(data["person_id"]) due_date = datetime.datetime.strptime(data["due_date"], "%d/%m/%Y") invoice = Invoice(person_id=person_id, due_date=due_date, manual=True, void=None) for item in data["items"]: invoice_item = InvoiceItem() if item.has_key("product_id") and item["product_id"]: product = Product.find_by_id(item["product_id"]) category = product.category invoice_item.product = product invoice_item.description = product.category.name + " - " + product.description else: invoice_item.description = item["description"] invoice_item.cost = int(item["cost"]) invoice_item.qty = int(item["qty"]) invoice.items.append(invoice_item) meta.Session.add(invoice) meta.Session.commit() return dict(r=dict(invoice_id=invoice.id))