From 28371360d11c04da99f2dfd6003b1cd83af56031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 27 Jul 2008 00:04:33 +0200 Subject: [PATCH] Handle on_change_with --- tryton/gui/window/view_form/model/field.py | 1 + tryton/gui/window/view_form/model/record.py | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index b7f4e3a628..19846c91a4 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -35,6 +35,7 @@ class CharField(object): model.on_change(self.name, self.attrs['on_change']) if self.attrs.get('change_default', False): model.cond_default(self.attrs['name'], self.get(model)) + model.on_change_with(self.name) def domain_get(self, model): dom = self.attrs.get('domain', '[]') diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index c4537f4f0c..bd8b05d8c1 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -314,6 +314,30 @@ class ModelRecord(SignalEvent): self.mgroup.mfields[fieldname].set_on_change(self, value) self.signal('record-changed') + def on_change_with(self, fieldname): + for fieldname in self.mgroup.mfields: + on_change_with = self.mgroup.mfields[fieldname].attrs.get( + 'on_change_with') + if not on_change_with: + continue + args = {} + for arg in on_change_with: + try: + args[arg] = self.expr_eval(arg) + except: + args[arg] = False + ids = self.id and [self.id] or [] + ctx = rpc.CONTEXT.copy() + ctx.update(self.context_get()) + try: + res = getattr(self.rpc, 'on_change_with_' + fieldname)(ids, + args, ctx) + except Exception, exception: + common.process_exception(exception, self.window) + res = getattr(self.rpc, 'on_change_with_' + fieldname)(ids, + args, ctx) + self.mgroup.mfields[fieldname].set_on_change(self, res) + def cond_default(self, field_name, value): ir_default = RPCProxy('ir.default') ctx = rpc.CONTEXT.copy()