[IMP] New kanban view for surveys (inspired of mass_mailing campaigns)
authorRichard Mathot (OpenERP) <rim@openerp.com>
Tue, 21 Jan 2014 16:03:54 +0000 (17:03 +0100)
committerRichard Mathot (OpenERP) <rim@openerp.com>
Tue, 21 Jan 2014 16:03:54 +0000 (17:03 +0100)
JS links need to be checked in the next revision :-)

bzr revid: rim@openerp.com-20140121160354-oc4jd8k2z71chvob

addons/survey/__openerp__.py
addons/survey/static/src/css/survey.css
addons/survey/survey.py
addons/survey/views/survey_views.xml

index a8880a8..eaa9417 100644 (file)
@@ -36,7 +36,7 @@ sent mails with personal token for the invitation of the survey.
     'summary': 'Create surveys, collect answers and print statistics',
     'author': 'OpenERP SA',
     'website': 'https://www.openerp.com/apps/survey/',
-    'depends': ['email_template', 'mail', 'website'],
+    'depends': ['email_template', 'mail', 'website', 'web_kanban_gauge'],
     'data': [
         'security/survey_security.xml',
         'security/ir.model.access.csv',
index 361fd54..8feb0c7 100644 (file)
@@ -6,8 +6,8 @@
 }
 
 .openerp .oe_kanban_survey {
-    width: 212px;
-    min-height: 86px !important;
+    width: 540px;
+    min-height: 220px !important;
 }
 .openerp .oe_kanban_survey .oe_kanban_survey_list{
     width: 100%;
index 177cf16..a9f78d4 100644 (file)
@@ -56,6 +56,17 @@ class survey_survey(osv.Model):
 
     ## Function fields ##
 
+    def _get_tot_sent_survey(self, cr, uid, ids, name, arg, context=None):
+        """ Returns the number of invitations sent for this survey, be they
+        (partially) completed or not """
+        res = dict((id, 0) for id in ids)
+        sur_res_obj = self.pool.get('survey.user_input')
+        for id in ids:
+            res[id] = sur_res_obj.search(cr, uid,  # SUPERUSER_ID,
+                [('survey_id', '=', id), ('type', '=', 'link')],
+                context=context, count=True)
+        return res
+
     def _get_tot_start_survey(self, cr, uid, ids, name, arg, context=None):
         """ Returns the number of started instances of this survey, be they
         completed or not """
@@ -63,7 +74,7 @@ class survey_survey(osv.Model):
         sur_res_obj = self.pool.get('survey.user_input')
         for id in ids:
             res[id] = sur_res_obj.search(cr, uid,  # SUPERUSER_ID,
-                [('survey_id', '=', id), ('state', '=', 'skip')],
+                ['&', ('survey_id', '=', id), '|', ('state', '=', 'skip'), ('state', '=', 'done')],
                 context=context, count=True)
         return res
 
@@ -108,6 +119,8 @@ class survey_survey(osv.Model):
             oldname="authenticate"),
         'users_can_go_back': fields.boolean('Users can go back',
             help="If checked, users can go back to previous pages."),
+        'tot_sent_survey': fields.function(_get_tot_sent_survey,
+            string="Number of sent surveys", type="integer"),
         'tot_start_survey': fields.function(_get_tot_start_survey,
             string="Number of started surveys", type="integer"),
         'tot_comp_survey': fields.function(_get_tot_comp_survey,
index 70f019a..b1208ab 100644 (file)
             </field>
         </record>
         <record model="ir.ui.view" id="view_survey_kanban">
-            <field name="name">event.survey.kanban</field>
+            <field name="name">survey.kanban</field>
             <field name="model">survey.survey</field>
             <field name="arch" type="xml">
                 <kanban>
-                    <field name="title"/>
-                    <field name="date_open"/>
-                    <field name="tot_comp_survey"/>
-                    <field name="user_input_limit"/>
-                    <field name="color"/>
-                    <field name="state"/>
-                    <field name="auth_required"/>
-                    <field name="public_url"/>
+                    <field name="title" />
+                    <field name="date_open" />
+                    <field name="tot_sent_survey" />
+                    <field name="tot_start_survey" />
+                    <field name="tot_comp_survey" />
+                    <field name="user_input_limit" />
+                    <field name="color" />
+                    <field name="state" />
+                    <field name="visible_to_user" />
+                    <field name="auth_required" />
+                    <field name="public_url" />
                     <templates>
                         <div t-name="kanban-box" t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_survey oe_kanban_global_click">
                             <div class="oe_dropdown_toggle oe_dropdown_kanban" t-if="widget.view.is_action_enabled('edit')">
                                     <a t-if="record.state.raw_value === 'cancel'" title="Cancelled" class="oe_kanban_status_salmon"> </a>
                                 </span>
                                 <h3 class="oe_kanban_ellipsis"><t t-esc="record.title.raw_value.toString()"></t></h3>
-                                <div><p>
-                                    <ul>
-                                        <li>Opening: <field name="date_open"/></li>
-                                        <li>Closing: <field name="date_close"/></li>
-                                    </ul>
-                                </p></div>
-                                <div class="oe_stats_box"><span><field name="tot_start_survey"/></span><br/>started</div>
-                                <div class="oe_stats_box"><span><field name="tot_comp_survey"/></span><br/>completed</div>
+                                <div t-if="record.visible_to_user.raw_value === false">
+                                    <center>
+                                        <field name="tot_sent_survey" widget="gauge" style="width:160px; height: 120px;"
+                                            options="{'max_field': 'tot_sent_survey'}"/>
+                                        <field name="tot_start_survey" widget="gauge" style="width:160px; height: 120px;"
+                                            options="{'max_field': 'tot_sent_survey'}"/>
+                                        <field name="tot_comp_survey" widget="gauge" style="width:160px; height: 120px;"
+                                            options="{'max_field': 'tot_sent_survey'}"/>
+                                    </center>
+                                </div>
+                                <div t-if="record.visible_to_user.raw_value === true">
+                                    <center>
+                                        <field name="tot_start_survey" widget="gauge" style="width:160px; height: 120px;"
+                                            options="{'max_field': 'tot_start_survey'}"/>
+                                        <field name="tot_comp_survey" widget="gauge" style="width:160px; height: 120px;"
+                                            options="{'max_field': 'tot_start_survey'}"/>
+                                    </center>
+                                </div>
+                                <div t-if="record.visible_to_user.raw_value === true">
+                                    <center><b><a t-att-href="record.public_url.raw_value"><t t-esc="record.public_url.raw_value"/></a></b></center>
+                                </div>
+                                <div>
+                                    Opening date: <field name="date_open" /><br />
+                                    Closing date: <field name="date_close" />
+                                </div>
                             </div>
                         </div>
                     </templates>
             <field name="res_model">survey.survey</field>
             <field name="view_type">form</field>
             <field name="view_mode">kanban,tree,form,calendar</field>
-            <field name="view_id" ref="view_survey_kanban"></field>
             <field name="search_view_id" ref="survey_search"/>
             <field name="help" type="html">
                 <p class="oe_view_nocontent_create">Click to create a new survey.</p>
             <field name="name">Survey User Input lines</field>
             <field name="res_model">survey.user_input_line</field>
             <field name="view_mode">tree,form</field>
-        </record> -->
+        </record>
 
 
         <!-- ACTIONS -->