Beispiel #1
0
 def test_grand_total(self):
     from seantisinvoice.models import Customer
     from seantisinvoice.models import CustomerContact
     from seantisinvoice.models import Invoice
     from seantisinvoice.models import InvoiceItem
     # Customer
     contact = CustomerContact()
     contact.customer = Customer()
     # Invoice
     invoice = Invoice()
     invoice.contact = contact
     self.assertEquals(0, invoice.grand_total())
     item = InvoiceItem()
     item.amount = 100.0
     invoice.items.append(item)
     self.assertEquals(Decimal('100.00'), invoice.grand_total())
     invoice.tax = 7.6
     self.assertEquals(Decimal('107.60'), invoice.grand_total())
     item = InvoiceItem()
     item.amount = 60.0
     invoice.items.append(item)
     # Value is rounded
     self.assertEquals(Decimal('172.15'), invoice.grand_total())
     invoice.tax = None
     self.assertEquals(Decimal('160.00'), invoice.grand_total())
Beispiel #2
0
    def test_grand_total(self):
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import InvoiceItem

        # Customer
        contact = CustomerContact()
        contact.customer = Customer()
        # Invoice
        invoice = Invoice()
        invoice.contact = contact
        self.assertEquals(0, invoice.grand_total())
        item = InvoiceItem()
        item.amount = 100.0
        invoice.items.append(item)
        self.assertEquals(Decimal("100.00"), invoice.grand_total())
        invoice.tax = 7.6
        self.assertEquals(Decimal("107.60"), invoice.grand_total())
        item = InvoiceItem()
        item.amount = 60.0
        invoice.items.append(item)
        # Value is rounded
        self.assertEquals(Decimal("172.15"), invoice.grand_total())
        invoice.tax = None
        self.assertEquals(Decimal("160.00"), invoice.grand_total())
Beispiel #3
0
    def test_total(self):
        from seantisinvoice.models import Company
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import InvoiceItem

        company = Company()
        # Customer
        customer = Customer()
        contact = CustomerContact()
        contact.customer = customer
        # Invoice
        invoice = Invoice()
        invoice.company = company
        invoice.contact = contact

        item = InvoiceItem()
        item.invoice = invoice
        item.amount = 3000.0
        self.assertEquals(3000.0, item.total())
        # Hourly rate is defined on the company
        company.hourly_rate = 120.0
        item = InvoiceItem()
        item.invoice = invoice
        item.hours = 13
        self.assertEquals(1560.0, item.total())
        # Daily rate is also defined on the company
        company.daily_rate = 1300.0
        item = InvoiceItem()
        item.invoice = invoice
        item.days = 2.5
        self.assertEquals(3250.0, item.total())
        # Special daily rate on customer
        customer.special_daily_rate = 1100.0
        item = InvoiceItem()
        item.invoice = invoice
        item.days = 4.5
        self.assertEquals(4950.0, item.total())
        # Special hourly rate on customer
        customer.special_hourly_rate = 100.0
        item = InvoiceItem()
        item.invoice = invoice
        item.hours = 10
        self.assertEquals(1000.0, item.total())
Beispiel #4
0
    def test_total(self):
        from seantisinvoice.models import Company
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import InvoiceItem

        company = Company()
        # Customer
        customer = Customer()
        contact = CustomerContact()
        contact.customer = customer
        # Invoice
        invoice = Invoice()
        invoice.company = company
        invoice.contact = contact

        item = InvoiceItem()
        item.invoice = invoice
        item.amount = 3000.0
        self.assertEquals(3000.0, item.total())
        # Hourly rate is defined on the company
        company.hourly_rate = 120.0
        item = InvoiceItem()
        item.invoice = invoice
        item.hours = 13
        self.assertEquals(1560.0, item.total())
        # Daily rate is also defined on the company
        company.daily_rate = 1300.0
        item = InvoiceItem()
        item.invoice = invoice
        item.days = 2.5
        self.assertEquals(3250.0, item.total())
        # Special daily rate on customer
        customer.special_daily_rate = 1100.0
        item = InvoiceItem()
        item.invoice = invoice
        item.days = 4.5
        self.assertEquals(4950.0, item.total())
        # Special hourly rate on customer
        customer.special_hourly_rate = 100.0
        item = InvoiceItem()
        item.invoice = invoice
        item.hours = 10
        self.assertEquals(1000.0, item.total())
