Tax rule for a specific country not working as expected

ERPNext V13.30.0.
I’ve set up a sales tax template and a tax rule. The intention is for the rule to apply the tax template ONLY if the shipping address is in the United Kingdom so I have put “United Kingdom” in the “Shipping Country” filter field and left all the other filter fields blank.

When I create a sales invoice, however, no matter what country the shipping address is in, the tax template is always applied.
If I remove the tax rule then the tax template is never applied so I believe it is the tax rule that is responsible and not some other setting.

As far as I can see I have configured the filter according to the documentation:
https://docs.erpnext.com/docs/v13/user/manual/en/accounts/tax-rule

This is my configuration for the tax rule:

With a little bit more experimentation, if I filter on the billing country instead of the shipping country then it does appear to work. So perhaps there is a bug that causes it to ignore the shipping country filter.

Another thing I noticed when using the billing country as a filter is that if I change the customer selected in the invoice a few times I see the following behaviour:

  • Select a non-UK customer - the tax template does not appear in the invoice
  • Select a UK customer - the tax template appears
  • Change back to the non-UK customer - the tax template is still there

So it looks as though once a tax template has been added to the list by the tax rule, it is never removed if the customer is changed. We can live with that since we will almost never change the customer while creating the invoice, except on very rare occasions when the wrong customer was selected initially by accident.

We do need the tax rule to be filtered by shipping address, though, because UK VAT rules depend on the shipping address rather than the billing address. Am I doing something wrong with the shipping country or does it look like I need to report a bug?

There is also one more Tax Setting available in Account Setting.

Thank you. I hadn’t noticed that. I just changed it to “Shipping Address” but it made no difference to the behaviour. I haven’t used tax categories as I don’t think they will achieve what I need (to automatically determine whether or not to apply a tax template depending on the shipping country).

Please have a look here

The addresses of your customers must be added correctly as Shipping Address, you can leave it as default and hide it for when they register.

Thank you.
I eventually got it working but a year later I can’t quite remember how. However, this is probably the solution so I will mark it as such.