From cffdcfea0f275beb7f3f7aaf5e921f89844a4101 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Fri, 23 Mar 2018 10:44:34 +0100 Subject: [PATCH] [9.0][IMP] base_tier_validation: * able to restart validation * sudo() not needed anymore --- base_tier_validation/__openerp__.py | 2 +- base_tier_validation/models/tier_validation.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/base_tier_validation/__openerp__.py b/base_tier_validation/__openerp__.py index ce34496..c9d97d9 100644 --- a/base_tier_validation/__openerp__.py +++ b/base_tier_validation/__openerp__.py @@ -4,7 +4,7 @@ { "name": "Base Tier Validation", "summary": "Implement a validation process based on tiers.", - "version": "9.0.1.0.0", + "version": "9.0.1.0.1", "category": "Tools", "website": "https://github.com/OCA/server-tools", "author": "Eficent, Odoo Community Association (OCA)", diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index e6cd559..739b2d6 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -15,7 +15,6 @@ class TierValidation(models.AbstractModel): _state_to = ['confirmed'] _cancel_state = 'cancel' - # TODO: reset validation? # TODO: step by step validation? review_ids = fields.One2many( @@ -69,6 +68,8 @@ class TierValidation(models.AbstractModel): @api.model def _calc_reviews_validated(self, reviews): """Override for different validation policy.""" + if not reviews: + return False return not any([s != 'approved' for s in reviews.mapped('status')]) @api.model @@ -122,7 +123,7 @@ class TierValidation(models.AbstractModel): raise ValidationError(_( "This action needs to be validated for at least " "one record. \nPlease request a validation.")) - if not rec.validated: + if rec.review_ids and not rec.validated: raise ValidationError(_( "A validation process is still open for at least " "one record.")) @@ -132,7 +133,7 @@ class TierValidation(models.AbstractModel): 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() + self.mapped('review_ids').unlink() return super(TierValidation, self).write(vals) def _validate_tier(self, tiers=False): @@ -179,3 +180,9 @@ class TierValidation(models.AbstractModel): }) # TODO: notify? post some msg in chatter? return created_trs + + @api.multi + def restart_validation(self): + for rec in self: + if getattr(rec, self._state_field) in self._state_from: + rec.mapped('review_ids').unlink()