Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3367 Weergaven

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
Annuleer
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. :(

Gerelateerde posts Antwoorden Weergaven Activiteit
3
aug. 25
3698
1
okt. 24
1439
2
aug. 18
5472
1
jul. 25
1648
4
apr. 25
11937