Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 1, 2025

This PR implements region-based VAT rates for Spain as requested in the issue. Spanish regions Ceuta, Las Palmas, Tenerife, and Melilla now have 0% VAT rate, while other regions maintain the standard 21% rate.

Changes Made

Core Implementation

  • Extended Party class with optional region_code parameter for backward compatibility
  • Enhanced EsVatRules to handle regional VAT calculations:
    • 0% VAT for special regions: Ceuta (CE), Las Palmas (GC), Tenerife (TF), Melilla (ML)
    • 21% VAT for all other Spanish regions (4% for ebooks in non-special regions)
    • Updated both get_sale_to_country_vat_charge and get_sale_from_country_vat_charge methods

Usage Examples

from pyvat import get_sale_vat_charge, ItemType, Party
import datetime

# Standard Spain (21% VAT)
buyer = Party('ES', False)
seller = Party('DE', True)
vat_charge = get_sale_vat_charge(
    datetime.date(2024, 1, 1),
    ItemType.generic_electronic_service,
    buyer, seller
)
print(vat_charge.rate)  # 21

# Spain with Tenerife region (0% VAT)
buyer = Party('ES', False, 'TF')
vat_charge = get_sale_vat_charge(
    datetime.date(2024, 1, 1),
    ItemType.generic_electronic_service,
    buyer, seller
)
print(vat_charge.rate)  # 0

Testing

  • Added comprehensive test suite in tests/test_spanish_regions.py
  • 8 new test cases covering all scenarios:
    • Special regions (CE, GC, TF, ML) return 0% VAT
    • Regular regions return standard Spanish VAT rates
    • Ebooks in special regions return 0% VAT (overriding the usual 4% rate)
    • Domestic and cross-border transactions work correctly
    • Backward compatibility maintained

Backward Compatibility

Fully backward compatible - existing code continues to work unchanged:

  • Party('ES', False) still works as before (21% VAT)
  • All existing VAT calculations remain unaffected
  • Region code is optional and defaults to None

Key Features

  • Only Spain has region-specific VAT rates (as requested)
  • Special regions (Ceuta, Las Palmas, Tenerife, Melilla) have 0% VAT
  • All other regions maintain standard Spanish VAT rates
  • Ebooks follow the same regional rules (0% in special regions, 4% elsewhere)

Fixes #5.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • ec.europa.eu
    • Triggering command: python -m unittest discover tests -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] VAT rates for regions (country states) Add region-based VAT rates support for Spain Jul 1, 2025
@Copilot Copilot AI requested a review from nicomollet July 1, 2025 09:32
Copilot finished work on behalf of nicomollet July 1, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VAT rates for regions (country states)
2 participants