|
@ -10,18 +10,25 @@ class TestPartnerTierValidation(common.SavepointCase): |
|
|
@classmethod |
|
|
@classmethod |
|
|
def setUpClass(cls): |
|
|
def setUpClass(cls): |
|
|
super().setUpClass() |
|
|
super().setUpClass() |
|
|
# Get res partner model |
|
|
|
|
|
cls.partner_model = cls.env.ref("base.model_res_partner") |
|
|
|
|
|
|
|
|
|
|
|
# Create users |
|
|
# Create users |
|
|
group_ids = cls.env.ref("base.group_system").ids |
|
|
|
|
|
group_ids.append(cls.env.ref("base.group_partner_manager").id) |
|
|
|
|
|
cls.test_user_1 = cls.env["res.users"].create( |
|
|
|
|
|
|
|
|
group_user = cls.env.ref("base.group_user") |
|
|
|
|
|
group_contacts = cls.env.ref("base.group_partner_manager") |
|
|
|
|
|
group_approver = cls.env.ref("base.group_no_one") |
|
|
|
|
|
User = cls.env["res.users"] |
|
|
|
|
|
cls.user_employee = User.create( |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "Employee", |
|
|
|
|
|
"login": "empl1", |
|
|
|
|
|
"email": "empl1@example.com", |
|
|
|
|
|
"groups_id": (group_user | group_contacts).ids, |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
cls.user_approver = User.create( |
|
|
{ |
|
|
{ |
|
|
"name": "John", |
|
|
|
|
|
"login": "test1", |
|
|
|
|
|
"groups_id": [(6, 0, group_ids)], |
|
|
|
|
|
"email": "test@example.com", |
|
|
|
|
|
|
|
|
"name": "Approver", |
|
|
|
|
|
"login": "aprov1", |
|
|
|
|
|
"email": "approv1@example.com", |
|
|
|
|
|
"groups_id": (group_user | group_contacts | group_approver).ids, |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -29,13 +36,20 @@ class TestPartnerTierValidation(common.SavepointCase): |
|
|
cls.TierDefinition = cls.env["tier.definition"] |
|
|
cls.TierDefinition = cls.env["tier.definition"] |
|
|
cls.TierDefinition.create( |
|
|
cls.TierDefinition.create( |
|
|
{ |
|
|
{ |
|
|
"model_id": cls.partner_model.id, |
|
|
|
|
|
|
|
|
"model_id": cls.env.ref("base.model_res_partner").id, |
|
|
"review_type": "individual", |
|
|
"review_type": "individual", |
|
|
"reviewer_id": cls.test_user_1.id, |
|
|
|
|
|
|
|
|
"reviewer_id": cls.user_approver.id, |
|
|
"definition_domain": "[('is_company','=',True)]", |
|
|
"definition_domain": "[('is_company','=',True)]", |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Setup Contact Stages: draft is the default |
|
|
|
|
|
Stage = cls.env["res.partner.stage"] |
|
|
|
|
|
Stage.search([("is_default", "=", True)]).write({"is_default": False}) |
|
|
|
|
|
cls.stage_draft = Stage.search([("state", "=", "draft")], limit=1) |
|
|
|
|
|
cls.stage_draft.is_default = True |
|
|
|
|
|
cls.stage_confirmed = Stage.search([("state", "=", "confirmed")], limit=1) |
|
|
|
|
|
|
|
|
def test_tier_validation_model_name(self): |
|
|
def test_tier_validation_model_name(self): |
|
|
self.assertIn( |
|
|
self.assertIn( |
|
|
"res.partner", self.TierDefinition._get_tier_validation_model_names() |
|
|
"res.partner", self.TierDefinition._get_tier_validation_model_names() |
|
@ -45,31 +59,37 @@ class TestPartnerTierValidation(common.SavepointCase): |
|
|
""" |
|
|
""" |
|
|
Case where new Contact requires validation |
|
|
Case where new Contact requires validation |
|
|
""" |
|
|
""" |
|
|
contact = self.env["res.partner"].create( |
|
|
|
|
|
{"name": "Company for test", "company_type": "company"} |
|
|
|
|
|
) |
|
|
|
|
|
# Since contact need validation, it should be inactive |
|
|
|
|
|
|
|
|
Partner = self.env["res.partner"] |
|
|
|
|
|
contact_vals = {"name": "Company for test", "company_type": "company"} |
|
|
|
|
|
contact = Partner.with_user(self.user_employee).create(contact_vals) |
|
|
self.assertEqual(contact.state, "draft") |
|
|
self.assertEqual(contact.state, "draft") |
|
|
|
|
|
|
|
|
# Assert an error shows if trying to make it active |
|
|
# Assert an error shows if trying to make it active |
|
|
with self.assertRaises(ValidationError): |
|
|
with self.assertRaises(ValidationError): |
|
|
contact.write({"state": "confirmed"}) |
|
|
|
|
|
|
|
|
contact.write({"stage_id": self.stage_confirmed.id}) |
|
|
|
|
|
|
|
|
# Request and validate partner |
|
|
# Request and validate partner |
|
|
contact.request_validation() |
|
|
contact.request_validation() |
|
|
contact.with_user(self.test_user_1).validate_tier() |
|
|
|
|
|
contact.with_user(self.test_user_1).write({"state": "confirmed"}) |
|
|
|
|
|
|
|
|
contact.with_user(self.user_approver).validate_tier() |
|
|
|
|
|
contact.with_user(self.user_approver).write( |
|
|
|
|
|
{"stage_id": self.stage_confirmed.id} |
|
|
|
|
|
) |
|
|
self.assertEqual(contact.state, "confirmed") |
|
|
self.assertEqual(contact.state, "confirmed") |
|
|
|
|
|
|
|
|
# Change company type to retrigger validation |
|
|
# Change company type to retrigger validation |
|
|
contact.write({"company_type": "person", "is_company": False}) |
|
|
|
|
|
self.assertEqual(contact.state, "draft") |
|
|
|
|
|
|
|
|
contact.write({"company_type": "person"}) |
|
|
|
|
|
self.assertEqual( |
|
|
|
|
|
contact.state, "draft", "Change company type sets back to draft" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
def test_no_validation_res_partner(self): |
|
|
def test_no_validation_res_partner(self): |
|
|
""" |
|
|
""" |
|
|
Case where new Contact does not require validation |
|
|
Case where new Contact does not require validation |
|
|
""" |
|
|
""" |
|
|
contact = self.env["res.partner"].create( |
|
|
|
|
|
{"name": "Person for test", "company_type": "person"} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
Partner = self.env["res.partner"] |
|
|
|
|
|
contact_vals = {"name": "Company for test", "company_type": "person"} |
|
|
|
|
|
contact = Partner.with_user(self.user_employee).create(contact_vals) |
|
|
|
|
|
self.assertEqual(contact.state, "draft") |
|
|
|
|
|
# Can move to confirmed state without approval |
|
|
|
|
|
contact.write({"stage_id": self.stage_confirmed.id}) |
|
|
self.assertEqual(contact.state, "confirmed") |
|
|
self.assertEqual(contact.state, "confirmed") |