fix:Displayed required and readonly attributes of a model.
bzr revid: jvo@tinyerp.com-20080922064849-q2wphtmsblxjn1yl
This commit is contained in:
parent
f2209f5e12
commit
68dd2596bf
|
@ -28,11 +28,11 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
import ir_model
|
||||||
import ir_sequence
|
import ir_sequence
|
||||||
import ir_ui_menu
|
import ir_ui_menu
|
||||||
import ir_ui_view
|
import ir_ui_view
|
||||||
import ir_default
|
import ir_default
|
||||||
import ir_model
|
|
||||||
import ir_actions
|
import ir_actions
|
||||||
import ir_report_custom
|
import ir_report_custom
|
||||||
import ir_attachment
|
import ir_attachment
|
||||||
|
|
|
@ -268,13 +268,13 @@ class ir_model_access(osv.osv):
|
||||||
'perm_create': fields.boolean('Create Access'),
|
'perm_create': fields.boolean('Create Access'),
|
||||||
'perm_unlink': fields.boolean('Delete Permission'),
|
'perm_unlink': fields.boolean('Delete Permission'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def check_groups(self, cr, uid, group):
|
def check_groups(self, cr, uid, group):
|
||||||
res = False
|
res = False
|
||||||
grouparr = group.split('.')
|
grouparr = group.split('.')
|
||||||
if grouparr:
|
if grouparr:
|
||||||
cr.execute("select * from res_groups_users_rel where uid=" + str(uid) + " and gid in(select res_id from ir_model_data where module=%s and name=%s)", (grouparr[0], grouparr[1],))
|
cr.execute("select * from res_groups_users_rel where uid=" + str(uid) + " and gid in(select res_id from ir_model_data where module=%s and name=%s)", (grouparr[0], grouparr[1],))
|
||||||
r = cr.fetchall()
|
r = cr.fetchall()
|
||||||
if not r:
|
if not r:
|
||||||
res = False
|
res = False
|
||||||
else:
|
else:
|
||||||
|
@ -282,30 +282,30 @@ class ir_model_access(osv.osv):
|
||||||
else:
|
else:
|
||||||
res = False
|
res = False
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def check_groups_by_id(self, cr, uid, group_id):
|
def check_groups_by_id(self, cr, uid, group_id):
|
||||||
cr.execute("select * from res_groups_users_rel where uid=%i and gid=%i", (uid, group_id,))
|
cr.execute("select * from res_groups_users_rel where uid=%i and gid=%i", (uid, group_id,))
|
||||||
r = cr.fetchall()
|
r = cr.fetchall()
|
||||||
if not r:
|
if not r:
|
||||||
res = False
|
res = False
|
||||||
else:
|
else:
|
||||||
res = True
|
res = True
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def check(self, cr, uid, model_name, mode='read',raise_exception=True):
|
def check(self, cr, uid, model_name, mode='read',raise_exception=True):
|
||||||
# Users root have all access (Todo: exclude xml-rpc requests)
|
# Users root have all access (Todo: exclude xml-rpc requests)
|
||||||
if uid==1:
|
if uid==1:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
assert mode in ['read','write','create','unlink'], 'Invalid access mode'
|
assert mode in ['read','write','create','unlink'], 'Invalid access mode'
|
||||||
|
|
||||||
# We check if a specific rule exists
|
# We check if a specific rule exists
|
||||||
cr.execute('SELECT MAX(CASE WHEN perm_'+mode+' THEN 1 else 0 END) '
|
cr.execute('SELECT MAX(CASE WHEN perm_'+mode+' THEN 1 else 0 END) '
|
||||||
'from ir_model_access a join ir_model m on (m.id=a.model_id) '
|
'from ir_model_access a join ir_model m on (m.id=a.model_id) '
|
||||||
'join res_groups_users_rel gu on (gu.gid = a.group_id) '
|
'join res_groups_users_rel gu on (gu.gid = a.group_id) '
|
||||||
'where m.model=%s and gu.uid=%s', (model_name, uid,))
|
'where m.model=%s and gu.uid=%s', (model_name, uid,))
|
||||||
r = cr.fetchall()
|
r = cr.fetchall()
|
||||||
|
|
||||||
if not r[0][0]:
|
if not r[0][0]:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
msgs = {
|
msgs = {
|
||||||
|
@ -382,7 +382,7 @@ class ir_model_data(osv.osv):
|
||||||
def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False):
|
def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False):
|
||||||
warning = True
|
warning = True
|
||||||
model_obj = self.pool.get(model)
|
model_obj = self.pool.get(model)
|
||||||
context = {}
|
context = {}
|
||||||
if xml_id and ('.' in xml_id):
|
if xml_id and ('.' in xml_id):
|
||||||
assert len(xml_id.split('.'))==2, _('"%s" contains too many dots. XML ids should not contain dots ! These are used to refer to other modules data, as in module.reference_id') % (xml_id)
|
assert len(xml_id.split('.'))==2, _('"%s" contains too many dots. XML ids should not contain dots ! These are used to refer to other modules data, as in module.reference_id') % (xml_id)
|
||||||
warning = False
|
warning = False
|
||||||
|
@ -544,7 +544,7 @@ class ir_model_config(osv.osv):
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'target':'new',
|
'target':'new',
|
||||||
}
|
}
|
||||||
|
|
||||||
def action_update_pw(self, cr, uid, ids, context={}):
|
def action_update_pw(self, cr, uid, ids, context={}):
|
||||||
res = self.read(cr,uid,ids)[0]
|
res = self.read(cr,uid,ids)[0]
|
||||||
root = self.pool.get('res.users').browse(cr, uid, [1])[0]
|
root = self.pool.get('res.users').browse(cr, uid, [1])[0]
|
||||||
|
|
|
@ -324,7 +324,9 @@ class orm_template(object):
|
||||||
'relate': (f.relate and 1) or 0,
|
'relate': (f.relate and 1) or 0,
|
||||||
'relation': f._obj or 'NULL',
|
'relation': f._obj or 'NULL',
|
||||||
'view_load': (f.view_load and 1) or 0,
|
'view_load': (f.view_load and 1) or 0,
|
||||||
'select_level': str(f.select or 0)
|
'select_level': str(f.select or 0),
|
||||||
|
'readonly':(f.readonly and 1) or 0,
|
||||||
|
'required':(f.required and 1) or 0,
|
||||||
}
|
}
|
||||||
if k not in cols:
|
if k not in cols:
|
||||||
cr.execute('select nextval(%s)', ('ir_model_fields_id_seq',))
|
cr.execute('select nextval(%s)', ('ir_model_fields_id_seq',))
|
||||||
|
@ -334,7 +336,7 @@ class orm_template(object):
|
||||||
id, model_id, model, name, field_description, ttype,
|
id, model_id, model, name, field_description, ttype,
|
||||||
relate,relation,view_load,state,select_level
|
relate,relation,view_load,state,select_level
|
||||||
) VALUES (
|
) VALUES (
|
||||||
%d,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s
|
%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s
|
||||||
)""", (
|
)""", (
|
||||||
id, vals['model_id'], vals['model'], vals['name'], vals['field_description'], vals['ttype'],
|
id, vals['model_id'], vals['model'], vals['name'], vals['field_description'], vals['ttype'],
|
||||||
bool(vals['relate']), vals['relation'], bool(vals['view_load']), 'base',
|
bool(vals['relate']), vals['relation'], bool(vals['view_load']), 'base',
|
||||||
|
@ -351,12 +353,12 @@ class orm_template(object):
|
||||||
cr.commit()
|
cr.commit()
|
||||||
cr.execute("""UPDATE ir_model_fields SET
|
cr.execute("""UPDATE ir_model_fields SET
|
||||||
model_id=%s, field_description=%s, ttype=%s, relate=%s, relation=%s,
|
model_id=%s, field_description=%s, ttype=%s, relate=%s, relation=%s,
|
||||||
view_load=%s, select_level=%s
|
view_load=%s, select_level=%s, readonly=%s ,required=%s
|
||||||
WHERE
|
WHERE
|
||||||
model=%s AND name=%s""", (
|
model=%s AND name=%s""", (
|
||||||
vals['model_id'], vals['field_description'], vals['ttype'], bool(vals['relate']),
|
vals['model_id'], vals['field_description'], vals['ttype'], bool(vals['relate']),
|
||||||
vals['relation'], bool(vals['view_load']),
|
vals['relation'], bool(vals['view_load']),
|
||||||
vals['select_level'], vals['model'], vals['name']
|
vals['select_level'], bool(vals['readonly']),bool(vals['required']), vals['model'], vals['name']
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
|
Loading…
Reference in New Issue