[IMP] doc/howtos/backend: improve exercises on relational fields
authorRaphael Collet <rco@openerp.com>
Wed, 27 Aug 2014 08:45:56 +0000 (10:45 +0200)
committerRaphael Collet <rco@openerp.com>
Wed, 27 Aug 2014 08:45:56 +0000 (10:45 +0200)
doc/howtos/backend.rst
doc/howtos/backend/exercise-many2many
doc/howtos/backend/exercise-many2one
doc/howtos/backend/exercise-one2many
doc/howtos/backend/exercise-session
doc/howtos/backend/series

index de96f53..7af76db 100644 (file)
@@ -496,11 +496,12 @@ client data; it is also related to its sale order line records.
 
     Create a model for *sessions*. A session has a name, a start date, a
     duration and a number of seats. Add an action and a menu item to display
-    them.
+    them. Make the new model visible via a menu item.
 
     .. only:: solutions
 
-        Create the class *Session* in ``openacademy/models.py``.
+        #. Create the class *Session* in ``openacademy/models.py``.
+        #. Add access to the session object in ``openacademy/view/openacademy.xml``.
 
         .. patch::
 
@@ -530,7 +531,7 @@ Relational field types are:
     accessing it results in a (possibly empty) set of records::
 
         for other in foo.other_ids:
-            print foo.name
+            print other.name
 
     .. danger::
 
@@ -544,7 +545,7 @@ Relational field types are:
     records, accessing it also results in a possibly empty set of records::
 
         for other in foo.other_ids:
-            print foo.name
+            print other.name
 
 .. exercise:: Many2one relations
 
@@ -557,12 +558,12 @@ Relational field types are:
       built-in model ``res.partner``.
     - A session is related to a *course*; the value of that field is a record
       of the model ``openacademy.course`` and is required.
+    - Adapt the views.
 
     .. only:: solutions
 
         #. Add the relevant ``Many2one`` fields to the models, and
-        #. add access to the session object in
-           ``openacademy/view/openacademy.xml``.
+        #. add them in the views.
 
         .. patch::
 
@@ -573,7 +574,8 @@ Relational field types are:
 
     .. only:: solutions
 
-        Modify the ``Course`` class as follows:
+        #. Modify the ``Course`` class, and
+        #. add the field in the course form view.
 
         .. patch::
 
@@ -582,32 +584,12 @@ Relational field types are:
     Using the relational field many2many, modify the *Session* model to relate
     every session to a set of *attendees*. Attendees will be represented by
     partner records, so we will relate to the built-in model ``res.partner``.
+    Adapt the views accordingly.
 
     .. only:: solutions
 
-        Modify the ``Session`` class as follows:
-
-        .. patch::
-
-.. exercise:: Views modification
-
-    For the *Course* model,
-
-    * the name and instructor for the course should be displayed in the tree
-      view
-    * the form view should display the course name and responsible at
-      the top, followed by the course description in a tab and the course
-      sessions in a second tab
-
-    For the *Session* model,
-
-    * the name of the session and the session course should be displayed in
-      the tree view
-    * the form view should display all the session's fields
-
-    Try to lay out the form views so that they're clear and readable.
-
-    .. only:: solutions
+        #. Modify the ``Session`` class, and
+        #. add the field in the form view.
 
         .. patch::
 
index e8242a4..b463bd6 100644 (file)
@@ -1,9 +1,22 @@
 Index: addons/openacademy/models.py
 ===================================================================
---- addons.orig/openacademy/models.py  2014-08-26 17:25:59.483783379 +0200
-+++ addons/openacademy/models.py       2014-08-26 17:25:59.479783379 +0200
+--- addons.orig/openacademy/models.py  2014-08-27 10:34:08.531934946 +0200
++++ addons/openacademy/models.py       2014-08-27 10:34:08.527934946 +0200
 @@ -25,3 +25,4 @@
      instructor_id = fields.Many2one('res.partner', string="Instructor")
      course_id = fields.Many2one('openacademy.course',
          ondelete='cascade', string="Course", required=True)
 +    attendee_ids = fields.Many2many('res.partner', string="Attendees")
