From ba6ca5b5fa2d4e10c5b5d050e1f87402611ae783 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Wed, 8 May 2019 11:22:18 +0200 Subject: [PATCH 1/2] [IMP] base_tier_validation: Add a chatter message if the model has it --- base_tier_validation/__manifest__.py | 2 +- base_tier_validation/models/tier_validation.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/base_tier_validation/__manifest__.py b/base_tier_validation/__manifest__.py index 3d4b40a..ff67920 100644 --- a/base_tier_validation/__manifest__.py +++ b/base_tier_validation/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Base Tier Validation", "summary": "Implement a validation process based on tiers.", - "version": "11.0.2.0.0", + "version": "11.0.2.0.1", "development_status": "Mature", "maintainers": ['lreficent'], "category": "Tools", diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index 3b474b9..cbb6ade 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -154,7 +154,14 @@ class TierValidation(models.AbstractModel): 'done_by': self.env.user.id, 'reviewed_date': fields.Datetime.now(), }) - # TODO: add message_post + for review in user_reviews: + rec = self.env[review.model].browse(review.res_id) + if hasattr(rec, 'message_post'): + # Notify state change + getattr(rec, 'message_post')( + subtype='mt_comment', + body=_('A review was accepted') + ) @api.multi def validate_tier(self): @@ -173,7 +180,14 @@ class TierValidation(models.AbstractModel): 'done_by': self.env.user.id, 'reviewed_date': fields.Datetime.now(), }) - # TODO: Add Message_post + if hasattr(rec, 'message_post'): + # Notify state change + getattr(rec, 'message_post')( + subtype='mt_comment', + body=_( + 'A review was rejected by %s.' + ) % (self.env.user.name) + ) @api.multi def request_validation(self): From 161d1a743d2674c36a90ceec172ba53f5330c177 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Thu, 9 May 2019 17:48:25 +0200 Subject: [PATCH 2/2] fixup! [IMP] base_tier_validation: Add a chatter message if the model has it --- .../models/tier_validation.py | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index cbb6ade..fcaed6a 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -156,12 +156,18 @@ class TierValidation(models.AbstractModel): }) for review in user_reviews: rec = self.env[review.model].browse(review.res_id) - if hasattr(rec, 'message_post'): - # Notify state change - getattr(rec, 'message_post')( - subtype='mt_comment', - body=_('A review was accepted') - ) + rec._notify_accepted_reviews() + + def _notify_accepted_reviews(self): + if hasattr(self, 'message_post'): + # Notify state change + getattr(self, 'message_post')( + subtype='mt_comment', + body=self._notify_accepted_reviews_body() + ) + + def _notify_accepted_reviews_body(self): + return _('A review was accepted') @api.multi def validate_tier(self): @@ -180,14 +186,18 @@ class TierValidation(models.AbstractModel): 'done_by': self.env.user.id, 'reviewed_date': fields.Datetime.now(), }) - if hasattr(rec, 'message_post'): - # Notify state change - getattr(rec, 'message_post')( - subtype='mt_comment', - body=_( - 'A review was rejected by %s.' - ) % (self.env.user.name) - ) + rec._notify_rejected_review() + + def _notify_rejected_review_body(self): + return _('A review was rejected by %s.') % (self.env.user.name) + + def _notify_rejected_review(self): + if hasattr(self, 'message_post'): + # Notify state change + getattr(self, 'message_post')( + subtype='mt_comment', + body=self._notify_rejected_review_body() + ) @api.multi def request_validation(self):