def get_vat_charge(self): if not self.country: raise VATException(_('Unable to get VAT charge because buyer country code is not specified.')) seller_country = settings.WALDUR_CORE.get('SELLER_COUNTRY_CODE') if not seller_country: raise VATException(_('Unable to get VAT charge because seller country code is not specified.')) return pyvat.get_sale_vat_charge( datetime.date.today(), pyvat.ItemType.generic_electronic_service, pyvat.Party(self.country, self.is_company and self.vat_code), pyvat.Party(seller_country, True) )
def test_get_sale_vat_charge(self): """get_sale_vat_charge(..) """ # EU businesses selling to any type of customer in their own country # charge VAT. for seller_cc in EU_COUNTRY_CODES: for it in SUPPORTED_ITEM_TYPES: for d in [ datetime.date(2014, 12, 15), datetime.date(2015, 1, 1) ]: for buyer_is_business in [True, False]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=seller_cc, is_business=buyer_is_business), Party(country_code=seller_cc, is_business=True)) self.assertEqual(vat_charge.action, VatChargeAction.charge) self.assertEqual(vat_charge.rate, EXPECTED_VAT_RATES[seller_cc][it]) self.assertEqual(vat_charge.country_code, seller_cc) # EU businesses selling to businesses in other EU countries apply the # reverse-charge mechanism. for seller_cc in EU_COUNTRY_CODES: for buyer_cc in EU_COUNTRY_CODES: if seller_cc == buyer_cc: continue for it in SUPPORTED_ITEM_TYPES: for d in [ datetime.date(2014, 12, 15), datetime.date(2015, 1, 1) ]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=buyer_cc, is_business=True), Party(country_code=seller_cc, is_business=True)) self.assertEqual(vat_charge.action, VatChargeAction.reverse_charge) self.assertEqual(vat_charge.rate, Decimal(0)) self.assertEqual(vat_charge.country_code, buyer_cc) # EU businesses selling to consumers in other EU countries charge VAT # in the country in which the consumer resides after January 1st, 2015. for seller_cc in EU_COUNTRY_CODES: for buyer_cc in EU_COUNTRY_CODES: if seller_cc == buyer_cc: continue for it in SUPPORTED_ITEM_TYPES: for d in [ datetime.date(2014, 12, 15), datetime.date(2015, 1, 1) ]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=buyer_cc, is_business=False), Party(country_code=seller_cc, is_business=True)) self.assertEqual(vat_charge.action, VatChargeAction.charge) self.assertEqual( vat_charge.rate, EXPECTED_VAT_RATES[buyer_cc][it] if d >= datetime.date(2015, 1, 1) else EXPECTED_VAT_RATES[seller_cc][it]) self.assertEqual( vat_charge.country_code, buyer_cc if d >= datetime.date(2015, 1, 1) else seller_cc) # EU businesses selling to customers outside the EU do not charge VAT. for seller_cc in EU_COUNTRY_CODES: for buyer_country in pycountry.countries: buyer_cc = buyer_country.alpha_2 if buyer_cc in EU_COUNTRY_CODES: continue for it in SUPPORTED_ITEM_TYPES: for d in [ datetime.date(2014, 12, 15), datetime.date(2015, 1, 1) ]: for buyer_is_business in [True, False]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=buyer_cc, is_business=buyer_is_business), Party(country_code=seller_cc, is_business=True)) self.assertEqual(vat_charge.action, VatChargeAction.no_charge) self.assertEqual(vat_charge.rate, Decimal(0))
def test_get_sale_vat_charge(self): """get_sale_vat_charge(..) """ # EU businesses selling to any type of customer in their own country # charge VAT. for seller_cc in EU_COUNTRY_CODES: for it in SUPPORTED_ITEM_TYPES: for d in [datetime.date(2014, 12, 15), datetime.date(2015, 1, 1)]: for buyer_is_business in [True, False]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=seller_cc, is_business=buyer_is_business), Party(country_code=seller_cc, is_business=True) ) self.assertEqual(vat_charge.action, VatChargeAction.charge) self.assertEqual(vat_charge.rate, EXPECTED_VAT_RATES[seller_cc][it]) self.assertEqual(vat_charge.country_code, seller_cc) # EU businesses selling to businesses in other EU countries apply the # reverse-charge mechanism. for seller_cc in EU_COUNTRY_CODES: for buyer_cc in EU_COUNTRY_CODES: if seller_cc == buyer_cc: continue for it in SUPPORTED_ITEM_TYPES: for d in [datetime.date(2014, 12, 15), datetime.date(2015, 1, 1)]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=buyer_cc, is_business=True), Party(country_code=seller_cc, is_business=True) ) self.assertEqual(vat_charge.action, VatChargeAction.reverse_charge) self.assertEqual(vat_charge.rate, Decimal(0)) self.assertEqual(vat_charge.country_code, buyer_cc) # EU businesses selling to consumers in other EU countries charge VAT # in the country in which the consumer resides after January 1st, 2015. for seller_cc in EU_COUNTRY_CODES: for buyer_cc in EU_COUNTRY_CODES: if seller_cc == buyer_cc: continue for it in SUPPORTED_ITEM_TYPES: for d in [datetime.date(2014, 12, 15), datetime.date(2015, 1, 1)]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=buyer_cc, is_business=False), Party(country_code=seller_cc, is_business=True) ) self.assertEqual(vat_charge.action, VatChargeAction.charge) self.assertEqual( vat_charge.rate, EXPECTED_VAT_RATES[buyer_cc][it] if d >= datetime.date(2015, 1, 1) else EXPECTED_VAT_RATES[seller_cc][it] ) self.assertEqual( vat_charge.country_code, buyer_cc if d >= datetime.date(2015, 1, 1) else seller_cc ) # EU businesses selling to customers outside the EU do not charge VAT. for seller_cc in EU_COUNTRY_CODES: for buyer_country in pycountry.countries: buyer_cc = buyer_country.alpha2 if buyer_cc in EU_COUNTRY_CODES: continue for it in SUPPORTED_ITEM_TYPES: for d in [datetime.date(2014, 12, 15), datetime.date(2015, 1, 1)]: for buyer_is_business in [True, False]: vat_charge = get_sale_vat_charge( d, it, Party(country_code=buyer_cc, is_business=buyer_is_business), Party(country_code=seller_cc, is_business=True) ) self.assertEqual(vat_charge.action, VatChargeAction.no_charge) self.assertEqual(vat_charge.rate, Decimal(0))