def unvoid(self, id): c.invoice = Invoice.find_by_id(id, True) c.invoice.void = None c.invoice.manual = True meta.Session.commit() h.flash("Invoice was un-voided.") return redirect_to(action='view', id=c.invoice.id)
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 check(self, app, environ, start_response): if not environ.get('REMOTE_USER'): set_redirect() raise NotAuthenticatedError('Not Authenticated') person = Person.find_by_email(environ['REMOTE_USER']) if person is None: environ['auth_failure'] = 'NO_USER' raise NotAuthorizedError( 'You are not one of the users allowed to access this resource.' ) invoice = Invoice.find_by_id(self.invoice_id) if invoice is None: raise NotAuthorizedError( "Invoice doesn't exist" ) if person.id <> invoice.person_id: set_role("Invoice is not for this user") raise NotAuthorizedError( "Invoice is not for this user" ) return app(environ, start_response)
def remind(self): c.invoice_collection = Invoice.find_all() #c.invoice = c.invoice_collection[0] #c.recipient = c.invoice.person # create dummy person for example: c.recipient = FakePerson() return render('/invoice/remind.mako')
def void(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_void(): h.flash("Invoice was already voided.") return redirect_to(action='view', id=c.invoice.id) if h.auth.authorized(h.auth.has_organiser_role): c.invoice.void = "Administration Change" meta.Session.commit() h.flash("Invoice was voided.") return redirect_to(action='view', id=c.invoice.id) else: if c.invoice.paid(): h.flash("Cannot void a paid invoice.") return redirect_to(action='view', id=c.invoice.id) c.invoice.void = "User cancellation" c.person = c.invoice.person meta.Session.commit() email(lca_info['contact_email'], render('/invoice/user_voided.mako')) h.flash("Previous invoice was voided.") return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
def void(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_void(): h.flash("Invoice was already voided.") return redirect_to(action='view', id=c.invoice.id) if h.auth.authorized(h.auth.has_organiser_role): c.invoice.void = "Administration Change" meta.Session.commit() h.flash("Invoice was voided.") return redirect_to(action='view', id=c.invoice.id) else: if c.invoice.paid(): h.flash("Cannot void a paid invoice.") return redirect_to(action='view', id=c.invoice.id) c.invoice.void = "User cancellation" c.person = c.invoice.person meta.Session.commit() email(lca_info['contact_email'], render('/invoice/user_voided.mako')) h.flash("Previous invoice was voided.") return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
def printable(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.printable = True c.invoice = Invoice.find_by_id(id, True) c.payment_received = None c.payment = None if c.invoice.paid() and c.invoice.total() > 0: c.payment_received = c.invoice.good_payments()[0] c.payment = c.payment_received.payment return render('/invoice/view_printable.mako')
def printable(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.printable = True c.invoice = Invoice.find_by_id(id, True) c.payment_received = None c.payment = None if c.invoice.paid() and c.invoice.total() > 0: c.payment_received = c.invoice.good_payments()[0] c.payment = c.payment_received.payment return render('/invoice/view_printable.mako')
def pay_manual(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person error = self._check_invoice(person, invoice, ignore_overdue=True) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total() c.payment.invoice = invoice meta.Session.commit() return redirect_to(controller='payment', id=c.payment.id, action='new_manual')
def pdf(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() import os, tempfile, libxml2, libxslt c.invoice = Invoice.find_by_id(id, True) xml_s = render('/invoice/pdf.mako') xsl_f = file_paths['zk_root'] + '/zookeepr/templates/invoice/pdf.xsl' xsl_s = libxml2.parseFile(xsl_f) xsl = libxslt.parseStylesheetDoc(xsl_s) xml = libxml2.parseDoc(xml_s) svg_s = xsl.applyStylesheet(xml, None) (svg_fd, svg) = tempfile.mkstemp('.svg') xsl.saveResultToFilename(svg, svg_s, 0) xsl.freeStylesheet() xml.freeDoc() svg_s.freeDoc() (pdf_fd, pdf) = tempfile.mkstemp('.pdf') os.close(svg_fd) os.close(pdf_fd) os.system('inkscape -z -f %s -A %s' % (svg, pdf)) pdf_f = file(pdf) res = Response(pdf_f.read()) pdf_f.close() res.headers['Content-type'] = 'application/pdf' #res.headers['Content-type']='application/octet-stream' #res.headers['Content-type']='text/plain; charset=utf-8' filename = lca_info['event_shortname'] + '_' + str( c.invoice.id) + '.pdf' res.headers['Content-Disposition'] = ('attachment; filename=%s' % filename) # We should really remove the pdf file, shouldn't we. return res
def pdf(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() import os, tempfile, libxml2, libxslt c.invoice = Invoice.find_by_id(id, True) xml_s = render('/invoice/pdf.mako') xsl_f = file_paths['zk_root'] + '/zookeepr/templates/invoice/pdf.xsl' xsl_s = libxml2.parseFile(xsl_f) xsl = libxslt.parseStylesheetDoc(xsl_s) xml = libxml2.parseDoc(xml_s) svg_s = xsl.applyStylesheet(xml, None) (svg_fd, svg) = tempfile.mkstemp('.svg') xsl.saveResultToFilename(svg, svg_s, 0) xsl.freeStylesheet() xml.freeDoc() svg_s.freeDoc() (pdf_fd, pdf) = tempfile.mkstemp('.pdf') os.close(svg_fd); os.close(pdf_fd) os.system('inkscape -z -f %s -A %s' % (svg, pdf)) pdf_f = file(pdf) res = Response(pdf_f.read()) pdf_f.close() res.headers['Content-type']='application/pdf' #res.headers['Content-type']='application/octet-stream' #res.headers['Content-type']='text/plain; charset=utf-8' filename = lca_info['event_shortname'] + '_' + str(c.invoice.id) + '.pdf' res.headers['Content-Disposition']=( 'attachment; filename=%s' % filename ) # We should really remove the pdf file, shouldn't we. return res
def pay(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() #return render('/registration/really_closed.mako') error = self._check_invoice(person, invoice) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total() c.payment.invoice = invoice meta.Session.commit() return render("/invoice/payment.mako")
def pay(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not h.auth.authorized( h.auth.Or(h.auth.is_same_zookeepr_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() #return render('/registration/really_closed.mako') error = self._check_invoice(person, invoice) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total() c.payment.invoice = invoice meta.Session.commit() return render("/invoice/payment.mako")
def _to_python(self, value, state): invoice = Invoice.find_by_id(int(value), False) if invoice is None: raise Invalid("Unknown invoice ID.", value, state) else: return invoice
def index(self): c.can_edit = True c.invoice_collection = Invoice.find_all() return render('/invoice/list.mako')
def remind(self): c.invoice_collection = Invoice.find_all() c.invoice = c.invoice_collection[0] c.recipient = c.invoice.person return render('/invoice/remind.mako')