odoo/odoo · error · ValidationError
The country of the foreign VAT number could not be detected.
Error message
The country of the foreign VAT number could not be detected. Please assign a country to the fiscal position.
What it means
Constraint on account.fiscal.position: when foreign_vat is set, country_id must be filled — the VAT number's country cannot be auto-detected from the number alone in this flow, so the fiscal position must state it. Raised from _validate_foreign_vat_country on create/write.
Source
Thrown at addons/account/models/partner.py:123
position.tax_map = dict(tax_map)
@api.depends('account_ids.account_src_id', 'account_ids.account_dest_id')
def _compute_account_map(self):
for position in self:
position.account_map = {al.account_src_id.id: al.account_dest_id.id for al in position.account_ids}
@api.constrains('zip_from', 'zip_to')
def _check_zip(self):
for position in self:
if bool(position.zip_from) != bool(position.zip_to) or position.zip_from > position.zip_to:
raise ValidationError(_('Invalid "Zip Range", You have to configure both "From" and "To" values for the zip range and "To" should be greater than "From".'))
@api.constrains('country_id', 'country_group_id', 'state_ids', 'foreign_vat')
def _validate_foreign_vat_country(self):
for record in self:
if record.foreign_vat:
if not record.country_id:
raise ValidationError(_("The country of the foreign VAT number could not be detected. Please assign a country to the fiscal position."))
if record.country_id == record.company_id.account_fiscal_country_id:
if not record.state_ids:
if record.company_id.account_fiscal_country_id.state_ids:
raise ValidationError(_("You cannot create a fiscal position with a foreign VAT within your fiscal country without assigning it a state."))
if record.country_group_id and record.country_id:
if record.country_id not in record.country_group_id.country_ids:
raise ValidationError(_("You cannot create a fiscal position with a country outside of the selected country group."))
similar_fpos_count = self.env['account.fiscal.position'].search_count([
*self.env['account.fiscal.position']._check_company_domain(record.company_id),
('foreign_vat', 'not in', (False, record.foreign_vat)),
('id', '!=', record.id),
('country_id', '=', record.country_id.id),
])
if similar_fpos_count:
raise ValidationError(_("A fiscal position with a foreign VAT already exists in this country."))
@api.onchange('country_id', 'foreign_vat')View on GitHub (pinned to 1e661df964)
Solutions
- Set the country matching the foreign VAT number on the fiscal position.
- Or derive it in scripts from the VAT prefix (first two letters) before create().
- Leave foreign_vat empty if the position is not a fiscal-representation position.
Example fix
# before
env['account.fiscal.position'].create({'name': 'DE VAT', 'foreign_vat': 'DE123456789'}) # ValidationError
# after
env['account.fiscal.position'].create({
'name': 'DE VAT', 'foreign_vat': 'DE123456789',
'country_id': env.ref('base.de').id,
}) Defensive patterns
Strategy: validation
Validate before calling
def fpos_country_ok(vals):
return not vals.get('foreign_vat') or vals.get('country_id') Prevention
- Derive country from the VAT prefix when importing.
- Make country mandatory on the fiscal position form when foreign_vat is filled.
When it happens
Trigger: create()/write() on account.fiscal.position with foreign_vat set and country_id empty (and no detectable country via country_group_id); e.g. creating an EU fiscal position for a foreign VAT registration without picking the country.
Common situations: VAT-identification setup for foreign subsidiaries; import of fiscal positions where the country column is missing; users expecting the VAT number prefix (e.g. 'BE0123...') to auto-set the country.
Related errors
- You cannot create a fiscal position with a foreign VAT withi
- You cannot create a fiscal position with a country outside o
- This entry contains taxes that are not compatible with your
- Invalid "Zip Range", You have to configure both "From" and "
- A fiscal position with a foreign VAT already exists in this
AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15).
Data as JSON: /api/errors/2264be418a06590b.
Report an issue: GitHub.