Exemplo n.º 1
0
 def __call__(self):
     if "invoice" in self.request.matchdict:
         session = DBSession()
         invoice_id = self.request.matchdict['invoice']
         invoice = session.query(Invoice).filter_by(id=invoice_id).first()
         if not invoice:
             return Response(status = 404)
     
     main = get_template('templates/master.pt')
     return dict(request=self.request, main=main, msgs=statusmessage.messages(self.request))
Exemplo n.º 2
0
 def __call__(self):
     if "customer" in self.request.matchdict:
         customer_id = self.request.matchdict['customer']
         session = DBSession()
         customer = session.query(Customer).filter_by(id=customer_id).first()
         if not customer:
             return Response(status = 404)
     
     main = get_template('templates/master.pt')
     return dict(request=self.request, main=main, msgs=statusmessage.messages(self.request))
Exemplo n.º 3
0
    def __call__(self):
        if "invoice" in self.request.matchdict:
            session = DBSession()
            invoice_id = self.request.matchdict['invoice']
            invoice = session.query(Invoice).filter_by(id=invoice_id).first()
            if not invoice:
                return Response(status=404)

        main = get_template('templates/master.pt')
        return dict(request=self.request,
                    main=main,
                    msgs=statusmessage.messages(self.request))
Exemplo n.º 4
0
 def test_handle_cancel(self):
     from seantisinvoice.views.invoice import InvoiceController
     from seantisinvoice import statusmessage
     # Register route for redirect in customer form actions
     testing.registerRoute('/', 'invoices', factory=None)
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     view = InvoiceController(None, request)
     view.handle_cancel()
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
Exemplo n.º 5
0
 def test_statusmessage(self):
     from seantisinvoice import statusmessage
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     msgs = statusmessage.messages(request)
     self.assertEquals([], msgs)
     statusmessage.show(request, u'Test message')
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u'Test message', msgs[0].msg)
     self.assertEquals(u'notice', msgs[0].msg_type)
     # Shown messages are removed
     msgs = statusmessage.messages(request)
     self.assertEquals([], msgs)
     statusmessage.show(request, u'First message')
     statusmessage.show(request, u'Second message', msg_type=u'error')
     msgs = statusmessage.messages(request)
     self.assertEquals(2, len(msgs))
     self.assertEquals(u'Second message', msgs[0].msg)
     self.assertEquals(u'error', msgs[0].msg_type)
     self.assertEquals(u'First message', msgs[1].msg)
Exemplo n.º 6
0
    def test_statusmessage(self):
        from seantisinvoice import statusmessage

        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        msgs = statusmessage.messages(request)
        self.assertEquals([], msgs)
        statusmessage.show(request, u"Test message")
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"Test message", msgs[0].msg)
        self.assertEquals(u"notice", msgs[0].msg_type)
        # Shown messages are removed
        msgs = statusmessage.messages(request)
        self.assertEquals([], msgs)
        statusmessage.show(request, u"First message")
        statusmessage.show(request, u"Second message", msg_type=u"error")
        msgs = statusmessage.messages(request)
        self.assertEquals(2, len(msgs))
        self.assertEquals(u"Second message", msgs[0].msg)
        self.assertEquals(u"error", msgs[0].msg_type)
        self.assertEquals(u"First message", msgs[1].msg)
