Allow to use numeric type as property
This commit is contained in:
1 parent
b2bcb5ec7b
commit
58deecd279
3 files changed
+42
-29
No files matched your search
+23
-15
@@ -1,5 +1,6 @@
|
||||
"Properties"
|
||||
from trytond.osv import OSV, fields
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class Property(OSV):
|
||||
@@ -39,17 +40,6 @@ class Property(OSV):
|
||||
done[model_field.model.id] = True
|
||||
return res
|
||||
|
||||
def unlink(self, cursor, user, ids, context=None):
|
||||
if ids:
|
||||
cursor.execute('DELETE FROM ir_model_field ' \
|
||||
'WHERE id IN (' \
|
||||
'SELECT field FROM ir_property ' \
|
||||
'WHERE (field IS NOT NULL) ' \
|
||||
'AND (id IN (' + ','.join([str(x) for x in ids]) + \
|
||||
')))')
|
||||
res = super(Property, self).unlink(cursor, user, ids, context)
|
||||
return res
|
||||
|
||||
def get(self, cursor, user, name, model, res_ids=None, context=None):
|
||||
"""
|
||||
Return property value for each res_ids
|
||||
@@ -63,6 +53,7 @@ class Property(OSV):
|
||||
('name', '=', name),
|
||||
('model.model', '=', model),
|
||||
], limit=1, context=context)[0]
|
||||
field = model_field_obj.browse(cursor, user, field_id, context=context)
|
||||
|
||||
default_id = self.search(cursor, user, [
|
||||
('field', '=', field_id),
|
||||
@@ -72,7 +63,16 @@ class Property(OSV):
|
||||
if default_id:
|
||||
value = self.browse(cursor, user, default_id[0],
|
||||
context=context).value
|
||||
default_val = (value and int(value.split(',')[1])) or False
|
||||
val = False
|
||||
if value:
|
||||
if value.split(',')[0]:
|
||||
val = int(value.split(',')[1])
|
||||
else:
|
||||
if field.ttype == 'numeric':
|
||||
val = Decimal(value.split(',')[1])
|
||||
else:
|
||||
raise Exception('Not implemented')
|
||||
default_val = val
|
||||
|
||||
if not res_ids:
|
||||
return default_val
|
||||
@@ -86,8 +86,16 @@ class Property(OSV):
|
||||
for obj_id in res_ids]),
|
||||
])
|
||||
for prop in self.browse(cursor, user, property_ids):
|
||||
res[int(prop.res.split(',')[1])] = (prop.value and \
|
||||
int(prop.value.split(',')[1])) or False
|
||||
val = False
|
||||
if prop.value:
|
||||
if prop.value.split(',')[0]:
|
||||
val = int(prop.value.split(',')[1])
|
||||
else:
|
||||
if field.ttype == 'numeric':
|
||||
val = Decimal(prop.value.split(',')[1])
|
||||
else:
|
||||
raise Exception('Not implemented')
|
||||
res[int(prop.res.split(',')[1])] = val
|
||||
|
||||
return res
|
||||
|
||||
@@ -103,7 +111,7 @@ class Property(OSV):
|
||||
|
||||
property_ids = self.search(cursor, user, [
|
||||
('field', '=', field_id),
|
||||
('res', '=', name + ',' + str(res_id)),
|
||||
('res', '=', model + ',' + str(res_id)),
|
||||
], context=context)
|
||||
self.unlink(cursor, user, property_ids, context=context)
|
||||
|
||||
|
||||
+16
-11
@@ -293,6 +293,9 @@ class Many2One(Column):
|
||||
_classic_read = False
|
||||
_classic_write = True
|
||||
_type = 'many2one'
|
||||
_symbol_c = '%s'
|
||||
_symbol_f = lambda x: x and int(x) or None
|
||||
_symbol_set = (_symbol_c, _symbol_f)
|
||||
|
||||
def __init__(self, obj, string='unknown', **args):
|
||||
Column.__init__(self, string=string, **args)
|
||||
@@ -560,6 +563,7 @@ class Function(Column):
|
||||
self._fnct = fnct
|
||||
self._fnct_inv = fnct_inv
|
||||
self._arg = arg
|
||||
self._obj = ''
|
||||
if 'relation' in args:
|
||||
self._obj = args['relation']
|
||||
self._fnct_inv_arg = fnct_inv_arg
|
||||
@@ -603,16 +607,17 @@ class Property(Function):
|
||||
res = property_obj.get(cursor, user, prop, obj._name, ids,
|
||||
context=context)
|
||||
|
||||
obj = obj.pool.get(self._obj)
|
||||
obj_names = {}
|
||||
for obj_id, obj_name in obj.name_get(cursor, user,
|
||||
[x for x in res.values() if x], context=context):
|
||||
obj_names[obj_id] = obj_name
|
||||
for i in ids:
|
||||
if res.get(i) and res[i] in obj_names:
|
||||
res[i] = (res[i], obj_names[res[i]])
|
||||
else:
|
||||
res[i] = False
|
||||
if self._obj:
|
||||
obj = obj.pool.get(self._obj)
|
||||
obj_names = {}
|
||||
for obj_id, obj_name in obj.name_get(cursor, user,
|
||||
[x for x in res.values() if x], context=context):
|
||||
obj_names[obj_id] = obj_name
|
||||
for i in ids:
|
||||
if res.get(i) and res[i] in obj_names:
|
||||
res[i] = (res[i], obj_names[res[i]])
|
||||
else:
|
||||
res[i] = False
|
||||
return res
|
||||
|
||||
def __init__(self, **args):
|
||||
@@ -625,6 +630,6 @@ class Property(Function):
|
||||
|
||||
def set(self, cursor, obj, obj_id, name, value, user=None, context=None):
|
||||
self._fnct_write(obj, cursor, user, obj_id, name, value,
|
||||
self._fnct_inv_arg, context=context)
|
||||
self._obj, context=context)
|
||||
|
||||
property = Property
|
||||
+3
-3
@@ -284,12 +284,12 @@ class ORM(object):
|
||||
"relation, group_name, view_load, help) " \
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
|
||||
(model_id, k, field.string, field._type,
|
||||
field._obj or 'NULL', field.group_name or '',
|
||||
field._obj or '', field.group_name or '',
|
||||
(field.view_load and 'True') or 'False',
|
||||
field.help))
|
||||
elif columns[k]['field_description'] != field.string \
|
||||
or columns[k]['ttype'] != field._type \
|
||||
or columns[k]['relation'] != (field._obj or 'NULL') \
|
||||
or columns[k]['relation'] != (field._obj or '') \
|
||||
or columns[k]['group_name'] != (field.group_name or '') \
|
||||
or columns[k]['view_load'] != \
|
||||
((field.view_load and 'True') or 'False') \
|
||||
@@ -302,7 +302,7 @@ class ORM(object):
|
||||
'view_load = %s, ' \
|
||||
'help = %s ' \
|
||||
'WHERE id = %s ',
|
||||
(field.string, field._type, field._obj or 'NULL',
|
||||
(field.string, field._type, field._obj or '',
|
||||
field.group_name or '',
|
||||
(field.view_load and 'True') or 'False',
|
||||
field.help, columns[k]['id']))
|
||||
|
||||
Reference in new issue
Block a user