def test_invalid_submission(self):
        basket = Mock()
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = 'ATU66688999'

        submission = { 'basket': basket,
                       'shipping_address': address }

        expected_rate = D('0.20')

        with self.assertRaises(vat.VATAssessmentException):
            result_rate = vat.lookup_vat_for_submission(submission)

        address.vatin = 'ATU66688202'
        address.line1 = 'hastexo'
        with self.assertRaises(vat.VATAssessmentException):
            result_rate = vat.lookup_vat_for_submission(submission)

        address.vatin = ''
        address.line1 = 'hastexo Professional Services GmbH'
        address.phone_number = '+49 9 999 9999'
        with self.assertRaises(vat.VATAssessmentException):
            result_rate = vat.lookup_vat_for_submission(submission)
    def test_valid_user_noreverse_charge(self):
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''

        request = Mock()
        request.user = Mock()
        request.user.addresses = Mock()
        request.user.addresses.order_by = Mock(return_value=[address])
        request.user.is_authenticated = Mock(return_value=True)

        selector = PerUserVATSelector()
        strategy = selector.strategy(request=request)

        result_rate = strategy.get_rate(None, None)
        self.assertEqual(result_rate,
                         D('0.20'))

        address.vatin = 'ATU66688202'
        # Valid VATIN, but same country as store: should return normal
        # VAT rate.
        result_rate = strategy.get_rate(None, None)
        self.assertEqual(result_rate,
                         D('0.20'))
    def test_basket_with_vatin_reverse_charge(self):
        basket = Mock()
        line = Mock()
        line.line_price_excl_tax_incl_discounts = D('100.00')
        line.purchase_info = Mock()
        line.purchase_info.price = Mock()
        line.quantity = 1
        basket.all_lines = Mock(return_value=[line])
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = 'ATU66688202'
        shipping_charge = Mock()
        shipping_charge.excl_tax = D('10.00')

        submission = { 'basket': basket,
                       'shipping_address': address,
                       'shipping_charge': shipping_charge }

        # We're pretending we're a store in Germany. Then we can do
        # reverse charge.
        vat.apply_to(submission)
        self.assertEqual(shipping_charge.tax, D('0.00'))
        self.assertEqual(line.purchase_info.price.tax, D('0.00'))
    def test_basket_with_vatin_no_reverse_charge(self):
        basket = Mock()
        line = Mock()
        line.line_price_excl_tax_incl_discounts = D('100.00')
        line.purchase_info = Mock()
        line.purchase_info.price = Mock()
        line.quantity = 1
        basket.all_lines = Mock(return_value=[line])
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = 'ATU66688202'
        shipping_charge = Mock()
        shipping_charge.excl_tax = D('10.00')

        submission = { 'basket': basket,
                       'shipping_address': address,
                       'shipping_charge': shipping_charge }

        # Even if they've given us a VATIN, if they're in the same
        # country as the store, VAT still applies.
        vat.apply_to(submission)
        self.assertEqual(shipping_charge.tax, D('2.00'))
        self.assertEqual(line.purchase_info.price.tax, D('20.00'))
    def test_basket_with_tax(self):
        basket = Mock()
        line = Mock()
        line.line_price_excl_tax_incl_discounts = D('100.00')
        line.purchase_info = Mock()
        line.purchase_info.price = Mock()
        line.quantity = 1
        basket.all_lines = Mock(return_value=[line])
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.vatin = ''
        shipping_charge = Mock()
        shipping_charge.excl_tax = D('10.00')

        submission = { 'basket': basket,
                       'shipping_address': address,
                       'shipping_charge': shipping_charge }

        vat.apply_to(submission)
        self.assertEqual(shipping_charge.tax, D('2.00'))
        self.assertEqual(line.purchase_info.price.tax, D('20.00'))
    def test_valid_submission_reverse_charge(self):
        basket = Mock()
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''

        submission = { 'basket': basket,
                       'shipping_address': address }

        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.20'))

        # We're pretending we're a store in Germany. Then we can do
        # reverse charge.
        address.vatin = 'ATU66688202'
        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.00'))
        # However, if we're using an empty VATIN, the regular VAT
        # rate applies again.
        address.vatin = ''
        address.line1 = 'HASTEXO PROFESSIONAL SERVICES GMBH'
        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.20'))