Beispiel #5
0
 def test_sub_total(self):
     from seantisinvoice.models import Customer
     from seantisinvoice.models import CustomerContact
     from seantisinvoice.models import Invoice
     from seantisinvoice.models import InvoiceItem
     # Customer
     contact = CustomerContact()
     contact.customer = Customer()
     # Invoice
     invoice = Invoice()
     invoice.contact = contact
     item = InvoiceItem()
     item.amount = 1250.50
     invoice.items.append(item)
     self.assertEquals(1250.5, invoice.sub_total())
     item = InvoiceItem()
     item.amount = 120.0
     invoice.items.append(item)
     self.assertEquals(1370.5, invoice.sub_total())
Beispiel #6
0
    def test_tax_amount(self):
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import InvoiceItem
        # Customer
        contact = CustomerContact()
        contact.customer = Customer()
        # Invoice
        invoice = Invoice()
        invoice.contact = contact

        self.assertEquals(0, invoice.tax_amount())
        invoice.tax = 7.6
        self.assertEquals(0, invoice.tax_amount())
        item = InvoiceItem()
        item.amount = 100.0
        invoice.items.append(item)
        self.assertEquals(7.6, invoice.tax_amount())
Beispiel #7
0
    def test_sub_total(self):
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import InvoiceItem

        # Customer
        contact = CustomerContact()
        contact.customer = Customer()
        # Invoice
        invoice = Invoice()
        invoice.contact = contact
        item = InvoiceItem()
        item.amount = 1250.50
        invoice.items.append(item)
        self.assertEquals(1250.5, invoice.sub_total())
        item = InvoiceItem()
        item.amount = 120.0
        invoice.items.append(item)
        self.assertEquals(1370.5, invoice.sub_total())
Beispiel #8
0
    def test_tax_amount(self):
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import InvoiceItem

        # Customer
        contact = CustomerContact()
        contact.customer = Customer()
        # Invoice
        invoice = Invoice()
        invoice.contact = contact

        self.assertEquals(0, invoice.tax_amount())
        invoice.tax = 7.6
        self.assertEquals(0, invoice.tax_amount())
        item = InvoiceItem()
        item.amount = 100.0
        invoice.items.append(item)
        self.assertEquals(7.6, invoice.tax_amount())
Beispiel #9
0
    def _add_customer(self):
        from seantisinvoice.models import Customer
        from seantisinvoice.models import CustomerContact
        from seantisinvoice.models import DBSession

        session = DBSession()
        customer = Customer()
        customer.name = u"Customers Inc."
        customer.address1 = u"Street"
        customer.postal_code = u"12234"
        customer.city = u"Dublin"
        session.add(customer)
        # Each customer needs at least one contact
        contact = CustomerContact()
        contact.first_name = u"Buck"
        contact.last_name = u"Mulligan"
        contact.title = u"Mr."
        contact.customer = customer
        session.add(contact)
        session.flush()
        return customer
Beispiel #10
0
 def _apply_data(self, customer, converted):
     changed = False
     session = DBSession()
     # Apply schema fields to the customer object
     field_names = [ p.key for p in class_mapper(Customer).iterate_properties ]
     for field_name in field_names:
         if field_name in converted.keys():
             if getattr(customer, field_name) != converted[field_name]:
                 setattr(customer, field_name, converted[field_name])
                 changed = True
         
     # Apply data of the contact subforms
     contact_map = {}
     for contact in customer.contacts:
         contact_map[contact.id] = contact
     for contact_data in converted['contact_list']:
         if contact_data['contact_id']:
             contact_id = contact_data['contact_id']
             contact = contact_map[contact_id]
             del contact_map[contact_id]
         else:
             contact = CustomerContact()
             contact.customer = customer
             session.add(contact)
             changed = True
         # Apply schema fields to the customer contact object
         field_names = [ p.key for p in class_mapper(CustomerContact).iterate_properties ]
         for field_name in field_names:
             if field_name in contact_data.keys():
                 if getattr(contact, field_name) != contact_data[field_name]:
                     setattr(contact, field_name, contact_data[field_name])
                     changed = True
     # Remove contact items that have been removed in the form
     for contact in contact_map.values():
         # FIXME: what happens to existing invoices that loose their contact?
         customer.contacts.remove(contact)
         changed = True
         
     return changed
Beispiel #11
0
 def _add_customer(self):
     from seantisinvoice.models import Customer
     from seantisinvoice.models import CustomerContact
     from seantisinvoice.models import DBSession
     session = DBSession()
     customer = Customer()
     customer.name = u'Customers Inc.'
     customer.address1 = u'Street'
     customer.postal_code = u'12234'
     customer.city = u'Dublin'
     session.add(customer)
     # Each customer needs at least one contact
     contact = CustomerContact()
     contact.first_name = u'Buck'
     contact.last_name = u'Mulligan'
     contact.title = u'Mr.'
     contact.customer = customer
     session.add(contact)
     session.flush()
     return customer