def new(self, **kwargs): invoice_no = request.params["invoice_no"] amount = request.params["amount"] po_id = request.params["po_id"] vendor_id = request.params["vendor_id"] user_id = request.params["user_id"] po_amount = PurchaseOrder.get_amount(po_id) if int(amount) != int(po_amount): return ("error", "Invoice amount does not match PO amount.") invoice = Invoice.create(invoice_no, po_id, vendor_id, user_id, amount) warehouse = Warehouse.get(1) # Send email config = Config() server = config.get("mailserver", "server") port = config.get("mailserver", "port") username = config.get("mailserver", "username") password = config.get("mailserver", "password") sender = config.get("email", "sender") recipient = warehouse.manager_email subject = config.get("email", "subject2") message = ( "Hi " + User.get(warehouse.manager).firstname + " " + User.get(warehouse.manager).lastname + ",\r\n\r\n" ) message += "Invoice %s has been received for purchase order %s. %sRegards %s" % ( invoice_no, po_id, "\r\n\r\n", "\r\n\r\n", ) h.send_mail(server, port, username, password, sender, recipient, subject, message) return ("invoice_object", invoice)