Exemplo n.º 7
0
    def test_handle_cancel(self):
        from seantisinvoice.views.invoice import InvoiceController
        from seantisinvoice import statusmessage

        # Register route for redirect in customer form actions
        testing.registerRoute("/", "invoices", factory=None)
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        view = InvoiceController(None, request)
        view.handle_cancel()
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)
Exemplo n.º 8
0
 def test_handle_submit(self):
     from seantisinvoice.views.invoice import InvoiceController
     from seantisinvoice import statusmessage
     # Register route for redirect in invoice form actions
     testing.registerRoute('/', 'invoices', factory=None)
     # Create an invoice
     invoice = self._add_invoice()
     request = testing.DummyRequest()
     request.matchdict = dict(invoice=str(invoice.id))
     view = InvoiceController(None, request)
     data = view.form_defaults()
     self.assertEquals(u'Project', data['project_description'])
     # Change some of the invoice date
     data['project_description'] = u'My project'
     data['recurring_term'] = 30
     data['item_list'][0]['service_title'] = u'My service'
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(u'My project', data['project_description'])
     self.assertEquals(u'My service', data['item_list'][0]['service_title'])
     # Add an additional invoice item
     data['item_list'].append(
         dict(item_id='',
              service_title=u'Training',
              service_description=u'',
              amount=200.0))
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(u'Training', data['item_list'][1]['service_title'])
     # Reorder the items
     data['item_list'][0] = view.form_defaults()['item_list'][1]
     data['item_list'][1] = view.form_defaults()['item_list'][0]
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(u'Training', data['item_list'][0]['service_title'])
     # And remove one of them
     del data['item_list'][0]
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(1, len(data['item_list']))
     self.assertEquals(u'My service', data['item_list'][0]['service_title'])
     # Submit without changing anything
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     request.matchdict = dict(invoice=str(invoice.id))
     view = InvoiceController(None, request)
     view.handle_submit(data)
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
Exemplo n.º 9
0
 def test_handle_submit(self):
     from seantisinvoice.views.company import CompanyController
     from seantisinvoice import statusmessage
     # Register route for redirect in company form actions
     testing.registerRoute('/company', 'company', factory=None)
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     view = CompanyController(None, request)
     # All defaults must initially be empty
     default_values = view.form_defaults()
     self.assertEquals(None, default_values['name'])
     # Set all required fields
     self._set_company_profile()
     # Defaults must be set
     default_values = view.form_defaults()
     self.assertEquals(u'Example Inc.', default_values['name'])
     # Change company name through the form
     view.handle_submit(dict(name=u'Seantis GmbH'))
     default_values = view.form_defaults()
     self.assertEquals(u'Seantis GmbH', default_values['name'])
     # Check status message
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"Changes saved.", msgs[0].msg)
     # Submit without changing anything
     view.handle_submit(default_values)
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
     # Logo upload
     from os.path import join, dirname
     from schemaish.type import File
     logo_path = join(dirname(__file__), 'views', 'templates', 'static',
                      'uploads', 'test_logo.jpg')
     default_values['logo'] = File(open(logo_path, 'rb'), 'logo.jpg',
                                   'image/jpeg')
     view.handle_submit(default_values)
Exemplo n.º 10
0
    def test_handle_submit(self):
        from seantisinvoice.views.company import CompanyController
        from seantisinvoice import statusmessage

        # Register route for redirect in company form actions
        testing.registerRoute("/company", "company", factory=None)
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        view = CompanyController(None, request)
        # All defaults must initially be empty
        default_values = view.form_defaults()
        self.assertEquals(None, default_values["name"])
        # Set all required fields
        self._set_company_profile()
        # Defaults must be set
        default_values = view.form_defaults()
        self.assertEquals(u"Example Inc.", default_values["name"])
        # Change company name through the form
        view.handle_submit(dict(name=u"Seantis GmbH"))
        default_values = view.form_defaults()
        self.assertEquals(u"Seantis GmbH", default_values["name"])
        # Check status message
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"Changes saved.", msgs[0].msg)
        # Submit without changing anything
        view.handle_submit(default_values)
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)
        # Logo upload
        from os.path import join, dirname
        from schemaish.type import File

        logo_path = join(dirname(__file__), "views", "templates", "static", "uploads", "test_logo.jpg")
        default_values["logo"] = File(open(logo_path, "rb"), "logo.jpg", "image/jpeg")
        view.handle_submit(default_values)
