* Support for adding custom O2M & M2M fields

* Improved fields view definitions

bzr revid: ame@tinyerp.com-20081023132828-nvjtv26qna56cztk
This commit is contained in:
Amit Mendapara 2008-10-23 18:58:28 +05:30
parent cf3ef5d59d
commit 08e80733c4
3 changed files with 27 additions and 12 deletions

View File

@ -647,11 +647,14 @@
<group colspan="2" col="2">
<separator string="Field Type" colspan="2"/>
<field name="ttype" select="2"/>
<field name="relation" select="2"/>
<field name="selection"/>
<field name="size"/>
<field name="relation" select="2" attrs="{'required': [('ttype','in',['many2one','one2many','many2many'])],
'readonly': [('ttype','not in', ['many2one','one2many','many2many'])]}"/>
<field name="relation_field" attrs="{'required': [('ttype','=','one2many')],
'readonly': [('ttype','!=','one2many')]}"/>
<field name="selection" attrs="{'required': [('ttype','=','selection')], 'readonly': [('ttype','!=','selection')]}"/>
<field name="size" attrs="{'required': [('ttype','=','char')], 'readonly': [('ttype','!=','char')]}"/>
<field name="state"/>
<field name="domain"/>
<field name="domain" attrs="{'readonly': [('relation','=','')]}"/>
</group>
<group colspan="2" col="2">
@ -661,7 +664,7 @@
<field name="select_level"/>
<field name="translate"/>
<field name="relate"/>
<field name="on_delete"/>
<field name="on_delete" attrs="{'readonly': [('ttype','!=','many2one')]}"/>
</group>
<separator string="Security on Groups" colspan="4"/>
<field name="groups" colspan="4" nolabel="1"/>
@ -724,11 +727,14 @@
<page string="Properties">
<group colspan="2" col="2">
<field name="ttype" select="2"/>
<field name="relation" select="2"/>
<field name="selection"/>
<field name="size"/>
<field name="relation" select="2" attrs="{'required': [('ttype','in', ['many2one','one2many','many2many'])],
'readonly': [('ttype','not in', ['many2one','one2many','many2many'])]}"/>
<field name="relation_field" attrs="{'required': [('ttype','=','one2many')],
'readonly': [('ttype','!=','one2many')]}"/>
<field name="selection" attrs="{'required': [('ttype','=','selection')], 'readonly': [('ttype','!=','selection')]}"/>
<field name="size" attrs="{'required': [('ttype','=','char')], 'readonly': [('ttype','!=','char')]}"/>
<field name="state"/>
<field name="domain"/>
<field name="domain" attrs="{'readonly': [('relation','=','')]}"/>
</group>
<group colspan="2" col="2">
@ -737,7 +743,7 @@
<field name="select_level"/>
<field name="translate"/>
<field name="relate"/>
<field name="on_delete"/>
<field name="on_delete" attrs="{'readonly': [('ttype','!=','many2one')]}"/>
</group>
</page>
<page string="Security on Groups" colspan="4">

View File

@ -72,7 +72,7 @@ class ir_model(osv.osv):
def unlink(self, cr, user, ids, context=None):
for model in self.browse(cr, user, ids, context):
if model.state <> 'manual':
raise except_orm(_('Error'), _("You can not remove the model '%s' !") %(field.name,))
raise except_orm(_('Error'), _("You can not remove the model '%s' !") %(model.name,))
res = super(ir_model, self).unlink(cr, user, ids, context)
pooler.restart_pool(cr.dbname)
return res
@ -201,6 +201,7 @@ class ir_model_fields(osv.osv):
'name': fields.char('Name', required=True, size=64, select=1),
'model': fields.char('Object Name', size=64, required=True),
'relation': fields.char('Object Relation', size=64),
'relation_field': fields.char('Relation Field', size=64),
'model_id': fields.many2one('ir.model', 'Object id', required=True, select=True, ondelete='cascade'),
'field_description': fields.char('Field Label', required=True, size=256),
'relate': fields.boolean('Click and Relate'),
@ -212,7 +213,7 @@ class ir_model_fields(osv.osv):
'select_level': fields.selection([('0','Not Searchable'),('1','Always Searchable'),('2','Advanced Search')],'Searchable', required=True),
'translate': fields.boolean('Translate'),
'size': fields.integer('Size'),
'state': fields.selection([('manual','Custom Field'),('base','Base Field')],'Manualy Created'),
'state': fields.selection([('manual','Custom Field'),('base','Base Field')],'Manualy Created', required=True, readonly=True),
'on_delete': fields.selection([('cascade','Cascade'),('set null','Set NULL')], 'On delete', help='On delete property for many2one fields'),
'domain': fields.char('Domain', size=256),

View File

@ -1594,6 +1594,14 @@ class orm(orm_template):
self._columns[field['name']] = getattr(fields, field['ttype'])(eval(field['selection']), **attrs)
elif field['ttype'] == 'many2one':
self._columns[field['name']] = getattr(fields, field['ttype'])(field['relation'], **attrs)
elif field['ttype'] == 'one2many':
self._columns[field['name']] = getattr(fields, field['ttype'])(field['relation'], field['relation_field'], **attrs)
elif field['ttype'] == 'many2many':
import random
_rel1 = field['relation'].replace('.', '_')
_rel2 = field['model'].replace('.', '_')
_rel_name = 'x_%s_%s_%s_rel' %(_rel1, _rel2, random.randint(0, 10000))
self._columns[field['name']] = getattr(fields, field['ttype'])(field['relation'], _rel_name, 'id1', 'id2', **attrs)
else:
self._columns[field['name']] = getattr(fields, field['ttype'])(**attrs)