Skip to content

Commit

Permalink
[REF] survey: rename survey.user_input type field to input_type
Browse files Browse the repository at this point in the history
Purpose of this commit is to rename type column to something matching the
the real business use of the field. That way it is easier to find and grep
in the code. It also lessens potential conflicts with type build-in python
function. It also lessens conflicts when using the field in JS as type
is a build-in attribute.

Renaming type column is a long-living issue. We choose to do it at the
beginning of the v13 development to catch errors as soon as possible.

This commit is linked to task ID 1896245. It is also a subpart of community
PR #27599.
  • Loading branch information
MiquelRForgeFlow authored and tde-banana-odoo committed Oct 19, 2018
1 parent b70ccc4 commit 35a5db9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion addons/survey/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def submit(self, survey, **post):
user_input = request.env['survey.user_input'].sudo().search([('token', '=', post['token'])], limit=1)
except KeyError: # Invalid token
return request.render("survey.403", {'survey': survey})
user_id = request.env.user.id if user_input.type != 'link' else SUPERUSER_ID
user_id = request.env.user.id if user_input.input_type != 'link' else SUPERUSER_ID

for question in questions:
answer_tag = "%s_%s_%s" % (survey.id, page_id, question.id)
Expand Down
4 changes: 2 additions & 2 deletions addons/survey/models/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ class SurveyUserInput(models.Model):
survey_id = fields.Many2one('survey.survey', string='Survey', required=True, readonly=True, ondelete='restrict')
date_create = fields.Datetime('Creation Date', default=fields.Datetime.now, required=True, readonly=True, copy=False)
deadline = fields.Datetime('Deadline', help="Date by which the person can open the survey and submit answers", oldname="date_deadline")
type = fields.Selection([('manually', 'Manually'), ('link', 'Link')], string='Answer Type', default='manually', required=True, readonly=True, oldname="response_type")
input_type = fields.Selection([('manually', 'Manually'), ('link', 'Link')], string='Answer Type', default='manually', required=True, readonly=True, oldname="type")
state = fields.Selection([
('new', 'Not started yet'),
('skip', 'Partially completed'),
Expand Down Expand Up @@ -736,7 +736,7 @@ def do_clean_emptys(self):
(used as a cronjob declared in data/survey_cron.xml)
"""
an_hour_ago = fields.Datetime.to_string(datetime.datetime.now() - datetime.timedelta(hours=1))
self.search([('type', '=', 'manually'), ('state', '=', 'new'),
self.search([('input_type', '=', 'manually'), ('state', '=', 'new'),
('date_create', '<', an_hour_ago)]).unlink()

@api.multi
Expand Down
10 changes: 5 additions & 5 deletions addons/survey/views/survey_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<field name="arch" type="xml">
<form string="Survey User inputs" create="false">
<header>
<button name="action_survey_resend" string="Send Invitation Again" type="object" class="oe_highlight" attrs="{'invisible': ['|', ('type','=','manually'), ('state', '=', 'done')]}"/>
<button name="action_survey_resend" string="Send Invitation Again" type="object" class="oe_highlight" attrs="{'invisible': ['|', ('input_type','=','manually'), ('state', '=', 'done')]}"/>
<button name="action_view_answers" states="done" string="Print These Answers" type="object" class="oe_highlight" />
<button name="action_survey_results" string="View Results" type="object" />
<field name="state" widget="statusbar"/>
Expand All @@ -41,7 +41,7 @@
<group>
<field name="survey_id"/>
<field name="date_create"/>
<field name="type"/>
<field name="input_type"/>
<field name="token" groups="base.group_no_one"/>
</group>
<group>
Expand Down Expand Up @@ -76,7 +76,7 @@
<field name="deadline"/>
<field name="partner_id"/>
<field name="email"/>
<field name="type"/>
<field name="input_type"/>
<field name="state"/>
<field name="test_entry" invisible="True"/>
<field name="quizz_score" groups="base.group_no_one"/>
Expand All @@ -93,7 +93,7 @@
<field name="date_create"/>
<field name="partner_id"/>
<field name="email"/>
<field name="type"/>
<field name="input_type"/>
<field name="state"/>
<templates>
<t t-name="kanban-box">
Expand All @@ -102,7 +102,7 @@
<div class="o_kanban_record_headings">
<strong class="o_kanban_record_title"><t t-esc="record.survey_id.value"/></strong>
</div>
<span class="badge badge-pill"><t t-esc="record.type.value"/></span>
<span class="badge badge-pill"><t t-esc="record.input_type.value"/></span>
</div>
<div class="o_kanban_record_bottom">
<div class="oe_kanban_bottom_left">
Expand Down
2 changes: 1 addition & 1 deletion addons/survey/wizard/survey_email_compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def create_token(wizard, partner_id, email):
'survey_id': wizard.survey_id.id,
'deadline': wizard.date_deadline,
'date_create': fields.Datetime.now(),
'type': 'link',
'input_type': 'link',
'state': 'new',
'token': token,
'partner_id': partner_id,
Expand Down

0 comments on commit 35a5db9

Please sign in to comment.