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.')
03/03/2021 11:31:22 | ERROR | server | ERROR: TestFormCreate.test_create_res_partner Traceback (most recent call last): File "/home/odoo/src/odoo/odoo/addons/base/tests/test_form_create.py", line 33, in test_create_res_partner partner_form.save() File "/home/odoo/src/odoo/odoo/tests/common.py", line 1884, in save r = self._model.create(values) File "<decorator-gen-154>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 344, in _model_create_multi return create(self, [arg]) File "/home/odoo/src/odoo/addons/partner_autocomplete/models/res_partner.py", line 183, in create partners = super(ResPartner, self).create(vals_list) File "<decorator-gen-95>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 345, in _model_create_multi return create(self, arg) File "/home/odoo/src/odoo/odoo/addons/base/models/res_partner.py", line 562, in create partners = super(Partner, self).create(vals_list) File "<decorator-gen-133>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 345, in _model_create_multi return create(self, arg) File "/home/odoo/src/odoo/addons/mail/models/mail_thread.py", line 264, in create threads = super(MailThread, self).create(vals_list) File "<decorator-gen-65>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 345, in _model_create_multi return create(self, arg) File "/home/odoo/src/odoo/odoo/addons/base/models/ir_fields.py", line 533, in create recs = super().create(vals_list) File "<decorator-gen-13>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 345, in _model_create_multi return create(self, arg) File "/home/odoo/src/odoo/odoo/models.py", line 3866, in create records = self._create(data_list) File "/home/odoo/src/odoo/odoo/models.py", line 4039, in _create records._validate_fields(name for data in data_list for name in data['stored']) File "/home/odoo/src/odoo/odoo/models.py", line 1256, in _validate_fields check(self) File "/home/odoo/src/user/psd_custom/models/res_partner.py", line 38, in _check_ssn raise ValidationError('Social Security # / EIN field is not valid EIN or SSN format.') odoo.exceptions.ValidationError: Social Security # / EIN field is not valid EIN or SSN format. |
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')
Actually the default DIDN'T work. :(