check recursion in parent_id and improved usability
bzr revid: hda@hda-laptop-20110414133510-znhaez2d9020n3sd
This commit is contained in:
@@ -31,11 +31,28 @@ DefaultVoteValue = '50'
|
||||
class idea_category(osv.osv):
|
||||
""" Category of Idea """
|
||||
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
if not len(ids):
|
||||
return []
|
||||
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
|
||||
res = []
|
||||
for record in reads:
|
||||
name = record['name']
|
||||
if record['parent_id']:
|
||||
name = record['parent_id'][1]+' / '+name
|
||||
res.append((record['id'], name))
|
||||
return res
|
||||
|
||||
def _categ_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
|
||||
res = self.name_get(cr, uid, ids, context=context)
|
||||
return dict(res)
|
||||
|
||||
_name = "idea.category"
|
||||
_description = "Idea Category"
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Category', size=64, required=True),
|
||||
'complete_name': fields.function(_categ_name_get_fnc, method=True, type="char", string='Name'),
|
||||
'summary': fields.text('Summary'),
|
||||
'parent_id': fields.many2one('idea.category', 'Parent Categories', ondelete='set null'),
|
||||
'child_ids': fields.one2many('idea.category', 'parent_id', 'Child Categories'),
|
||||
@@ -46,6 +63,10 @@ class idea_category(osv.osv):
|
||||
]
|
||||
_order = 'parent_id,name asc'
|
||||
|
||||
_constraints = [
|
||||
(osv.osv._check_recursion, 'Error ! You can not create recursive categories.', ['parent_id'])
|
||||
]
|
||||
|
||||
idea_category()
|
||||
|
||||
class idea_idea(osv.osv):
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<field name="field_parent">child_ids</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Category of ideas">
|
||||
<field name="name"/>
|
||||
<field name="complete_name"/>
|
||||
<field name="parent_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -234,11 +234,11 @@
|
||||
<field name="count_votes" />
|
||||
</group>
|
||||
<field name="stat_vote_ids" colspan="4" mode="graph,tree" nolabel="1">
|
||||
<graph string="Vots Statistics" type="bar">
|
||||
<graph string="Votes Statistics" type="bar">
|
||||
<field name="score"/>
|
||||
<field name="nbr"/>
|
||||
</graph>
|
||||
<tree string="Vots Statistics">
|
||||
<tree string="Votes Statistics">
|
||||
<field name="score"/>
|
||||
<field name="nbr"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user