Se rendre au contenu
Menu
Cette question a été signalée

Odoo.sh 14

When committing to a development branch, the Odoo Test Suite is failing the TestFormCreate.test_create_res_partner because of a constraint I added to check to make sure a custom field ('ssn') was in either SSN or EIN format.

I don't know how this test is testing this field.  Is there any way to exclude this constraint from the test?  What's the best practice here?


class Custom(models.Model):
_inherit = "res.partner"

ssn = fields.Char(string='Social Security # / EIN', size=11)

@api.constrains('ssn')
def _check_ssn(self):
from stdnum import get_cc_module
modssn = get_cc_module('us', 'ssn')
modein = get_cc_module('us', 'ein')

for record in self:
error_flag = 0
try:
modssn.validate(record.ssn)
except:
error_flag+= 1
try:
modein.validate(record.ssn)
except:
error_flag+= 1
if error_flag == 2:
raise ValidationError('Social Security # / EIN field is not valid EIN or SSN format.')
Avatar
Ignorer
Auteur

I found a work around by adding a default, but I'd still like to know what the BEST solution would be.

ssn = fields.Char(string='Social Security # / EIN', size=11, default='000-00-0000')

Auteur

Actually the default DIDN'T work. :(

Publications associées Réponses Vues Activité
3
août 25
3801
1
oct. 24
1550
2
août 18
5531
1
juil. 25
1668
4
avr. 25
11981