Xavier ALT (OpenERP) has proposed merging
lp:~openerp-dev/openobject-client-web/6.0-opw-580592-xal into
lp:openobject-client-web.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-580592-xal/+merge/129654
Hi,
When clicking on a button within a one2many window, web client force data of
that record to be rewritten. This can cause permission errors.
The one2many save() has been modified to support filtering only modified datas
(like it's done on form save()).
Regards,
Xavier
--
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-580592-xal/+merge/129654
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-client-web/6.0-opw-580592-xal.
=== modified file 'addons/openerp/controllers/openo2m.py'
--- addons/openerp/controllers/openo2m.py 2012-09-13 15:19:58 +0000
+++ addons/openerp/controllers/openo2m.py 2012-10-15 11:15:38 +0000
@@ -113,6 +113,7 @@
params, data = TinyDict.split(kw)
params.editable = True
+ o2m_proxy = rpc.RPCProxy(params.o2m_model)
proxy = rpc.RPCProxy(params.parent_model)
pprefix = '.'.join(params.o2m.split('/')[:-1])
@@ -120,11 +121,42 @@
if pprefix:
data = eval(pprefix, TinyDict(**data)).make_dict()
+ fld = params.o2m.split('/')[-1]
+
ctx = context_with_concurrency_info(rpc.session.context, params.concurrency_info)
ctx.update(params.parent_context or {})
ctx.update(params.o2m_context or {})
- id = proxy.write([params.parent_id], data, ctx)
+ ## Before writing, filter data that has not been modified
+ if isinstance(data, dict) and fld in data:
+ fld_data = []
+ fld_ctx = dict((params.o2mcontext or {}), **rpc.session.context)
+ for (op, _id, values) in data[fld]:
+ modified = {}
+ if _id and op == 1: # we're updating that record
+ original_data = o2m_proxy.read(_id, values.keys(), fld_ctx)
+
+ if original_data and isinstance(original_data, dict):
+ for field, original_value in original_data.iteritems():
+ if isinstance(original_value, tuple):
+ original_data[field] = original_value[0]
+ if field in values and values[field] != original_data[field]:
+ #When field is many2many at that time following code will be applied
+ if isinstance(values[field], list) and isinstance(values[field][0][2], list):
+ if sorted(values[field][0][2]) != sorted(original_data[field]):
+ modified[field] = values[field]
+ else:
+ modified[field] = values[field]
+ if modified:
+ fld_data.append((op, _id, modified))
+ # update 'fld' in data, or remove it if there is nothing to be written
+ if fld_data:
+ data[fld] = fld_data
+ else:
+ data.pop(fld, None)
+
+ if data:
+ id = proxy.write([params.parent_id], data, ctx)
prefix = params.o2m
current = params.chain_get(prefix)
@@ -132,7 +164,6 @@
params.load_counter = 1
ids = current.ids
- fld = params.o2m.split('/')[-1]
all_ids = proxy.read([params.parent_id], [fld])[0][fld]
new_ids = [i for i in all_ids if i not in ids]
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp