[FIX] website_forum_doc: default stage for post + removed unused import + added toc_i...
authorThibault Delavallée <tde@openerp.com>
Wed, 3 Sep 2014 08:15:06 +0000 (10:15 +0200)
committerThibault Delavallée <tde@openerp.com>
Wed, 3 Sep 2014 08:39:30 +0000 (10:39 +0200)
addons/website_forum_doc/models/documentation.py
addons/website_forum_doc/views/doc.xml

index 655040f..773ec46 100644 (file)
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 
-import openerp
 from openerp.osv import osv, fields
 
+
 class Documentation(osv.Model):
     _name = 'forum.documentation.toc'
     _description = 'Documentation ToC'
@@ -10,12 +10,13 @@ class Documentation(osv.Model):
     _order = "parent_left"
     _parent_order = "sequence, name"
     _parent_store = True
+
     def name_get(self, cr, uid, ids, context=None):
         if isinstance(ids, (list, tuple)) and not len(ids):
             return []
         if isinstance(ids, (long, int)):
             ids = [ids]
-        reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
+        reads = self.read(cr, uid, ids, ['name', 'parent_id'], context=context)
         res = []
         for record in reads:
             name = record['name']
@@ -50,6 +51,7 @@ class DocumentationStage(osv.Model):
     _name = 'forum.documentation.stage'
     _description = 'Post Stage'
     _order = 'sequence'
+
     _columns = {
         'sequence': fields.integer('Sequence'),
         'name': fields.char('Stage Name', required=True, translate=True),
@@ -58,11 +60,20 @@ class DocumentationStage(osv.Model):
 
 class Post(osv.Model):
     _inherit = 'forum.post'
+
     _columns = {
         'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC', ondelete='set null'),
         'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage'),
         'color': fields.integer('Color Index')
     }
+
+    def _get_documentation_stage(self, cr, uid, context=None):
+        return self.pool["forum.documentation.stage"].search(cr, uid, [], limit=1, context=context) or False
+
+    _defaults = {
+        'documentation_stage_id': _get_documentation_stage,
+    }
+
     def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
         stage_obj = self.pool.get('forum.documentation.stage')
         stage_ids = stage_obj.search(cr, uid, [], context=context)
@@ -72,4 +83,3 @@ class Post(osv.Model):
     _group_by_full = {
         'documentation_stage_id': _read_group_stage_ids,
     }
-
index 2e21f0b..e073090 100644 (file)
             </field>
         </record>
 
-
+        <record id="view_forum_post_doc_list" model="ir.ui.view">
+            <field name="name">forum.post.list.doc</field>
+            <field name="model">forum.post</field>
+            <field name="inherit_id" ref="website_forum.view_forum_post_list"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='forum_id']" position="after">
+                    <field name="documentation_toc_id"/>
+                </xpath>
+            </field>
+        </record>
 
     </data>
 </openerp>