From 09aa7cfdaa5390adae1c1444d810397f4940cdd8 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Thu, 15 Mar 2018 12:17:19 +0100 Subject: [PATCH] allow to add exceptions for fields that can be written on under validation records --- base_tier_validation/models/tier_validation.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index ce9763d62..e6cd55990 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -94,6 +94,21 @@ class TierValidation(models.AbstractModel): "Error evaluating tier validation conditions.\n %s") % error) return res + @api.model + def _get_under_validation_exceptions(self): + """Extend for more field exceptions.""" + return ['message_follower_ids'] + + @api.multi + def _check_allow_write_under_validation(self, vals): + """Allow to add exceptions for fields that are allowed to be written + even when the record is under validation.""" + exceptions = self._get_under_validation_exceptions() + for val in vals: + if val not in exceptions: + return False + return True + @api.multi def write(self, vals): for rec in self: @@ -113,7 +128,8 @@ class TierValidation(models.AbstractModel): "one record.")) if (rec.review_ids and getattr(rec, self._state_field) in self._state_from and not vals.get(self._state_field) in - (self._state_to + [self._cancel_state])): + (self._state_to + [self._cancel_state]) and not + self._check_allow_write_under_validation(vals)): raise ValidationError(_("The operation is under validation.")) if vals.get(self._state_field) in self._state_from: self.mapped('review_ids').sudo().unlink()