From 9d2f8665100bc2253ed4737f4c7c4b8c67265d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 21 Apr 2008 23:50:14 +0200 Subject: [PATCH 1/5] Add Decimal in eval context for default value --- trytond/ir/default.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trytond/ir/default.py b/trytond/ir/default.py index ff48bfbc10..4e29b90377 100644 --- a/trytond/ir/default.py +++ b/trytond/ir/default.py @@ -1,5 +1,6 @@ "Default" from trytond.osv import fields, OSV +from decimal import Decimal class Default(OSV): @@ -37,6 +38,8 @@ class Default(OSV): test_clause = False continue break + ctx = {} + ctx['Decimal'] = Decimal for default in self.browse(cursor, user, default_ids, context=context): if default.field.name not in res: res[default.field.name] = eval(default.value) From 2b10d7e061704816d77d6af35ec78c1a37d1cb1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 21 Apr 2008 23:51:18 +0200 Subject: [PATCH 2/5] Call on_change fonction after default_get to prevent the client to call it. --- trytond/osv/orm.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/trytond/osv/orm.py b/trytond/osv/orm.py index cc6ad1ba3c..1e67661ae9 100644 --- a/trytond/osv/orm.py +++ b/trytond/osv/orm.py @@ -1208,6 +1208,9 @@ class ORM(object): obj = self.pool.get(fld_def._obj) if not obj.search(cursor, user, [('id', '=', field_value)]): continue + if isinstance(field_value, (int, long)): + field_value = obj.name_get(cursor, user, field_value, + context=context)[0] if fld_def._type in ('many2many'): obj = self.pool.get(fld_def._obj) field_value2 = [] @@ -1220,7 +1223,7 @@ class ORM(object): if fld_def._type in ('one2many'): obj = self.pool.get(fld_def._obj) field_value2 = [] - for i in range(len(field_value)): + for i in range(len(field_value or [])): field_value2.append({}) for field2 in field_value[i]: if obj._columns[field2]._type \ @@ -1229,12 +1232,41 @@ class ORM(object): if not obj2.search(cursor, user, [('id', '=', field_value[i][field2])]): continue + if isinstance(field_value[i][field2], + (int, long)): + field_value[i][field2] = obj2.name_get( + cursor, user, + field_value[i][field2], + context=context)[0] # TODO add test for many2many and one2many field_value2[i][field2] = field_value[i][field2] field_value = field_value2 value[field] = field_value + value = self._default_on_change(cursor, user, value, context=context) return value + def _default_on_change(self, cursor, user, value, context=None): + res = value.copy() + val = {} + for i in self._inherits.keys(): + val.update(self.pool.get(i)._default_on_change(cursor, user, + value, context=context)) + for field in value.keys(): + if field in self._columns: + if self._columns[field].on_change: + args = {} + for arg in self._columns[field].on_change: + args[arg] = value.get(arg, False) + val.update(getattr(self, 'on_change_' + field)(cursor, user, + [], args, context=context)) + if self._columns[field]._type in ('many2many', 'one2many'): + obj = self.pool.get(self._columns[field]._obj) + for val2 in res[field]: + val2.update(obj._default_on_change(cursor, user, + val, context=context)) + res.update(val) + return res + def unlink(self, cursor, user, ids, context=None): if context is None: context = {} From d16813b15d938e9957d2b5820fdebbbd1393bd47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 22 Apr 2008 11:28:17 +0200 Subject: [PATCH 3/5] Add graph doc and graph dtd --- doc/graph.t2t | 47 +++++++++++++++++++++++++++++++++++++++++ trytond/ir/ui/graph.dtd | 14 ++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 doc/graph.t2t create mode 100644 trytond/ir/ui/graph.dtd diff --git a/doc/graph.t2t b/doc/graph.t2t new file mode 100644 index 0000000000..ff5063ba2e --- /dev/null +++ b/doc/graph.t2t @@ -0,0 +1,47 @@ + +== Graph view == + +The dtd that describe the xml for a graph view is stored in trytond/ir/ui/graph.dtd. + +* XML description: + +- tag "graph": + + - "type": vbar, hbar, line, pie + + - "string": the name of the graph + + - "background": an hexaecimal value for the color of the background + + - "color": the main color + + - "legend": a boolean to specify if the legend must be display + +- tag "x", "y": + + Describe the field that must be used for axis. + "x" must contain only one tag "field" and "y" must at least one but may contain many. + +- tag "field": + + - "name": the name of the field on the object to use + + - "string": allow to override the string that comes from the object + + - "key": can be used to distinguish fields with the same name but that are different with domain + + - "domain": a string that is evaluate with the object value as context. If the result is true the field value is added to the graph otherwise not + + - "fill": defined if the graph must be fill + + +* Example: + + + + + + + + + diff --git a/trytond/ir/ui/graph.dtd b/trytond/ir/ui/graph.dtd new file mode 100644 index 0000000000..46451b3e35 --- /dev/null +++ b/trytond/ir/ui/graph.dtd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + From 3c630538c7e77e0d1ea8c6362f55ff0490c7be4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 22 Apr 2008 13:54:13 +0200 Subject: [PATCH 4/5] Move domain and required on object --- trytond/res/user.py | 3 ++- trytond/res/user.xml | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/trytond/res/user.py b/trytond/res/user.py index 739bfc1c08..eb8d634f6e 100644 --- a/trytond/res/user.py +++ b/trytond/res/user.py @@ -19,7 +19,8 @@ class User(OSV): #address_id = fields.Many2One('res.partner.address', 'Address') active = fields.Boolean('Active') action = fields.Many2One('ir.action', 'Home Action') - menu = fields.Many2One('ir.action', 'Menu Action') + menu = fields.Many2One('ir.action', 'Menu Action', + domain=[('usage','=','menu')], required=True) groups = fields.Many2Many('res.group', 'res_group_user_rel', 'uid', 'gid', 'Groups') rule_groups = fields.Many2Many('ir.rule.group', 'user_rule_group_rel', diff --git a/trytond/res/user.xml b/trytond/res/user.xml index d5842f1c42..fd31e00528 100644 --- a/trytond/res/user.xml +++ b/trytond/res/user.xml @@ -33,9 +33,7 @@