OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
869 stars 436 forks source link

Add Northern Ireland (after Brexit) as independent selectable Country #1486

Open AlterWeb opened 3 years ago

AlterWeb commented 3 years ago

Description (*)

Northern Ireland has special rules sins the Brexit. For what I understand, it is like for some tax rules they still belong to the EU and are not part of the UK. They got there own vat number starting with XI. For goods delivered to or from Europe they should not calculate or pay tax. This is not possible as of now in OpenMage because they belong to the UK.

So I think we should add Northern Ireland as an extra country to OpenMage. In that way we can apply different tax rules for it and add it to the list of European countries.

Before I will create the code for this in a pull request I have to say I'm not an tax expert and I don't want to break something or add other unexpected behavior. So if anyone can verify that adding a extra country is indeed the right thing to do then I will do so.

For more info see: https://www.avalara.com/vatlive/en/vat-news/brexit-northern-ireland-vat-and-eoro--xi--number.html

Expected behavior (*)

Companies from Northern Ireland buying in the EU with a valid XI vat number should not pay tax to the European store.

Benefits

The right tax rules could be applied.

Also other business rules could be implemented based on the customer's location. For example because they need a phytosanitary certificate in England but not in Northern Ireland.

Additional information

jfksk commented 3 years ago

I'm also not an expert on this matter but I'd like add how I understand it:

VAT/Customs: NI <-> EU: intra community (for goods) NI <-> GB: domestic EU <-> GB: customs (also EU <-> GB via NI)

NI has a new EU VAT ID: XI. This VAT ID can be validated in VIES. So NI stays in the EU customs union and the EU VAT system for the trade of goods. Normal rules apply. The VAT depends on the merchant and the merchant-customer-relationship (B2B with optional reverse charge or B2C (from July OSS, limit rule or direct)). However, AFAIK this does not apply to digital services. Digital services sold to consumers in NI are taxable in the UK and not in the EU (OSS for e.g.) The destination country principle applies. Off the top of my head, I don't see any problem with that.

The UK VAT ID (GB) does not have any meaning in the EU anymore, but I dont know about NI <-> GB trade. However, we do not have a validator for it - not anymore. So it doesn't matter... Customs rules apply for the trade of goods EU <-> GB. The new EORI (XU) is IMHO not of concern for OpenMage as EORI numbers aren't a feature, yet.

The basic B2C setup could probably be done by adding NI as a subdivision of the UK but the VIES validation would need to be adapted (actually quiet a bit) because its currently on country level.

On the other hand, I think it would almost just work if NI would be added as country and configured as EU country (or would there be any downside to do it?). BTW: the assumption in Magento that all EU VAT IDs are prefixed with the country code is wrong. So it also doesn't matter if its NI, XI... It probably needs to be fixed sometime somehow anyway. For Greece its EL and not GR. Of course, we could also completely ignore VIES for NI, but why...

Bottom line, I also think that adding NI as a country is probably the better option. VIES is somehow optional and could be added now or later.

AlterWeb commented 3 years ago

