From a7b0a0379c02f2f6023ebd74a5c0e4e72826a65f Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 1 Jul 2013 15:53:13 +0200 Subject: [PATCH] add save method for javascript call bzr revid: mat@openerp.com-20130701135313-absej6vq16aztrc8 --- openerp/addons/base/ir/ir_ui_view.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index ddbde5be262..d3ccdb1ec5c 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -189,6 +189,23 @@ class view(osv.osv): return super(view, self).write(cr, uid, ids, vals, context) + def save(self, cr, uid, model, res_id, field, value, xpath=None, context=None): + """ Update the content of a field + + :param str model: + :param int res_id: + :param str xpath: valid xpath to the tag to replace + """ + model_obj = self.pool.get(model) + origin = model_obj.read(cr, uid, [res_id], [field], context=context) + if xpath: + origin_tree = etree.fromstring(origin.encode('utf-8')) + zone = origin_tree.xpath(xpath)[0] + zone.getparent().replace(zone, etree.fromstring(value)) + value = etree.tostring(origin_tree, encoding='utf-8') + + model_obj.write(cr, uid, res_id, {field: value}, context=context) + # default view selection def default_view(self, cr, uid, model, view_type, context=None): @@ -288,8 +305,8 @@ class view(osv.osv): count = {} for node in specs_tree: try: - count[node.tag] = count.get(node.tag, -1) + 1 - xpath = "%s/%s[%s]" % (base_xpath or '', node.tag, (count and count.get(node.tag)) or 0) + count[node.tag] = count.get(node.tag, 0) + 1 + xpath = "%s/%s[%s]" % (base_xpath or '', node.tag, count.get(node.tag)) if node.tag == 'data' or node.tag == 'xpath': node = self.inherit_branding(node, view_id, xpath, count) else: @@ -727,7 +744,7 @@ class view(osv.osv): if e.tag == 't' or e.tag == 'field': # can not anotate t and field return True - xpath = "%s/%s[%s]" % (xpath or '', e.tag, (count and count.get(e.tag)) or 0) + xpath = "%s/%s[%s]" % (xpath or '', e.tag, (count and count.get(e.tag)) or 1) if branding and not e.attrib.get('data-oe-model'): e.attrib.update(branding) e.attrib['data-oe-xpath'] = xpath @@ -741,7 +758,7 @@ class view(osv.osv): e.attrib.pop(i) count = {} for child in e: - count[child.tag] = count.get(child.tag,-1) + 1 + count[child.tag] = count.get(child.tag, 0) + 1 self.distribute_branding(child, branding_dist, xpath, count) def render(self, cr, uid, id_or_xml_id, values, context=None):