{"record":{"id":"2264be418a06590b","repo":"odoo/odoo","slug":"the-country-of-the-foreign-vat-number-could-not-be","errorCode":null,"errorMessage":"The country of the foreign VAT number could not be detected. Please assign a country to the fiscal position.","messagePattern":"The country of the foreign VAT number could not be detected\\. Please assign a country to the fiscal position\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"addons/account/models/partner.py","lineNumber":123,"sourceCode":"            position.tax_map = dict(tax_map)\n\n    @api.depends('account_ids.account_src_id', 'account_ids.account_dest_id')\n    def _compute_account_map(self):\n        for position in self:\n            position.account_map = {al.account_src_id.id: al.account_dest_id.id for al in position.account_ids}\n\n    @api.constrains('zip_from', 'zip_to')\n    def _check_zip(self):\n        for position in self:\n            if bool(position.zip_from) != bool(position.zip_to) or position.zip_from > position.zip_to:\n                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\".'))\n\n    @api.constrains('country_id', 'country_group_id', 'state_ids', 'foreign_vat')\n    def _validate_foreign_vat_country(self):\n        for record in self:\n            if record.foreign_vat:\n                if not record.country_id:\n                    raise ValidationError(_(\"The country of the foreign VAT number could not be detected. Please assign a country to the fiscal position.\"))\n                if record.country_id == record.company_id.account_fiscal_country_id:\n                    if not record.state_ids:\n                        if record.company_id.account_fiscal_country_id.state_ids:\n                            raise ValidationError(_(\"You cannot create a fiscal position with a foreign VAT within your fiscal country without assigning it a state.\"))\n                if record.country_group_id and record.country_id:\n                    if record.country_id not in record.country_group_id.country_ids:\n                        raise ValidationError(_(\"You cannot create a fiscal position with a country outside of the selected country group.\"))\n\n                similar_fpos_count = self.env['account.fiscal.position'].search_count([\n                    *self.env['account.fiscal.position']._check_company_domain(record.company_id),\n                    ('foreign_vat', 'not in', (False, record.foreign_vat)),\n                    ('id', '!=', record.id),\n                    ('country_id', '=', record.country_id.id),\n                ])\n                if similar_fpos_count:\n                    raise ValidationError(_(\"A fiscal position with a foreign VAT already exists in this country.\"))\n\n    @api.onchange('country_id', 'foreign_vat')","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/odoo/odoo/blob/1e661df964b1b264c9cef3ab28430d4785be3fda/addons/account/models/partner.py#L105-L141","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nenv['account.fiscal.position'].create({'name': 'DE VAT', 'foreign_vat': 'DE123456789'})  # ValidationError\n\n# after\nenv['account.fiscal.position'].create({\n    'name': 'DE VAT', 'foreign_vat': 'DE123456789',\n    'country_id': env.ref('base.de').id,\n})","handlingStrategy":"validation","validationCode":"def fpos_country_ok(vals):\n    return not vals.get('foreign_vat') or vals.get('country_id')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive country from the VAT prefix when importing.","Make country mandatory on the fiscal position form when foreign_vat is filled."],"tags":["odoo","accounting","fiscal-position","vat","validation"],"backgroundTag":null,"analyzedSha":"1e661df964b1b264c9cef3ab28430d4785be3fda","analyzedAt":"2026-08-15T05:22:16.142Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}