[FIX] website_forum_doc: default stage for post + removed unused import + added toc_id field in post tree view

This commit is contained in:
Thibault Delavallée 2014-09-03 10:15:06 +02:00
parent 78fa861936
commit 04d95c6a1a
2 changed files with 23 additions and 4 deletions

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import openerp
from openerp.osv import osv, fields from openerp.osv import osv, fields
class Documentation(osv.Model): class Documentation(osv.Model):
_name = 'forum.documentation.toc' _name = 'forum.documentation.toc'
_description = 'Documentation ToC' _description = 'Documentation ToC'
@ -10,12 +10,13 @@ class Documentation(osv.Model):
_order = "parent_left" _order = "parent_left"
_parent_order = "sequence, name" _parent_order = "sequence, name"
_parent_store = True _parent_store = True
def name_get(self, cr, uid, ids, context=None): def name_get(self, cr, uid, ids, context=None):
if isinstance(ids, (list, tuple)) and not len(ids): if isinstance(ids, (list, tuple)) and not len(ids):
return [] return []
if isinstance(ids, (long, int)): if isinstance(ids, (long, int)):
ids = [ids] 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 = [] res = []
for record in reads: for record in reads:
name = record['name'] name = record['name']
@ -50,6 +51,7 @@ class DocumentationStage(osv.Model):
_name = 'forum.documentation.stage' _name = 'forum.documentation.stage'
_description = 'Post Stage' _description = 'Post Stage'
_order = 'sequence' _order = 'sequence'
_columns = { _columns = {
'sequence': fields.integer('Sequence'), 'sequence': fields.integer('Sequence'),
'name': fields.char('Stage Name', required=True, translate=True), 'name': fields.char('Stage Name', required=True, translate=True),
@ -58,11 +60,20 @@ class DocumentationStage(osv.Model):
class Post(osv.Model): class Post(osv.Model):
_inherit = 'forum.post' _inherit = 'forum.post'
_columns = { _columns = {
'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC', ondelete='set null'), 'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC', ondelete='set null'),
'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage'), 'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage'),
'color': fields.integer('Color Index') '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): 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_obj = self.pool.get('forum.documentation.stage')
stage_ids = stage_obj.search(cr, uid, [], context=context) stage_ids = stage_obj.search(cr, uid, [], context=context)
@ -72,4 +83,3 @@ class Post(osv.Model):
_group_by_full = { _group_by_full = {
'documentation_stage_id': _read_group_stage_ids, 'documentation_stage_id': _read_group_stage_ids,
} }

View File

@ -87,7 +87,16 @@
</field> </field>
</record> </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> </data>
</openerp> </openerp>