Skip to content

Commit

Permalink
Merge commit 'refs/pull/1142/head' of https://github.com/OCA/partner-…
Browse files Browse the repository at this point in the history
…contact into fko/14.0.2.1.0
  • Loading branch information
max3903 committed Feb 2, 2022
2 parents 3e7849e + 4c2eaff commit 6ef28ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
11 changes: 3 additions & 8 deletions partner_tier_validation/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 0 additions & 4 deletions partner_tier_validation/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 1 addition & 4 deletions partner_tier_validation/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
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,
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.
8 changes: 6 additions & 2 deletions partner_tier_validation/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions partner_tier_validation/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")

0 comments on commit 6ef28ad

Please sign in to comment.