diff options
| author | Fabien Pinckaers <fp@tinyerp.com> | 2008-04-13 06:54:08 +0000 |
|---|---|---|
| committer | Fabien Pinckaers <fp@tinyerp.com> | 2008-04-13 06:54:08 +0000 |
| commit | f7a43ea577fe78f47e6da2c3de27de94ae2d358d (patch) | |
| tree | 0718e4851aca32b32c2135a045d1609a6c440c0d /bin | |
| parent | 776ab5c235b3e30c8f667b5499f879cb09b56c42 (diff) | |
Improvements for creating objects
bzr revid: fp@tinyerp.com-240c41f315d5c5614d3259529b922e05be57908b
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/addons/base/ir/ir.xml | 2 | ||||
| -rw-r--r-- | bin/addons/base/ir/ir_model.py | 28 |
2 files changed, 28 insertions, 2 deletions
diff --git a/bin/addons/base/ir/ir.xml b/bin/addons/base/ir/ir.xml index b4202c4b163..fdeb93cc942 100644 --- a/bin/addons/base/ir/ir.xml +++ b/bin/addons/base/ir/ir.xml @@ -728,6 +728,8 @@ <field name="state" readonly="1"/> </form> </field> + <separator string="Status" colspan="4"/> + <field name="state"/> </form> </field> </record> diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 9297d566f02..7945aaf0a7d 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -46,13 +46,37 @@ class ir_model(osv.osv): 'model': fields.char('Object name', size=64, required=True), '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'), } _defaults = { 'name': lambda *a: 'No Name', + 'model': lambda *a: 'x_', + 'state': lambda self,cr,uid,ctx={}: (ctx and ctx.get('manual',False)) and 'manual' or 'base', } -ir_model() + 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,)) + return super(ir_model, self).unlink(cr, user, ids, context) + + def create(self, cr, user, vals, context=None): + if context and context.get('manual',False): + 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_'): + 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) + return res -print 'MODEL' +# def instanciate(self, cr, user, models): +# class inst_obj(osv.osv): +# def __init__(): +# pass +# for model in models: +# self.pool.add(model, inst_moed) +ir_model() class ir_model_fields(osv.osv): _name = 'ir.model.fields' |
