Creating new objects
bzr revid: fp@tinyerp.com-94e557aa5ec9f39bf119e161bda8f33c9f568fc2
This commit is contained in:
parent
0b8afcefc0
commit
b056a18630
|
@ -186,6 +186,7 @@ def load_module_graph(cr, graph, status=None, **kwargs):
|
|||
# **kwargs is passed directly to convert_xml_import
|
||||
if not status:
|
||||
status={}
|
||||
|
||||
status = status.copy()
|
||||
package_todo = []
|
||||
statusi = 0
|
||||
|
@ -235,6 +236,11 @@ def load_module_graph(cr, graph, status=None, **kwargs):
|
|||
statusi+=1
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
cr.execute('select * from ir_model where state=%s', ('manual',))
|
||||
for model in cr.dictfetchall():
|
||||
print 'INSTANCIATE', model['model']
|
||||
pool.get('ir.model').instanciate(cr, 1, model['model'], {})
|
||||
|
||||
pool.get('ir.model.data')._process_end(cr, 1, package_todo)
|
||||
cr.commit()
|
||||
|
||||
|
|
|
@ -726,6 +726,7 @@
|
|||
<field name="selection"/>
|
||||
<field name="domain"/>
|
||||
<field name="state" readonly="1"/>
|
||||
<button name="%(base.menu_create)d" string="Create Menu" colspan="2" type="action"/>
|
||||
</form>
|
||||
</field>
|
||||
<separator string="Status" colspan="4"/>
|
||||
|
|
|
@ -43,10 +43,10 @@ class ir_model(osv.osv):
|
|||
_rec_name = 'model'
|
||||
_columns = {
|
||||
'name': fields.char('Model name', size=64, translate=True),
|
||||
'model': fields.char('Object name', size=64, required=True),
|
||||
'model': fields.char('Object name', size=64, required=True, search=1),
|
||||
'info': fields.text('Information'),
|
||||
'field_id': fields.one2many('ir.model.fields', 'model_id', 'Fields', required=True),
|
||||
'state': fields.selection([('manual','Custom Field'),('base','Base Field')],'Manualy Created'),
|
||||
'state': fields.selection([('manual','Custom Field'),('base','Base Field')],'Manualy Created',readonly=1),
|
||||
}
|
||||
_defaults = {
|
||||
'name': lambda *a: 'No Name',
|
||||
|
@ -64,18 +64,18 @@ class ir_model(osv.osv):
|
|||
vals['state']='manual'
|
||||
res = super(ir_model,self).create(cr, user, vals, context)
|
||||
if vals.get('state','base')=='manual':
|
||||
if not vals['name'].startswith('x_'):
|
||||
if not vals['model'].startswith('x_'):
|
||||
raise except_orm('Error', "Custom models must have an object name that starts with 'x_' !")
|
||||
# self.pool.get(vals['model']).__init__(self.pool, cr)
|
||||
# self.pool.get(vals['model'])._auto_init(cr)
|
||||
pooler.restart_pool(cr.dbname)
|
||||
return res
|
||||
|
||||
# def instanciate(self, cr, user, models):
|
||||
# class inst_obj(osv.osv):
|
||||
# def __init__():
|
||||
# pass
|
||||
# for model in models:
|
||||
# self.pool.add(model, inst_moed)
|
||||
def instanciate(self, cr, user, model, context={}):
|
||||
class x_custom_model(osv.osv):
|
||||
pass
|
||||
x_custom_model._name = model
|
||||
x_custom_model._module = False
|
||||
x_custom_model._rec_name = 'id'
|
||||
x_custom_model.createInstance(self.pool, '', cr)
|
||||
ir_model()
|
||||
|
||||
class ir_model_fields(osv.osv):
|
||||
|
@ -96,7 +96,7 @@ class ir_model_fields(osv.osv):
|
|||
'translate': fields.boolean('Translate'),
|
||||
'size': fields.integer('Size'),
|
||||
'state': fields.selection([('manual','Custom Field'),('base','Base Field')],'Manualy Created'),
|
||||
'on_delete': fields.selection([('no','Nothing'),('cascade','Cascade'),('set null','Set NULL')], 'On delete', help='On delete property for many2one fields'),
|
||||
'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),
|
||||
|
||||
'groups': fields.many2many('res.groups', 'ir_model_fields_group_rel', 'field_id', 'group_id', 'Groups'),
|
||||
|
@ -110,10 +110,10 @@ class ir_model_fields(osv.osv):
|
|||
'domain': lambda *a: "[]",
|
||||
'name': lambda *a: 'x_',
|
||||
'state': lambda self,cr,uid,ctx={}: (ctx and ctx.get('manual',False)) and 'manual' or 'base',
|
||||
'on_delete': lambda *a: 'no',
|
||||
'on_delete': lambda *a: 'set null',
|
||||
'select_level': lambda *a: '0',
|
||||
'size': lambda *a: 64,
|
||||
'field_description': lambda *a: 'No',
|
||||
'field_description': lambda *a: '',
|
||||
}
|
||||
_order = "id"
|
||||
def unlink(self, cr, user, ids, context=None):
|
||||
|
@ -135,6 +135,7 @@ class ir_model_fields(osv.osv):
|
|||
if vals.get('state','base')=='manual':
|
||||
if not vals['name'].startswith('x_'):
|
||||
raise except_orm('Error', "Custom fields must have a name that starts with 'x_' !")
|
||||
print vals['model']
|
||||
self.pool.get(vals['model']).__init__(self.pool, cr)
|
||||
self.pool.get(vals['model'])._auto_init(cr)
|
||||
return res
|
||||
|
|
|
@ -551,11 +551,16 @@ class orm(object):
|
|||
'size': field['size'],
|
||||
'ondelete': field['on_delete'],
|
||||
'translate': (field['translate']),
|
||||
'select': int(field['select_level'])
|
||||
#'select': int(field['select_level'])
|
||||
}
|
||||
if field['relation']:
|
||||
attrs['relation'] = field['relation']
|
||||
self._columns[field['name']] = getattr(fields, field['ttype'])(**attrs)
|
||||
#if field['relation']:
|
||||
# attrs['relation'] = field['relation']
|
||||
if field['ttype'] == 'selection':
|
||||
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)
|
||||
else:
|
||||
self._columns[field['name']] = getattr(fields, field['ttype'])(**attrs)
|
||||
|
||||
self._inherits_reload()
|
||||
if not self._sequence:
|
||||
|
|
|
@ -208,7 +208,6 @@ class osv_pool(netsvc.Service):
|
|||
|
||||
class osv(orm.orm):
|
||||
#__metaclass__ = inheritor
|
||||
|
||||
def __new__(cls):
|
||||
module = str(cls)[6:]
|
||||
module = module[:len(module)-1]
|
||||
|
|
Loading…
Reference in New Issue