Skip to Content
Menu
This question has been flagged

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
Discard
Author

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')

Author

Actually the default DIDN'T work. :(

Related Posts Replies Views Activity
2
Jul 24
1921
1
Oct 24
313
2
Aug 18
4344
1
Sep 24
1641
0
Sep 24
319