-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Conditional survey questions' usability
* Allow to configure conditional questions before saving the page * Skip pages in the survey without visible questions * Hide questions and pages without visible questions in the print overview * Restore method inheritance * Adapt to Odoo 14.0 datamodel
- Loading branch information
1 parent
a4f322c
commit 471e33d
Showing
16 changed files
with
311 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
survey_conditional_questions/migrations/11.0.1.2.0/pre-migrate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
|
||
def migrate(cr, version): | ||
logger = logging.getLogger( | ||
'survey_conditional_questions.migrations.11.0.1.3.0') | ||
|
||
def rename(old, new): | ||
""" Rename column if the old column exists and the new one does not """ | ||
cr.execute( | ||
""" SELECT EXISTS( | ||
SELECT * | ||
FROM information_schema.columns | ||
WHERE table_name='survey_question' | ||
AND column_name=%s) """, (new,)) | ||
if cr.fetchone()[0]: | ||
logger.info('Column %s already exists', new) | ||
return | ||
cr.execute( | ||
""" SELECT EXISTS( | ||
SELECT * | ||
FROM information_schema.columns | ||
WHERE table_name='survey_question' | ||
AND column_name=%s) """, (old,)) | ||
if not cr.fetchone()[0]: | ||
logger.info('Column %s does not exist', old) | ||
return | ||
logger.info('Renaming column %s to %s', new, old) | ||
cr.execute( | ||
""" ALTER TABLE survey_question | ||
RENAME COLUMN %s to %s """ % (old, new)) | ||
|
||
for old, new in [ | ||
('conditional', 'is_conditional'), | ||
('question_conditional_id', 'triggering_question_id'), | ||
('answer_id', 'triggering_answer_id')]: | ||
rename(old, new) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from odoo import api, models | ||
|
||
|
||
class SurveySurvey(models.Model): | ||
_inherit = 'survey.survey' | ||
|
||
@api.model | ||
def next_page(self, user_input, page_id, go_back=False): | ||
""" Skip pages that only have hidden questions on them, | ||
except if its the last page or the first page (in which case there | ||
is a configuration error in the survey). """ | ||
questions_to_hide = user_input.get_hidden_questions() | ||
res = super(SurveySurvey, self).next_page( | ||
user_input, page_id, go_back=go_back) | ||
page, index, last = res | ||
if page and not (page.question_ids - questions_to_hide): | ||
if (not go_back and not last) or (go_back and index): | ||
# Mark every question on this hidden page as hidden. | ||
for question in page.question_ids: | ||
self.env['survey.user_input_line'].update_hidden( | ||
user_input, question) | ||
return self.next_page( | ||
user_input, page.id, go_back=go_back) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.