Bhumi Thakkar (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.1-opw-576076-bth into 
lp:openobject-addons/6.1.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-576076-bth/+merge/113916

Hello,

     Add to dashboard filter not translated when language is changed.

1. Create new database select english language.
2. Laod an official translation, language for ex: dutch.
3. Select language Dutch from setting => user.
4. Sales => Sale => Lead => From filter select Add to dashboard.
5. Click on menu sale.

Observed: 'Added action is in dutch and existed actions are in english. when 
click on reset then actions are in current language. If i changed language than 
also new created actions are not translated it is in from which language is 
created. It will not translated.'
Expected: 'Added action and existed actions should displayed in current 
language and when reset at that time should also displayed in current language 
and when changed the language at that time should displayed in changed 
language.'

when select add to dashboard from filter existed actions and new created 
actions are stored with context which contains current language in 
ir.ui.view.custom model and when retrieve records from that model have 
translate in current language and parsing xml architecture than return.
Same as doing in fields_view_get from server side for while calling in board.py 
file in fields_view_get for ir.ui.view model for that it is done and return 
architecture in current language and parsed. But then after browse record from 
ir.ui.view.custom model and return arch but not return in current language and 
also architecture is not parsed. 

Thanks.




-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-576076-bth/+merge/113916
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-576076-bth.
=== modified file 'board/board.py'
--- board/board.py	2012-02-08 01:27:26 +0000
+++ board/board.py	2012-07-09 07:23:23 +0000
@@ -22,6 +22,7 @@
 from osv import fields, osv
 import time
 import tools
+from lxml import etree
 
 class board_board(osv.osv):
     """
@@ -119,19 +120,29 @@
         res = {}
         res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,\
                                  context, toolbar=toolbar, submenu=submenu)
-
         vids = self.pool.get('ir.ui.view.custom').search(cr, user,\
                      [('user_id', '=', user), ('ref_id' ,'=', view_id)])
+        def encode(s):
+            if isinstance(s, unicode):
+                return s.encode('utf8')
+            return s
+
         if vids:
             view_id = vids[0]
             arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id, context=context)
+
+            fields = self.fields_get(cr, user, None, context)
+            xarch = etree.fromstring(encode(arch.arch))
+            fields_def = self.__view_look_dom(cr, user, xarch, view_id, False, fields, context=context)
+            arch = etree.tostring(xarch, encoding="utf-8").replace('\t', '')
             res['custom_view_id'] = view_id
-            res['arch'] = arch.arch
-        res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
+            res['arch'] = arch
+        else:
+            res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
+
         res['toolbar'] = {'print': [], 'action': [], 'relate': []}
         return res
 
-
     def _arch_preprocessing(self, cr, user, arch, context=None):
         from lxml import etree
         def remove_unauthorized_children(node):
@@ -150,9 +161,218 @@
         archnode = etree.fromstring(encode(arch))
         return etree.tostring(remove_unauthorized_children(archnode),pretty_print=True)
 
-
-
-
+    def __view_look_dom(self, cr, user, node, view_id, in_tree_view, model_fields, context=None):
+        """ Return the description of the fields in the node.
+
+        In a normal call to this method, node is a complete view architecture
+        but it is actually possible to give some sub-node (this is used so
+        that the method can call itself recursively).
+
+        Originally, the field descriptions are drawn from the node itself.
+        But there is now some code calling fields_get() in order to merge some
+        of those information in the architecture.
+
+        """
+        if context is None:
+            context = {}
+        result = False
+        fields = {}
+        children = True
+
+        modifiers = {}
+
+        def encode(s):
+            if isinstance(s, unicode):
+                return s.encode('utf8')
+            return s
+
+        def check_group(node):
+            """ Set invisible to true if the user is not in the specified groups. """
+            if node.get('groups'):
+                groups = node.get('groups').split(',')
+                ir_model_access = self.pool.get('ir.model.access')
+                can_see = any(ir_model_access.check_groups(cr, user, group) for group in groups)
+                if not can_see:
+                    node.set('invisible', '1')
+                    modifiers['invisible'] = True
+                    if 'attrs' in node.attrib:
+                        del(node.attrib['attrs']) #avoid making field visible later
+                del(node.attrib['groups'])
+
+        if node.tag in ('field', 'node', 'arrow'):
+            if node.get('object'):
+                attrs = {}
+                views = {}
+                xml = "<form>"
+                for f in node:
+                    if f.tag in ('field'):
+                        xml += etree.tostring(f, encoding="utf-8")
+                xml += "</form>"
+                new_xml = etree.fromstring(encode(xml))
+                ctx = context.copy()
+                ctx['base_model_name'] = self._name
+                xarch, xfields = self.pool.get(node.get('object')).__view_look_dom_arch(cr, user, new_xml, view_id, ctx)
+                views['form'] = {
+                    'arch': xarch,
+                    'fields': xfields
+                }
+                attrs = {'views': views}
+                fields = xfields
+            if node.get('name'):
+                attrs = {}
+                try:
+                    if node.get('name') in self._columns:
+                        column = self._columns[node.get('name')]
+                    else:
+                        column = self._inherit_fields[node.get('name')][2]
+                except Exception:
+                    column = False
+
+                if column:
+                    relation = self.pool.get(column._obj)
+
+                    children = False
+                    views = {}
+                    for f in node:
+                        if f.tag in ('form', 'tree', 'graph'):
+                            node.remove(f)
+                            ctx = context.copy()
+                            ctx['base_model_name'] = self._name
+                            xarch, xfields = relation.__view_look_dom_arch(cr, user, f, view_id, ctx)
+                            views[str(f.tag)] = {
+                                'arch': xarch,
+                                'fields': xfields
+                            }
+                    attrs = {'views': views}
+                    if node.get('widget') and node.get('widget') == 'selection':
+                        # Prepare the cached selection list for the client. This needs to be
+                        # done even when the field is invisible to the current user, because
+                        # other events could need to change its value to any of the selectable ones
+                        # (such as on_change events, refreshes, etc.)
+
+                        # If domain and context are strings, we keep them for client-side, otherwise
+                        # we evaluate them server-side to consider them when generating the list of
+                        # possible values
+                        # TODO: find a way to remove this hack, by allow dynamic domains
+                        dom = []
+                        if column._domain and not isinstance(column._domain, basestring):
+                            dom = column._domain
+                        dom += eval(node.get('domain', '[]'), {'uid': user, 'time': time})
+                        search_context = dict(context)
+                        if column._context and not isinstance(column._context, basestring):
+                            search_context.update(column._context)
+                        attrs['selection'] = relation._name_search(cr, user, '', dom, context=search_context, limit=None, name_get_uid=1)
+                        if (node.get('required') and not int(node.get('required'))) or not column.required:
+                            attrs['selection'].append((False, ''))
+                fields[node.get('name')] = attrs
+
+                field = model_fields.get(node.get('name'))
+                if field:
+                    transfer_field_to_modifiers(field, modifiers)
+
+
+        elif node.tag in ('form', 'tree'):
+            result = self.view_header_get(cr, user, False, node.tag, context)
+            if result:
+                node.set('string', result)
+            in_tree_view = node.tag == 'tree'
+
+        elif node.tag == 'calendar':
+            for additional_field in ('date_start', 'date_delay', 'date_stop', 'color'):
+                if node.get(additional_field):
+                    fields[node.get(additional_field)] = {}
+
+        check_group(node)
+
+        # The view architeture overrides the python model.
+        # Get the attrs before they are (possibly) deleted by check_group below
+        transfer_node_to_modifiers(node, modifiers, context, in_tree_view)
+
+        # TODO remove attrs couterpart in modifiers when invisible is true ?
+
+        # translate view
+        if 'lang' in context:
+            if node.get('string') and not result:
+                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('string'))
+                if trans == node.get('string') and ('base_model_name' in context):
+                    # If translation is same as source, perhaps we'd have more luck with the alternative model name
+                    # (in case we are in a mixed situation, such as an inherited view where parent_view.model != model
+                    trans = self.pool.get('ir.translation')._get_source(cr, user, context['base_model_name'], 'view', context['lang'], node.get('string'))
+                if trans:
+                    node.set('string', trans)
+            if node.get('confirm'):
+                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('confirm'))
+                if trans:
+                    node.set('confirm', trans)
+            if node.get('sum'):
+                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('sum'))
+                if trans:
+                    node.set('sum', trans)
+            if node.get('avg'):
+                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('avg'))
+                if trans:
+                    node.set('avg', trans)
+            if node.get('help'):
+                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('help'))
+                if trans:
+                    node.set('help', trans)
+
+        for f in node:
+            if children or (node.tag == 'field' and f.tag in ('filter','separator')):
+                fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
+
+        transfer_modifiers_to_node(modifiers, node)
+        return fields
+
+def simplify_modifiers(modifiers):
+    for a in ('invisible', 'readonly', 'required'):
+        if a in modifiers and not modifiers[a]:
+            del modifiers[a]
+
+def transfer_modifiers_to_node(modifiers, node):
+    if modifiers:
+        simplify_modifiers(modifiers)
+        node.set('modifiers', simplejson.dumps(modifiers))
+
+def transfer_field_to_modifiers(field, modifiers):
+    default_values = {}
+    state_exceptions = {}
+    for attr in ('invisible', 'readonly', 'required'):
+        state_exceptions[attr] = []
+        default_values[attr] = bool(field.get(attr))
+    for state, modifs in (field.get("states",{})).items():
+        for modif in modifs:
+            if default_values[modif[0]] != modif[1]:
+                state_exceptions[modif[0]].append(state)
+
+    for attr, default_value in default_values.items():
+        if state_exceptions[attr]:
+            modifiers[attr] = [("state", "not in" if default_value else "in", state_exceptions[attr])]
+        else:
+            modifiers[attr] = default_value
+
+def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False):
+    if node.get('attrs'):
+        modifiers.update(eval(node.get('attrs')))
+
+    if node.get('states'):
+        if 'invisible' in modifiers and isinstance(modifiers['invisible'], list):
+             # TODO combine with AND or OR, use implicit AND for now.
+             modifiers['invisible'].append(('state', 'not in', node.get('states').split(',')))
+        else:
+             modifiers['invisible'] = [('state', 'not in', node.get('states').split(','))]
+
+    for a in ('invisible', 'readonly', 'required'):
+        if node.get(a):
+            v = bool(eval(node.get(a), {'context': context or {}}))
+            if in_tree_view and a == 'invisible':
+                # Invisible in a tree view has a specific meaning, make it a
+                # new key in the modifiers attribute.
+                modifiers['tree_invisible'] = v
+            elif v or (a not in modifiers or not isinstance(modifiers[a], list)):
+                # Don't set the attribute to False if a dynamic value was
+                # provided (i.e. a domain from attrs or states).
+                modifiers[a] = v
     _columns = {
         'name': fields.char('Dashboard', size=64, required=True),
         'view_id': fields.many2one('ir.ui.view', 'Board View'),

_______________________________________________
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

Reply via email to