diff --git a/partner_tier_validation/models/res_partner.py b/partner_tier_validation/models/res_partner.py index 34e78d17e22..e3e5ac488ef 100644 --- a/partner_tier_validation/models/res_partner.py +++ b/partner_tier_validation/models/res_partner.py @@ -27,21 +27,16 @@ def _tier_revalidation_fields(self, values): @api.model def create(self, vals): new = super().create(vals) - if new.need_validation and new.state != "confirmed": - new.active = False - else: - new.active = True + if not new.need_validation: new.state = "confirmed" + return new def write(self, vals): - # Changing certain fields required new validation process + # Changing certain fields requires validation process revalidate_fields = self._tier_revalidation_fields(vals) if any(x in revalidate_fields for x in vals.keys()): self.mapped("review_ids").unlink() vals["state"] = "draft" - # Automatically update active flag depending on state - if "state" in vals: - vals["active"] = vals["state"] == "confirmed" return super().write(vals) diff --git a/partner_tier_validation/readme/CONFIGURATION.rst b/partner_tier_validation/readme/CONFIGURATION.rst index f2c56d72eb7..1e7bfc8998c 100644 --- a/partner_tier_validation/readme/CONFIGURATION.rst +++ b/partner_tier_validation/readme/CONFIGURATION.rst @@ -4,7 +4,3 @@ that can be used as a starting point fot this configuration. This configuration is done at *Settings > Technical > Tier Validations > Tier Definition*. - -Note that, since Contacts start as archived records, -the *Definition Domain* must include ``"|",["active","=",True],["active","=",False]``. -Otherwise the validation rule won't apply correctly in new records. diff --git a/partner_tier_validation/readme/DESCRIPTION.rst b/partner_tier_validation/readme/DESCRIPTION.rst index fe2b83fe66f..000fa7fec20 100644 --- a/partner_tier_validation/readme/DESCRIPTION.rst +++ b/partner_tier_validation/readme/DESCRIPTION.rst @@ -1,6 +1,5 @@ Adds an approval workflow to Partners. -The default rule requires new company Contacts to be approved -before they can be used. +The default rule sets new company Contacts to the Draft state. The rule can be extended to new non-company contact, but beware that may cause issues with automatically created new contacts, @@ -8,5 +7,3 @@ such as the ones generated when processing incoming emails. If the 'Is Company' or 'Parent' field changes then the contact is Request for approval. - -For this, the new Contact record is kept as "Archived" until it is approved. diff --git a/partner_tier_validation/readme/USAGE.rst b/partner_tier_validation/readme/USAGE.rst index 40016f54a5b..cf5115a715f 100644 --- a/partner_tier_validation/readme/USAGE.rst +++ b/partner_tier_validation/readme/USAGE.rst @@ -1,7 +1,7 @@ A regular user creates a new Contact and sends it for approval: #. Create a Contact triggering at least one "Tier Definition". - The Contact will be in Draft state and marked as Archived until approved. + The Contact will be in Draft state until approved. #. Click on *Request Validation* button. #. In the *Reviews* section, at the bottom of the form, inspect the pending reviews and their status. @@ -12,7 +12,11 @@ The approver reviews Contacts to approve: #. Open the Contact form to approve. It will display a "This Records needs to be validated" banner, with "Validate" and "Reject" options. #. The approver can change the state to "Active". - This will automatically unarchive the record and make it available to be used. + This will automatically make the record available to be used. + + +To restrict certain fields to only allow approved Contacts, +add a domain to that field with [("state", "=", "confirmed")] The Approve/Reject actions do not automatically change the State. diff --git a/partner_tier_validation/tests/test_tier_validation.py b/partner_tier_validation/tests/test_tier_validation.py index f4fe3d2214f..8f902bb6c23 100644 --- a/partner_tier_validation/tests/test_tier_validation.py +++ b/partner_tier_validation/tests/test_tier_validation.py @@ -46,8 +46,8 @@ def test_validation_res_partner(self): company = self.env["res.partner"].create( {"name": "Company for test", "company_type": "company"} ) - # Since company need validation, it should be inactive - self.assertEqual(company.active, False) + # Since company need validation, it should be in Draft state + self.assertEqual(company.state, "draft") # Assert an error shows if trying to make it active with self.assertRaises(ValidationError): @@ -65,4 +65,4 @@ def test_validation_res_partner(self): # Test partner creation that doesn't need validation customer = self.env["res.partner"].create({"name": "Partner for test"}) - self.assertEqual(customer.active, True) + self.assertEqual(customer.state, "confirmed")