@jfksk Thank you for your input. Maybe I should have mentioned that I already tried to add Northern Ireland the quick and dirty way. Just to test how that would work. If we decide to go with the route of adding Northern Ireland as an country with the iso code XI, the VIES system is already working like it should (NI isn't an option anyway because it is already in use for Nicaragua). So no need to change anything there.

I also think the VIES validation could use some improvements but that would be outside of the scope of this issue.

jfksk commented 3 years ago

@AlterWeb

If we decide to go with the route of adding Northern Ireland as an country with the iso code XI, the VIES system is already working like it should (NI isn't an option anyway because it is already in use for Nicaragua). So no need to change anything there.

Nice that's great. Yes that was a stupid example from me. Anyway, giving it a second thought, there are also many other non-ISO codes and there is simply no 2 letter ISO code for Northern Ireland. So XI might actually be the best choice in that case.

Are there any obligations with configuring it as EU country (for VIES), maybe from an UK perspective?

I also think the VIES validation could use some improvements but that would be outside of the scope of this issue.

I agree. But I think its good to keep that in mind to not introduce more problems down the road. I should had have added that in the first place. But as I understood you, there aren't any new ones and, as it is, none with NI :smiley:

kiatng commented 3 years ago

Adding Northern Ireland as a separate country in the table directory_country may cause problems for some use cases, it could be a very senstive subject (such as Taiwan and Hong Kong for the Chinese government). For me, I had made some visas related API to immigration authority based on user's country input, it'll be a problem for users who select Northern Ireland, as the dropdown is based on directory_country.

AlterWeb commented 3 years ago

@jfksk

Yes that was a stupid example from me.

That wasn't a stupid example. The only way I knew NI was already taken was because I did the test earlier that day. We can't know everything ;-).

Are there any obligations with configuring it as EU country (for VIES), maybe from an UK perspective?

Not that I know of. But once again, I'm not an expert on that.

@kiatng

Thank you for your input. This is the whole reason I first wanted to ask more people before making a change.

it could be a very senstive subject (such as Taiwan and Hong Kong for the Chinese government)

I never thought of that. I'm not sure if this could be a sensitive issue for Northern Ireland or the UK. On the other hand, should we not add a country based on political issues? I know Wikipedia is not the best source but it says Northern Ireland is a country. And if someone does not like Northern Ireland to be a separate country they can just not select it in the allowed country list in the system configuration and everything will be back to how it was I think. Or we could just not select it by default.

For me, I had made some visas related API to immigration authority based on user's country input, it'll be a problem for users who select Northern Ireland, as the dropdown is based on directory_country.

Would that also be a problem if Northern Ireland was not by default selected as an allowed country?

We could also make it configurable of course. So that the shop owners could decide for themselves if in there use case Northern Ireland should be seen as an separate country or not.

AlterWeb commented 3 years ago

Also I forgot to mention that there are some other business rules that a customer of ours mentioned that are based on whether the shop customer is located in Northern Ireland or not.

For example, in England they need an phytosanitary certificate for importing plant and/or animal based products since the brexit. That is not the case for Northern Ireland. This makes the cost for sending those products to England a lot higher than to Northern Ireland.

rvelhote commented 3 years ago

Doing this would possibly have implications with payment methods and shipping methods as they might not accept the XI as a country code. Of course you can always monkey wrench XI to GB in the code but still something to consider potential wider implications.

We faced this issue trying to add Kosovo XK to the list of countries (in the end we decided we wouldn't proceed with the change for now). Adding the country to the directory is easy but the side-effects might be tricky.

At this moment we are dealing with Northern Ireland by checking the postal code and using it as a deciding factor when issuing invoices, shipping, export statements etc.

AlterWeb commented 3 years ago

@rvelhote Thank you for your input.

This looks like it's a bigger issue than I thought.

For Northern Ireland we could change the VIES check functionality I guess. If I'm not wrong Mage_Customer_Helper_Data::checkVatNumber() is responsible for this. This functionality is used in three different locations in the code:

Mage_Adminhtml_Customer_System_Config_ValidatevatController:_validate() Mage_Customer_Model_Observer::afterAddressSave() Mage_Sales_Model_Observer::changeQuoteCustomerGroupId()

Only the first of those doesn't have access to the postal code. This code is responsible to check the VAT number filled in System Configuration. We could add a extra field there if GB is selected to also enter a postcode. In that case we also have the needed information over there.

If we then add an extra optional parameter to the end of Mage_Customer_Helper_Data::checkVatNumber($countryCode, $vatNumber, $requesterCountryCode = '', $requesterVatNumber = '', $postcode = null) we can check it for starting with BT followed with 1 or 2 digits when the country code is GB and submit the VIES request with XI if so. All external / third party code that uses this helper function should still work like it should now then.

For other business rules like a discount on shipping we could use shopping cart price rules. It is not pretty but if I'm right you can check if the postcode contains BT1,BT2,BT3,...,BT8 or BT9 when the country is GB to know for sure if it's in Northern Ireland.

convenient commented 3 years ago

but if I'm right you can check if the postcode contains BT1,BT2,BT3,...,BT8 or BT9 when the country is GB to know for sure if it's in Northern Ireland.

Yeah the "Belfast" post code actually covers the entirety of Northern Ireland.

twosg commented 3 years ago

If Nothern Ireland is being added as an own country entity, it should be done with "XI" as country code. "NI" is already blocked and VIES supports "XI".

AlterWeb commented 3 years ago

My conclusion was to not add Northern Ireland as a country because there was to much depending on this. Instead I improved the VAT number validation (VIES) and added the possibility to validate Northern Ireland based on postcode (see pull request #1503). I also changed the logic of the table rate shipping module to also handle postcodes for Northern Ireland (see pull request #1504). Those two pull request are ready for reviewing.

addison74 commented 1 year ago

There is an open PR related to this issue. If Northern Ireland needs to be added it is the right place.