Exemplo n.º 11
0
 def test_handle_submit(self):
     from seantisinvoice.views.customer import CustomerController
     from seantisinvoice import statusmessage
     # Register route for redirect in customer form actions
     testing.registerRoute('/customers', 'customers', factory=None)
     # Add a customer
     customer = self._add_customer()
     request = testing.DummyRequest()
     request.matchdict = dict(customer=str(customer.id))
     view = CustomerController(None, request)
     # Check default values
     default_values = view.form_defaults()
     self.assertEquals(u'Customers Inc.', default_values['name'])
     # Change the data
     default_values['name'] = u'Seantis GmbH'
     default_values['contact_list'][0]['first_name'] = u'Leopold'
     view.handle_submit(default_values)
     default_values = view.form_defaults()
     self.assertEquals(u'Seantis GmbH', default_values['name'])
     self.assertEquals(u'Leopold',
                       default_values['contact_list'][0]['first_name'])
     # Add an additional contact
     contact_date = dict(first_name=u'Stephen',
                         last_name=u'Dedalus',
                         title=u'Mr.',
                         contact_id='')
     default_values['contact_list'].append(contact_date)
     view.handle_submit(default_values)
     default_values = view.form_defaults()
     self.assertEquals(u'Stephen',
                       default_values['contact_list'][1]['first_name'])
     # Remove one of the contacts
     del default_values['contact_list'][0]
     view.handle_submit(default_values)
     default_values = view.form_defaults()
     self.assertEquals(1, len(default_values['contact_list']))
     # Contacts are alphabetically ordered.
     self.assertEquals(u'Stephen',
                       default_values['contact_list'][0]['first_name'])
     # Submit without changing anything
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     request.matchdict = dict(customer=str(customer.id))
     view = CustomerController(None, request)
     view.handle_submit(default_values)
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
Exemplo n.º 12
0
    def test_handle_submit(self):
        from seantisinvoice.views.invoice import InvoiceController
        from seantisinvoice import statusmessage

        # Register route for redirect in invoice form actions
        testing.registerRoute("/", "invoices", factory=None)
        # Create an invoice
        invoice = self._add_invoice()
        request = testing.DummyRequest()
        request.matchdict = dict(invoice=str(invoice.id))
        view = InvoiceController(None, request)
        data = view.form_defaults()
        self.assertEquals(u"Project", data["project_description"])
        # Change some of the invoice date
        data["project_description"] = u"My project"
        data["recurring_term"] = 30
        data["item_list"][0]["service_title"] = u"My service"
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(u"My project", data["project_description"])
        self.assertEquals(u"My service", data["item_list"][0]["service_title"])
        # Add an additional invoice item
        data["item_list"].append(dict(item_id="", service_title=u"Training", service_description=u"", amount=200.0))
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(u"Training", data["item_list"][1]["service_title"])
        # Reorder the items
        data["item_list"][0] = view.form_defaults()["item_list"][1]
        data["item_list"][1] = view.form_defaults()["item_list"][0]
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(u"Training", data["item_list"][0]["service_title"])
        # And remove one of them
        del data["item_list"][0]
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(1, len(data["item_list"]))
        self.assertEquals(u"My service", data["item_list"][0]["service_title"])
        # Submit without changing anything
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        request.matchdict = dict(invoice=str(invoice.id))
        view = InvoiceController(None, request)
        view.handle_submit(data)
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)
Exemplo n.º 13
0
def view_invoices(request):
    session = DBSession()
    query = session.query(Invoice)
    today = datetime.date.today()

    if 'recurring' in request.params:
        if request.params['recurring'] == '1':
            query = query.filter(Invoice.recurring_date != None)
            # We don't show the recurring invoices that have stop date in the past
            query = query.filter(Invoice.recurring_stop >= today
                                 or Invoice.recurring_stop == None)
            title = u'Recurring Invoices'
        elif request.params['recurring'] == '0':
            query = query.filter(Invoice.recurring_date == None)
            title = u'Non-recurring Invoices'
    elif 'due' in request.params and request.params['due'] == '1':
        query = query.filter(Invoice.due_date <= today)
        query = query.filter(Invoice.payment_date == None)
        title = u'Invoices due'
    else:
        title = u'All Invoices'

    # Sorting
    if 'sort' in request.params:
        sort_key = request.params['sort']
        if hasattr(Invoice, sort_key):
            sort_attr = getattr(Invoice, sort_key)
            if 'reverse' in request.params:
                sort_attr = desc(sort_attr)
            query = query.order_by(sort_attr)
    else:
        query = query.order_by(desc(Invoice.date))

    invoices = query.all()
    company = session.query(Company).first()
    main = get_template('templates/master.pt')
    return dict(request=request,
                main=main,
                invoices=invoices,
                company=company,
                title=title,
                msgs=statusmessage.messages(request),
                formatThousands=formatThousands)
