base_vat : Skips the vat validation if VAT contains false country code

Bug #567216 reported by Carlos Liebana
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Invalid
Undecided
Unassigned
Trunk
Fix Released
Medium
Unassigned

Bug Description

Hi,

VAT validation is not working correct, at least in the last version 5.0.9, but maybe since 5.0.6. In a clean installation with base vat installed, I can introduce a string like "ttsscff4554" and it's saving the changes. If I change that for "EStts..." it shows the pop-up error. I think that all the strings that don't begin with two country representative characters are saved.

Best regards.

Revision history for this message
Carlos Liebana (carlos-liebana) wrote :
Revision history for this message
Eduard Carreras i Nadal (ecarreras) wrote :

If you see the code in partner.py line 55 of base_vat module, there is a function called default_vat_check, it acts when the two first letters of the vat doesn't match on any check_vat_countyletters function.

def default_vat_check(self, cn, vn):
            # by default, a VAT number is valid if:
            # it starts with 2 letters
            # has more than 3 characters
            return len(vn) > 0 and len(cn) == 2 and cn[0] in string.ascii_lowercase and cn[1] in string.ascii_lowercase

IMHO is better return False than perform this check...

Revision history for this message
Carlos Liebana (carlos-liebana) wrote :

So, by default now the check is only made if the string begins with the two country-representative chars... Is this correct for you?

Changed in openobject-addons:
importance: Undecided → Medium
milestone: none → 5.0.11
status: New → Confirmed
summary: - base_vat is not working right
+ base_vat : Skips the vat validation if VAT contains false country code
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Carlos,

We decided to allow any vat number which doesn't start with a 2 digit country code(non-numerics).
There are situations where we do not have the validation check avalaible for any country in OpenERP, so to allow those VATs which atleast have 2 digit country code and minimum 3 characters as Vat; we skipped the test.

Let us know,if your country's validation check is not available. We would be obliged to have your valuable suggestion.
Hope this helps.

Thanks.

Changed in openobject-addons:
status: Confirmed → Invalid
Revision history for this message
Carlos Liebana (carlos-liebana) wrote :

Hi Jay,

Thanks for your reply, the validations for my country (Spain) is working well. I completely understand your point of view, but for us and I suppose for others, there's another scenario: when the user doesn't introduce the 2 represantive characters of the country of the partner. If so, it could be understood that the VAT is correct (no pop-up displayed and saving is allowed), when maybe is not, and this could suppose future issues with invoices.

So I think, there's two approaches to solve the problem when the VAT number doesn't start with the 2 digits country code:

- Display a message saying that the validation is not being done.
- Or, maybe this is just spanish localization specific, extend the module and make the ES as the default starting characters when there's not known starting characters in the VAT number. So, in my initial example, the string "ttsscff4554" would not be allowed because it would try to validate as "ESttsscff4554", obviously incorrect.

I don't know in other countries, but users are not used to introduce the 2 first representative characters in the VAT number.

What do you think?

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

Carlos, we usually go with the "autocomplete" way for our clients. If they type a VAT without starting characters we just add them using an on_change method:

    def onchange_vat(self, cr, uid, ids, vat):
        """
        Método que comprueba el NIF/CIF y añade el prefijo ES en caso necesario
        """
        if vat:
            if not re.match(r'[a-zA-Z]{2}.+', vat):
                vat = "ES%s" % vat.upper()
            return { 'value': { 'vat': vat, 'vat_subjected': True } }
        return { 'value': { 'vat_subjected': False } }

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

I agree with the pop-up message which notifies the user that the vat has not gone under the validation scanner.
I escalate the bug to be fixed in next version.
Thanks.

Revision history for this message
Carlos Liebana (carlos-liebana) wrote :

Thanks a lot Jay.

Revision history for this message
xrg (xrg) wrote : Re: [Bug 567216] Re: base_vat : Skips the vat validation if VAT contains false country code

On Monday 24 May 2010, you wrote:
> Hello Carlos,
>
> We decided to allow any vat number which doesn't start with a 2 digit
> country code(non-numerics). There are situations where we do not have the
> validation check avalaible for any country in OpenERP, so to allow those
> VATs which atleast have 2 digit country code and minimum 3 characters as
> Vat; we skipped the test.

I think I have a more politically correct solution:
Introduce a "VAT code" field in res.countries

Then, if the VAT code doesn't start with letters, try to get the number from
the address.country_id /or/ the main company and append that..
Then, validate.

I think this will be better than hard-coding a country or not validating the
VAT string.

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

+1 to xrg idea.

Having info on res.countries about what VAT letters for that country are, that is; and (I would add) whether we want to validate codes for that country.

End users usually don't even care about the country letters, they just want to write the code itself (after all most of the customers will be from the same country as the company). With xrg proposal we would cover this 'lazy user' case.

Revision history for this message
Carlos Liebana (carlos-liebana) wrote :

Same opinion than Borja and xrg.

Revision history for this message
xrg (xrg) wrote :

On Monday 24 May 2010, you wrote:
> [Bug 567216]
>
Fixed in my branch.

Revision history for this message
Dhruti Shastri(OpenERP) (dhs-openerp) wrote :

This has been fixed in the trunk version.
Thank you.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.