Example #7
0
    def test_valid_submission(self):
        basket = Mock()
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''

        submission = { 'basket': basket,
                       'shipping_address': address }

        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.20'))

        address.vatin = 'ATU66688202'
        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.00'))

        address.vatin = ''
        address.line1 = 'HASTEXO PROFESSIONAL SERVICES GMBH'
        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.20'))
Example #8
0
 def test_str(self):
     mock_guest = Mock(spec=Guest)
     mock_guest.name = "Test Guest"
     mock_guest.number_of_guests = 1
     mock_guest.phone_number = "+13101231235"
     self.assertEqual(Guest.__str__(mock_guest),
                      'Guest: {0} (Party of {1})'.format(mock_guest.name, mock_guest.number_of_guests)
                      )
    def test_invalid_user(self):
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+49 911 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''
        user = Mock()
        user.addresses = Mock()
        user.addresses.order_by = Mock(return_value=[address])

        with self.assertRaises(vat.VATAssessmentException):
            result_rate = vat.lookup_vat_for_user(user)

        address.vatin = 'ATU66688999'
        with self.assertRaises(vat.VATAssessmentException):
            result_rate = vat.lookup_vat_for_user(user)
Example #10
0
    def test_valid_user(self):
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''
        user = Mock()
        user.addresses = Mock()
        user.addresses.order_by = Mock(return_value=[address])

        result_rate = vat.lookup_vat_for_user(user)
        self.assertEqual(result_rate,
                         D('0.20'))

        address.vatin = 'ATU66688202'
        result_rate = vat.lookup_vat_for_user(user)
        self.assertEqual(result_rate,
                         D('0.00'))
Example #11
0
    def test_valid_user_reverse_charge(self):
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''
        user = Mock()
        user.addresses = Mock()
        user.addresses.order_by = Mock(return_value=[address])

        # No VATIN, different country? Standard rate applies.
        result_rate = vat.lookup_vat_for_user(user)
        self.assertEqual(result_rate,
                         D('0.20'))

        # Valid VATIN, different country? Reverse charge applies.
        address.vatin = 'ATU66688202'
        result_rate = vat.lookup_vat_for_user(user)
        self.assertEqual(result_rate,
                           D('0.00'))
Example #12
0
    def test_valid_submission_no_reverse_charge(self):
        basket = Mock()
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''

        submission = { 'basket': basket,
                       'shipping_address': address }

        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.20'))

        # Do they have a VATIN? Doesn't matter if they're in the same
        # country as the store; VAT still applies.
        address.vatin = 'ATU66688202'
        result_rate = vat.lookup_vat_for_submission(submission)
        self.assertEqual(result_rate,
                         D('0.20'))
Example #13
0
    def test_valid_user_no_reverse_charge(self):
        address = Mock()
        address.country = Mock()
        address.country.code = 'AT'
        address.line4 = 'Vienna'
        address.postcode = '1010'
        address.phone_number = '+43 1 234 5678'
        address.line1 = 'hastexo Professional Services GmbH'
        address.vatin = ''
        user = Mock()
        user.addresses = Mock()
        user.addresses.order_by = Mock(return_value=[address])

        # No VATIN? Standard rate applies.
        result_rate = vat.lookup_vat_for_user(user)
        self.assertEqual(result_rate,
                         D('0.20'))

        # Do they have a VATIN? Doesn't matter if they're in the same
        # country as the store; VAT still applies.
        address.vatin = 'ATU66688202'
        result_rate = vat.lookup_vat_for_user(user)
        self.assertEqual(result_rate,
                         D('0.20'))