Exemplo n.º 14
0
    def test_handle_submit(self):
        from seantisinvoice.views.customer import CustomerController
        from seantisinvoice import statusmessage

        # Register route for redirect in customer form actions
        testing.registerRoute("/customers", "customers", factory=None)
        # Add a customer
        customer = self._add_customer()
        request = testing.DummyRequest()
        request.matchdict = dict(customer=str(customer.id))
        view = CustomerController(None, request)
        # Check default values
        default_values = view.form_defaults()
        self.assertEquals(u"Customers Inc.", default_values["name"])
        # Change the data
        default_values["name"] = u"Seantis GmbH"
        default_values["contact_list"][0]["first_name"] = u"Leopold"
        view.handle_submit(default_values)
        default_values = view.form_defaults()
        self.assertEquals(u"Seantis GmbH", default_values["name"])
        self.assertEquals(u"Leopold", default_values["contact_list"][0]["first_name"])
        # Add an additional contact
        contact_date = dict(first_name=u"Stephen", last_name=u"Dedalus", title=u"Mr.", contact_id="")
        default_values["contact_list"].append(contact_date)
        view.handle_submit(default_values)
        default_values = view.form_defaults()
        self.assertEquals(u"Stephen", default_values["contact_list"][1]["first_name"])
        # Remove one of the contacts
        del default_values["contact_list"][0]
        view.handle_submit(default_values)
        default_values = view.form_defaults()
        self.assertEquals(1, len(default_values["contact_list"]))
        # Contacts are alphabetically ordered.
        self.assertEquals(u"Stephen", default_values["contact_list"][0]["first_name"])
        # Submit without changing anything
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        request.matchdict = dict(customer=str(customer.id))
        view = CustomerController(None, request)
        view.handle_submit(default_values)
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)
Exemplo n.º 15
0
 def __call__(self):            
     
     total_amount = 0
     total_tax = 0
     
     invoices = self.invoices()
     for invoice in invoices:
         total_amount += invoice.grand_total()
         total_tax += invoice.tax_amount()
     
     main = get_template('templates/master.pt')
     return dict(request=self.request,
                 invoices=invoices,
                 main=main,
                 total_amount=total_amount,
                 total_tax=total_tax,
                 from_date=self.from_date,
                 to_date=self.to_date,
                 msgs=statusmessage.messages(self.request),
                 formatThousands=formatThousands)
Exemplo n.º 16
0
def view_invoices(request):
    session = DBSession()
    query = session.query(Invoice)
    today = datetime.date.today()
    
    if 'recurring' in request.params:
        if request.params['recurring'] == '1':
            query = query.filter(Invoice.recurring_date != None)
            # We don't show the recurring invoices that have stop date in the past
            query = query.filter(Invoice.recurring_stop >= today or Invoice.recurring_stop == None) 
            title = u'Recurring Invoices'
        elif request.params['recurring'] == '0':
            query = query.filter(Invoice.recurring_date == None)
            title = u'Non-recurring Invoices'
    elif 'due' in request.params and request.params['due'] == '1':
        query = query.filter(Invoice.due_date <= today)
        query = query.filter(Invoice.payment_date == None)
        title = u'Invoices due'
    else:
        title = u'All Invoices'
        
    # Sorting
    if 'sort' in request.params:
        sort_key = request.params['sort']
        if hasattr(Invoice, sort_key):
            sort_attr = getattr(Invoice, sort_key)
            if 'reverse' in request.params:
                sort_attr = desc(sort_attr)
            query = query.order_by(sort_attr)
    else:
        query = query.order_by(desc(Invoice.date))
        
    invoices = query.all()
    company = session.query(Company).first()
    main = get_template('templates/master.pt')
    return dict(request=request, main=main, invoices=invoices, company=company, 
                title=title, msgs=statusmessage.messages(request), formatThousands=formatThousands)
Exemplo n.º 17
0
def view_customers(request):
    session = DBSession()
    customers = session.query(Customer).order_by(Customer.name).all()
    main = get_template('templates/master.pt')
    return dict(request=request, main=main, customers=customers, msgs=statusmessage.messages(request))
    
Exemplo n.º 18
0
 def __call__(self):
     main = get_template('templates/master.pt')
     return dict(request=self.request,
                 main=main,
                 msgs=statusmessage.messages(self.request))
Exemplo n.º 19
0
 def __call__(self):
     main = get_template('templates/master.pt')
     return dict(request=self.request, main=main, msgs=statusmessage.messages(self.request))
Exemplo n.º 20
0
def view_license(request):
    main = get_template('templates/master.pt')
    return dict(request=request, main=main, msgs=statusmessage.messages(request))
Exemplo n.º 21
0
def view_license(request):
    main = get_template('templates/master.pt')
    return dict(request=request,
                main=main,
                msgs=statusmessage.messages(request))