Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3398 มุมมอง

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.')
อวตาร
ละทิ้ง
ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ส.ค. 25
3808
1
ต.ค. 24
1560
2
ส.ค. 18
5534
1
ก.ค. 25
1671
4
เม.ย. 25
11987