[FIX] base_vat: allow disabling VAT check through context
Before this fix there is no real way to influence the VAT validation. This can be problematic though as in some cases external platforms push data to you on which you don't really have control. If an external software pushes an invalid VAT and your database has the option 'Verify VAT Numbers' checked on there is no way for you to bypass this though. This means that before this commit you have to always run VAT number checks on all data, no matter if they come through the frontend or backend. After this commit you can supply a context key 'no_vat_validation' though. This way you could skip doing VAT number validations on (some) records while still enforcing this in the UI. This allows you to have crons/external API's push any VAT number while enforcing full validation through the UI. This opens up the best of both worlds. closes odoo/odoo#80843 X-original-commit: d31bf866e1556327f634e20d6d845d67143e2a06 Signed-off-by: Olivier Colson <oco@odoo.com>
This commit is contained in:
@@ -149,6 +149,11 @@ class ResPartner(models.Model):
|
||||
|
||||
@api.constrains('vat', 'country_id')
|
||||
def check_vat(self):
|
||||
# The context key 'no_vat_validation' allows you to store/set a VAT number without doing validations.
|
||||
# This is for API pushes from external platforms where you have no control over VAT numbers.
|
||||
if self.env.context.get('no_vat_validation'):
|
||||
return
|
||||
|
||||
for partner in self:
|
||||
country = partner.commercial_partner_id.country_id
|
||||
if partner.vat and self._run_vat_test(partner.vat, country, partner.is_company) is False:
|
||||
|
||||
Reference in New Issue
Block a user