|
|
@ -1,15 +1,16 @@ |
|
|
|
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
from psycopg2._psycopg import IntegrityError |
|
|
|
|
|
|
|
from odoo.exceptions import UserError, ValidationError |
|
|
|
from odoo.tests import common |
|
|
|
from odoo.exceptions import ValidationError |
|
|
|
from odoo.tools import mute_logger |
|
|
|
|
|
|
|
|
|
|
|
class TestPartnerIdentificationBase(common.TransactionCase): |
|
|
|
def test_create_id_category(self): |
|
|
|
partner_id_category = self.env["res.partner.id_category"].create( |
|
|
|
{"code": "id_code", "name": "id_name",} |
|
|
|
{"code": "id_code", "name": "id_name"} |
|
|
|
) |
|
|
|
self.assertEqual(partner_id_category.name, "id_name") |
|
|
|
self.assertEqual(partner_id_category.code, "id_code") |
|
|
@ -20,25 +21,18 @@ class TestPartnerIdentificationBase(common.TransactionCase): |
|
|
|
self.assertEqual(len(partner_1.id_numbers), 0) |
|
|
|
# create without required category |
|
|
|
with self.assertRaises(IntegrityError): |
|
|
|
partner_1.write({"id_numbers": [(0, 0, {"name": "1234",})]}) |
|
|
|
partner_1.write({"id_numbers": [(0, 0, {"name": "1234"})]}) |
|
|
|
|
|
|
|
def test_update_partner_with_category(self): |
|
|
|
partner_1 = self.env.ref("base.res_partner_1") |
|
|
|
partner_id_category = self.env["res.partner.id_category"].create( |
|
|
|
{"code": "new_code", "name": "new_name",} |
|
|
|
{"code": "new_code", "name": "new_name"} |
|
|
|
) |
|
|
|
# successful creation |
|
|
|
partner_1.write( |
|
|
|
{ |
|
|
|
"id_numbers": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "1234", |
|
|
|
"category_id": partner_id_category.id, |
|
|
|
}, |
|
|
|
) |
|
|
|
(0, 0, {"name": "1234", "category_id": partner_id_category.id}) |
|
|
|
] |
|
|
|
} |
|
|
|
) |
|
|
@ -66,28 +60,14 @@ if id_number.name != '1234': |
|
|
|
partner_1.write( |
|
|
|
{ |
|
|
|
"id_numbers": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "01234", |
|
|
|
"category_id": partner_id_category.id, |
|
|
|
}, |
|
|
|
) |
|
|
|
(0, 0, {"name": "01234", "category_id": partner_id_category.id}) |
|
|
|
] |
|
|
|
} |
|
|
|
) |
|
|
|
partner_1.write( |
|
|
|
{ |
|
|
|
"id_numbers": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "1234", |
|
|
|
"category_id": partner_id_category.id, |
|
|
|
}, |
|
|
|
) |
|
|
|
(0, 0, {"name": "1234", "category_id": partner_id_category.id}) |
|
|
|
] |
|
|
|
} |
|
|
|
) |
|
|
@ -107,9 +87,7 @@ if id_number.name != '1235': |
|
|
|
# check that the constrains is also checked when we change the |
|
|
|
# associated category |
|
|
|
with self.assertRaises(ValidationError), self.cr.savepoint(): |
|
|
|
partner_1.id_numbers.write( |
|
|
|
{"category_id": partner_id_category2.id} |
|
|
|
) |
|
|
|
partner_1.id_numbers.write({"category_id": partner_id_category2.id}) |
|
|
|
|
|
|
|
def test_bad_validation_code(self): |
|
|
|
partner_id_category = self.env["res.partner.id_category"].create( |
|
|
@ -123,18 +101,11 @@ if id_number.name != '1234' # missing : |
|
|
|
} |
|
|
|
) |
|
|
|
partner_1 = self.env.ref("base.res_partner_1") |
|
|
|
with self.assertRaises(ValidationError): |
|
|
|
with self.assertRaises(UserError): |
|
|
|
partner_1.write( |
|
|
|
{ |
|
|
|
"id_numbers": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "1234", |
|
|
|
"category_id": partner_id_category.id, |
|
|
|
}, |
|
|
|
) |
|
|
|
(0, 0, {"name": "1234", "category_id": partner_id_category.id}) |
|
|
|
] |
|
|
|
} |
|
|
|
) |
|
|
@ -151,20 +122,11 @@ if id_number.name != '1234' # missing : |
|
|
|
""", |
|
|
|
} |
|
|
|
) |
|
|
|
partner_1 = self.env.ref("base.res_partner_1").with_context( |
|
|
|
id_no_validate=True, |
|
|
|
) |
|
|
|
partner_1 = self.env.ref("base.res_partner_1").with_context(id_no_validate=True) |
|
|
|
partner_1.write( |
|
|
|
{ |
|
|
|
"id_numbers": [ |
|
|
|
( |
|
|
|
0, |
|
|
|
0, |
|
|
|
{ |
|
|
|
"name": "1234", |
|
|
|
"category_id": partner_id_category.id, |
|
|
|
}, |
|
|
|
) |
|
|
|
(0, 0, {"name": "1234", "category_id": partner_id_category.id}) |
|
|
|
] |
|
|
|
} |
|
|
|
) |