+Index: addons/openacademy/views/openacademy.xml
+===================================================================
+--- addons.orig/openacademy/views/openacademy.xml      2014-08-27 10:34:08.531934946 +0200
++++ addons/openacademy/views/openacademy.xml   2014-08-27 10:34:08.527934946 +0200
+@@ -102,6 +102,8 @@
+                                 <field name="seats"/>
+                             </group>
+                         </group>
++                        <label for="attendee_ids"/>
++                        <field name="attendee_ids"/>
+                     </sheet>
+                 </form>
+             </field>
index 1029ffc..6eade5c 100644 (file)
@@ -3,8 +3,8 @@
 
 Index: addons/openacademy/models.py
 ===================================================================
---- addons.orig/openacademy/models.py  2014-08-26 17:25:57.515783409 +0200
-+++ addons/openacademy/models.py       2014-08-26 17:25:57.511783409 +0200
+--- addons.orig/openacademy/models.py  2014-08-27 10:37:10.135932250 +0200
++++ addons/openacademy/models.py       2014-08-27 10:37:10.131932250 +0200
 @@ -8,6 +8,9 @@
      name = fields.Char(string="Title", required=True)
      description = fields.Text()
@@ -25,22 +25,71 @@ Index: addons/openacademy/models.py
 +        ondelete='cascade', string="Course", required=True)
 Index: addons/openacademy/views/openacademy.xml
 ===================================================================
---- addons.orig/openacademy/views/openacademy.xml      2014-08-26 17:25:57.515783409 +0200
-+++ addons/openacademy/views/openacademy.xml   2014-08-26 17:25:57.511783409 +0200
-@@ -64,5 +64,16 @@
-         <!-- Full id location:
-              action="openacademy.course_list_action"
-              It is not required when it is the same module -->
+--- addons.orig/openacademy/views/openacademy.xml      2014-08-27 10:37:10.135932250 +0200
++++ addons/openacademy/views/openacademy.xml   2014-08-27 10:37:10.131932250 +0200
+@@ -9,6 +9,7 @@
+                     <sheet>
+                         <group>
+                             <field name="name"/>
++                            <field name="responsible_id"/>
+                         </group>
+                         <notebook>
+                             <page string="Description">
+@@ -34,6 +35,18 @@
+             </field>
+         </record>
++        <!-- override the automatically generated list view for courses -->
++        <record model="ir.ui.view" id="course_tree_view">
++            <field name="name">course.tree</field>
++            <field name="model">openacademy.course</field>
++            <field name="arch" type="xml">
++                <tree string="Course Tree">
++                    <field name="name"/>
++                    <field name="responsible_id"/>
++                </tree>
++            </field>
++        </record>
 +
-+        <record model="ir.actions.act_window" id="session_list_action">
-+            <field name="name">Sessions</field>
-+            <field name="res_model">openacademy.session</field>
-+            <field name="view_type">form</field>
-+            <field name="view_mode">tree,form</field>
+         <!-- window action -->
+         <!--
+             The following tag is an action definition for a "window action",
+@@ -73,16 +86,34 @@
+                 <form string="Session Form">
+                     <sheet>
+                         <group>
+-                            <field name="name"/>
+-                            <field name="start_date"/>
+-                            <field name="duration"/>
+-                            <field name="seats"/>
++                            <group string="General">
++                                <field name="course_id"/>
++                                <field name="name"/>
++                                <field name="instructor_id"/>
++                            </group>
++                            <group string="Schedule">
++                                <field name="start_date"/>
++                                <field name="duration"/>
++                                <field name="seats"/>
++                            </group>
+                         </group>
+                     </sheet>
+                 </form>
+             </field>
+         </record>
++        <!-- session tree/list view -->
++        <record model="ir.ui.view" id="session_tree_view">
++            <field name="name">session.tree</field>
++            <field name="model">openacademy.session</field>
++            <field name="arch" type="xml">
++                <tree string="Session Tree">
++                    <field name="name"/>
++                    <field name="course_id"/>
++                </tree>
++            </field>
 +        </record>
 +
-+        <menuitem id="session_menu" name="Sessions"
-+                  parent="openacademy_menu"
-+                  action="session_list_action"/>
-     </data>
- </openerp>
+         <record model="ir.actions.act_window" id="session_list_action">
+             <field name="name">Sessions</field>
+             <field name="res_model">openacademy.session</field>
index 6d5f18e..b067332 100644 (file)
@@ -3,8 +3,8 @@
 
 Index: addons/openacademy/models.py
 ===================================================================
