diff options
| author | Victor Feyens <vfe@odoo.com> | 2019-03-28 16:46:44 +0000 |
|---|---|---|
| committer | Victor Feyens <vfe@odoo.com> | 2019-04-25 14:17:45 +0000 |
| commit | 50caae5bc02bc6eaa1b4a4dfd965c84c940bb84b (patch) | |
| tree | 15b80bf599dc2bf615e2621566370d41d28f99b9 /addons/survey/models | |
| parent | 28e1686bc5c862802162606527a190e344014591 (diff) | |
[REF] survey: replace dynamic survey.stage by a static state on survey.survey
Stages modification through the clickable statusbar wasn't very intuitive.
By fixing default behavior through states (and corresponding buttons), default user experience is simplified.
3 static states available : draft, open, closed
Form view: navigation through states with buttons
Kanban view: disabled modification of survey state
Task ID : 1949110
closes odoo/odoo#32325
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/survey/models')
| -rw-r--r-- | addons/survey/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/survey/models/survey_stage.py | 19 | ||||
| -rw-r--r-- | addons/survey/models/survey_survey.py | 41 |
3 files changed, 26 insertions, 35 deletions
diff --git a/addons/survey/models/__init__.py b/addons/survey/models/__init__.py index 7b04b95e1cc..982f7817af9 100644 --- a/addons/survey/models/__init__.py +++ b/addons/survey/models/__init__.py @@ -4,5 +4,4 @@ from . import ir_autovacuum from . import survey_survey from . import survey_question -from . import survey_stage from . import survey_user diff --git a/addons/survey/models/survey_stage.py b/addons/survey/models/survey_stage.py deleted file mode 100644 index f2d415340fd..00000000000 --- a/addons/survey/models/survey_stage.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import fields, models - - -class SurveyStage(models.Model): - _name = 'survey.stage' - _description = 'Survey Stage' - _order = 'sequence,id' - - name = fields.Char(required=True, translate=True) - sequence = fields.Integer(default=1) - closed = fields.Boolean(help="If closed, people won't be able to answer to surveys in this column.") - fold = fields.Boolean(string="Folded in kanban view") - - _sql_constraints = [ - ('positive_sequence', 'CHECK(sequence >= 0)', 'Sequence number MUST be a natural') - ] diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index c2452b55524..3f6410c6899 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -21,9 +21,6 @@ class Survey(models.Model): _rec_name = 'title' _inherit = ['mail.thread', 'mail.activity.mixin'] - def _get_default_stage_id(self): - return self.env['survey.stage'].search([], limit=1).id - def _get_default_access_token(self): return str(uuid.uuid4()) @@ -37,9 +34,15 @@ class Survey(models.Model): question_and_page_ids = fields.One2many('survey.question', 'survey_id', string='Sections and Questions', copy=True) page_ids = fields.One2many('survey.question', string='Pages', compute="_compute_page_and_question_ids") question_ids = fields.One2many('survey.question', string='Questions', compute="_compute_page_and_question_ids") - stage_id = fields.Many2one('survey.stage', string="Stage", default=lambda self: self._get_default_stage_id(), - ondelete="restrict", copy=False, group_expand='_read_group_stage_ids') - is_closed = fields.Boolean("Is closed", related='stage_id.closed', readonly=True) + state = fields.Selection( + string="Survey Stage", + selection=[ + ('draft', 'Draft'), + ('open', 'In Progress'), + ('closed', 'Closed'), + ], default='draft', required=True, + group_expand='_read_group_states' + ) questions_layout = fields.Selection([ ('one_page', 'One page with all the questions'), ('page_per_section', 'One page per section'), @@ -174,13 +177,9 @@ class Survey(models.Model): if self.is_time_limited and (not self.time_limit or self.time_limit <= 0): self.time_limit = 10 - @api.model - def _read_group_stage_ids(self, stages, domain, order): - """ Read group customization in order to display all the stages in the - kanban view, even if they are empty - """ - stage_ids = stages._search([], order=order, access_rights_uid=SUPERUSER_ID) - return stages.browse(stage_ids) + def _read_group_states(self, values, domain, order): + selection = self.env['survey.survey'].fields_get(allfields=['state'])['state']['selection'] + return [s[0] for s in selection] # Public methods # def copy_data(self, default=None): @@ -245,7 +244,7 @@ class Survey(models.Model): else: if not self.active: raise UserError(_('Creating token for archived surveys is not allowed.')) - elif self.is_closed: + elif self.state == 'closed': raise UserError(_('Creating token for closed surveys is not allowed.')) if self.access_mode == 'authentication': # signup possible -> should have at least a partner to create an account @@ -438,6 +437,18 @@ class Survey(models.Model): # Actions @api.multi + def action_draft(self): + self.write({'state': 'draft'}) + + @api.multi + def action_open(self): + self.write({'state': 'open'}) + + @api.multi + def action_close(self): + self.write({'state': 'closed'}) + + @api.multi def action_start_survey(self): """ Open the website page with the survey form """ self.ensure_one() @@ -457,7 +468,7 @@ class Survey(models.Model): if (not self.page_ids and self.questions_layout == 'page_per_section') or not self.question_ids: raise UserError(_('You cannot send an invitation for a survey that has no questions.')) - if self.stage_id.closed: + if self.state == 'closed': raise UserError(_("You cannot send invitations for closed surveys.")) template = self.env.ref('survey.mail_template_user_input_invite', raise_if_not_found=False) |