---- addons.orig/openacademy/models.py  2014-08-26 17:25:58.455783395 +0200
-+++ addons/openacademy/models.py       2014-08-26 17:25:58.447783395 +0200
+--- addons.orig/openacademy/models.py  2014-08-27 10:37:24.591932036 +0200
++++ addons/openacademy/models.py       2014-08-27 10:37:24.583932036 +0200
 @@ -10,6 +10,8 @@
  
      responsible_id = fields.Many2one('res.users',
@@ -14,3 +14,23 @@ Index: addons/openacademy/models.py
  
  
  class Session(models.Model):
+Index: addons/openacademy/views/openacademy.xml
+===================================================================
+--- addons.orig/openacademy/views/openacademy.xml      2014-08-27 10:37:24.591932036 +0200
++++ addons/openacademy/views/openacademy.xml   2014-08-27 10:37:24.583932036 +0200
+@@ -15,8 +15,13 @@
+                             <page string="Description">
+                                 <field name="description"/>
+                             </page>
+-                            <page string="About">
+-                                This is an example of notebooks
++                            <page string="Sessions">
++                                <field name="session_ids">
++                                    <tree string="Registered sessions">
++                                        <field name="name"/>
++                                        <field name="instructor_id"/>
++                                    </tree>
++                                </field>
+                             </page>
+                         </notebook>
+                     </sheet>
index ec3c845..993ee0a 100644 (file)
@@ -2,8 +2,8 @@
 # Parent 22f8d180a7f9ad209d7e98cf7d1bd0fee1f05350
 Index: addons/openacademy/models.py
 ===================================================================
---- addons.orig/openacademy/models.py  2014-08-26 17:25:56.603783422 +0200
-+++ addons/openacademy/models.py       2014-08-26 17:25:56.595783422 +0200
+--- addons.orig/openacademy/models.py  2014-08-27 10:35:29.179933749 +0200
++++ addons/openacademy/models.py       2014-08-27 10:35:56.000000000 +0200
 @@ -7,3 +7,12 @@
  
      name = fields.Char(string="Title", required=True)
@@ -17,3 +17,42 @@ Index: addons/openacademy/models.py
 +    start_date = fields.Date()
 +    duration = fields.Float(digits=(6, 2), help="Duration in days")
 +    seats = fields.Integer(string="Number of seats")
+Index: addons/openacademy/views/openacademy.xml
+===================================================================
+--- addons.orig/openacademy/views/openacademy.xml      2014-08-27 10:35:29.179933749 +0200
++++ addons/openacademy/views/openacademy.xml   2014-08-27 10:36:54.643932480 +0200
+@@ -64,5 +64,34 @@
+         <!-- Full id location:
+              action="openacademy.course_list_action"
+              It is not required when it is the same module -->
++
++        <!-- session form view -->
++        <record model="ir.ui.view" id="session_form_view">
++            <field name="name">session.form</field>
++            <field name="model">openacademy.session</field>
++            <field name="arch" type="xml">
++                <form string="Session Form">
++                    <sheet>
++                        <group>
++                            <field name="name"/>
++                            <field name="start_date"/>
++                            <field name="duration"/>
++                            <field name="seats"/>
++                        </group>
++                    </sheet>
++                </form>
++            </field>
++        </record>
++
++        <record model="ir.actions.act_window" id="session_list_action">
++            <field name="name">Sessions</field>
++            <field name="res_model">openacademy.session</field>
++            <field name="view_type">form</field>
++            <field name="view_mode">tree,form</field>
++        </record>
++
++        <menuitem id="session_menu" name="Sessions"
++                  parent="openacademy_menu"
++                  action="session_list_action"/>
+     </data>
+ </openerp>
index 0206331..c21ba15 100644 (file)
@@ -9,7 +9,6 @@ exercise-session
 exercise-many2one
 exercise-one2many
 exercise-many2many
-exercise-o2m-views
 exercise-model-inheritance
 exercise-domain-basic
 exercise-domain-advanced