Example #1
0
 def fields_view_get(self,
                     cr,
                     uid,
                     view_id=None,
                     view_type='form',
                     context=None,
                     toolbar=False,
                     submenu=False):
     result = super(multiple_edition,
                    self).fields_view_get(cr, uid, view_id, view_type,
                                          context, toolbar, submenu)
     xml = ''
     if context is None:
         context = {}
     if context.get('value_ok'):
         fields = {}
         multiple_edition_id = context.get('multiple_edition_id')
         field_data = self.pool.get('multiple.edition').browse(
             cr, uid, multiple_edition_id, context).field_id
         fields.update({
             'field_relation': {
                 'type': field_data.ttype,
                 'relation': field_data.relation,
                 'string': field_data.name
             },
         })
         xml_field = etree.Element('field', {'name': 'field_relation'})
         root = xml_field.getroottree()
         xml = etree.tostring(root)
         fields.update(result['fields'])
         result['fields'] = fields
     result['arch'] = result['arch'].replace(
         '<separator string="placeholder"/>', xml)
     return result
Example #2
0
    def postprocess_and_fields(self, cr, user, model, node, view_id, context=None):
        """ Return an architecture and a description of all the fields.

        The field description combines the result of fields_get() and
        postprocess().

        :param node: the architecture as as an etree
        :return: a tuple (arch, fields) where arch is the given node as a
            string and fields is the description of all the fields.

        """
        fields = {}
        Model = self.pool.get(model)
        if not Model:
            self.raise_view_error(cr, user, _('Model not found: %(model)s') % dict(model=model), view_id, context)

        if node.tag == 'diagram':
            if node.getchildren()[0].tag == 'node':
                node_model = self.pool[node.getchildren()[0].get('object')]
                node_fields = node_model.fields_get(cr, user, None, context)
                fields.update(node_fields)
                if not node.get("create") and not node_model.check_access_rights(cr, user, 'create', raise_exception=False):
                    node.set("create", 'false')
            if node.getchildren()[1].tag == 'arrow':
                arrow_fields = self.pool[node.getchildren()[1].get('object')].fields_get(cr, user, None, context)
                fields.update(arrow_fields)
        else:
            fields = Model.fields_get(cr, user, None, context)

        fields_def = self.postprocess(cr, user, model, node, view_id, False, fields, context=context)
        node = self._disable_workflow_buttons(cr, user, model, node)
        if node.tag in ('kanban', 'tree', 'form', 'gantt'):
            for action, operation in (('create', 'create'), ('delete', 'unlink'), ('edit', 'write')):
                if not node.get(action) and not Model.check_access_rights(cr, user, operation, raise_exception=False):
                    node.set(action, 'false')
        if node.tag in ('kanban'):
            group_by_field = node.get('default_group_by')
            if group_by_field and Model._all_columns.get(group_by_field):
                group_by_column = Model._all_columns[group_by_field].column
                if group_by_column._type == 'many2one':
                    group_by_model = Model.pool.get(group_by_column._obj)
                    for action, operation in (('group_create', 'create'), ('group_delete', 'unlink'), ('group_edit', 'write')):
                        if not node.get(action) and not group_by_model.check_access_rights(cr, user, operation, raise_exception=False):
                            node.set(action, 'false')

        arch = etree.tostring(node, encoding="utf-8").replace('\t', '')
        for k in fields.keys():
            if k not in fields_def:
                del fields[k]
        for field in fields_def:
            if field == 'id':
                # sometime, the view may contain the (invisible) field 'id' needed for a domain (when 2 objects have cross references)
                fields['id'] = {'readonly': True, 'type': 'integer', 'string': 'ID'}
            elif field in fields:
                fields[field].update(fields_def[field])
            else:
                message = _("Field `%(field_name)s` does not exist") % \
                                dict(field_name=field)
                self.raise_view_error(cr, user, message, view_id, context)
        return arch, fields
Example #3
0
    def postprocess_and_fields(self, cr, user, model, node, view_id, context=None):
        """ Return an architecture and a description of all the fields.

        The field description combines the result of fields_get() and
        postprocess().

        :param node: the architecture as as an etree
        :return: a tuple (arch, fields) where arch is the given node as a
            string and fields is the description of all the fields.

        """
        fields = {}
        Model = self.pool.get(model)
        if not Model:
            self.raise_view_error(cr, user, _('Model not found: %(model)s') % dict(model=model), view_id, context)

        if node.tag == 'diagram':
            if node.getchildren()[0].tag == 'node':
                node_model = self.pool[node.getchildren()[0].get('object')]
                node_fields = node_model.fields_get(cr, user, None, context)
                fields.update(node_fields)
                if not node.get("create") and not node_model.check_access_rights(cr, user, 'create', raise_exception=False):
                    node.set("create", 'false')
            if node.getchildren()[1].tag == 'arrow':
                arrow_fields = self.pool[node.getchildren()[1].get('object')].fields_get(cr, user, None, context)
                fields.update(arrow_fields)
        else:
            fields = Model.fields_get(cr, user, None, context)

        fields_def = self.postprocess(cr, user, model, node, view_id, False, fields, context=context)
        node = self._disable_workflow_buttons(cr, user, model, node)
        if node.tag in ('kanban', 'tree', 'form', 'gantt'):
            for action, operation in (('create', 'create'), ('delete', 'unlink'), ('edit', 'write')):
                if not node.get(action) and not Model.check_access_rights(cr, user, operation, raise_exception=False):
                    node.set(action, 'false')
        if node.tag in ('kanban'):
            group_by_field = node.get('default_group_by')
            if group_by_field and Model._all_columns.get(group_by_field):
                group_by_column = Model._all_columns[group_by_field].column
                if group_by_column._type == 'many2one':
                    group_by_model = Model.pool.get(group_by_column._obj)
                    for action, operation in (('group_create', 'create'), ('group_delete', 'unlink'), ('group_edit', 'write')):
                        if not node.get(action) and not group_by_model.check_access_rights(cr, user, operation, raise_exception=False):
                            node.set(action, 'false')

        arch = etree.tostring(node, encoding="utf-8").replace('\t', '')
        for k in fields.keys():
            if k not in fields_def:
                del fields[k]
        for field in fields_def:
            if field == 'id':
                # sometime, the view may contain the (invisible) field 'id' needed for a domain (when 2 objects have cross references)
                fields['id'] = {'readonly': True, 'type': 'integer', 'string': 'ID'}
            elif field in fields:
                fields[field].update(fields_def[field])
            else:
                message = _("Field `%(field_name)s` does not exist") % \
                                dict(field_name=field)
                self.raise_view_error(cr, user, message, view_id, context)
        return arch, fields
Example #4
0
 def _order_fields(self, cr, uid, ui_order, context=None):
     fields = {
         'name':         ui_order['name'],
         'user_id':      ui_order['user_id'] or False,
         'session_id':   ui_order['pos_session_id'],
         'lines':        ui_order['lines'],
         'pos_reference':ui_order['name'],
         'partner_id':   ui_order['partner_id'] or False,
     }
     if ui_order['return_status'] == 'active':
         fields.update({'return_order': ui_order['return_order']})
     return fields
Example #5
0
 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
     result = super(multiple_edition, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
     xml = ''
     if context is None:
         context = {}
     if context.get('value_ok'):
         fields = {}
         multiple_edition_id = context.get('multiple_edition_id')
         field_data = self.pool.get('multiple.edition').browse(cr, uid, multiple_edition_id, context).field_id
         fields.update({'field_relation': {'type': field_data.ttype, 'relation': field_data.relation, 'string': field_data.name},})        
         xml_field = etree.Element('field', {'name':'field_relation'})
         root = xml_field.getroottree()
         xml = etree.tostring(root)
         fields.update(result['fields'])
         result['fields'] = fields
     result['arch'] = result['arch'].replace('<separator string="placeholder"/>',xml)
     return result
Example #6
0
 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
     result = super(field_relation, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
     fields = {}
     xml = ''
     if context is None:
         context = {}
     multiple_edition_id = context.get('multiple_edition_id')
     multiple_obj = self.pool.get('multiple.edition')
     field_obj = self.pool.get('ir.model.fields')
     if multiple_edition_id:
         multi_edition = multiple_obj.browse(cr, uid, multiple_edition_id, context=context)
         field_data = multi_edition.field_id
         model = multi_edition.model_id
         field_type = multi_edition.field_type
         readonly = field_data.readonly
         if readonly == True:
             raise orm.except_orm(_('Warning'), _('This field is not editable'))
         if field_type == "selection":
             selection = self.pool.get(model.model)._columns[field_data.name].selection     
             fields.update({'field_relation': {'type': field_data.ttype, 'string': field_data.name, 'selection': selection},}) 
         else:
             fields.update({'field_relation': {'type': field_data.ttype, 'relation': field_data.relation, 'string': field_data.name},})        
         xml_field = etree.Element('field', {'name':'field_relation'})
         root = xml_field.getroottree()
         xml = etree.tostring(root)
         fields.update(result['fields'])
         result['fields'] = fields
         result['arch'] = result['arch'].replace('<separator string="placeholder"/>',xml)
     return result
Example #7
0
    def _set_vote_vote(self, cr, uid, id, name, value, arg, context={}):
        #_logger.info('name : %s, value %s, arg %s', name, value, arg)

        """ Create or update the vote in vote.vote model when we save the record """
        vote_obj = self.pool.get('vote.vote')
        vote_line_obj = self.pool.get('vote.vote.line')
        lastvoter_obj = self.pool.get('vote.last.voter')

        #TODO Yes I used a field in res.users to retrieve the partner specified in form... Clearly not concurrent thread proof, please tell me someone has a better idea
        if 'vote_partner_id' in context:
            vote_partner_id = context['vote_partner_id']
        else:
            vote_partner_id = lastvoter_obj.get_user_last_voter(cr, uid, context=context)

        vote_ids = vote_obj.search(cr, uid, [('model','=',self._name),('res_id','=',id),('partner_id','=',vote_partner_id)], context=context)
        vote_line_ids = vote_line_obj.search(cr, uid, [('vote_id','in',vote_ids)], context=context)
        lines = {}
        for line in vote_line_obj.browse(cr, uid, vote_line_ids, context=context):
            lines[line.type_id.id] = line
        #_logger.info('lines %s', lines)
        #_logger.info('value %s', value)
        #_logger.info('vote_ids %s', vote_ids)

        if value:
            fields = {}
            if name == 'vote_comment':
                fields.update({'comment': value})
            if not vote_ids:
                fields.update({'model': self._name, 'res_id': id, 'partner_id': vote_partner_id})
                #_logger.info('before create %s', fields)
                vote_id = vote_obj.create(cr, uid, fields, context=context)
            else:
                #_logger.info('In write vote_ids %s, fields : %s', fields)
                vote_obj.write(cr, uid, vote_ids, fields, context=context)
                vote_id = vote_ids[0]

            if name == 'vote_vote_line_ids':
                vote_obj._set_lines(cr, uid, vote_id, name, value, arg, context=context)
Example #8
0
 def fields_view_get(self,
                     cr,
                     uid,
                     view_id=None,
                     view_type='form',
                     context=None,
                     toolbar=False,
                     submenu=False):
     if context is None:
         context = {}
     res = super(object_merger, self).fields_view_get(cr,
                                                      uid,
                                                      view_id,
                                                      view_type,
                                                      context=context,
                                                      toolbar=toolbar,
                                                      submenu=False)
     object_ids = context.get('active_ids', [])
     active_model = context.get('active_model')
     field_name = 'x_' + (active_model and active_model.replace('.', '_')
                          or '') + '_id'
     fields = res['fields']
     if object_ids:
         view_part = """<label for='""" + field_name + """'/>
                     <div>
                         <field name='""" + field_name + """' required="1" domain="[(\'id\', \'in\', """ + str(
             object_ids) + """)]"/>
                     </div>"""
         #                            <field name='""" + field_name +"""' domain="[(\'id\', \'in\', '""" + str(object_ids) + """')]"/>'
         res['arch'] = res['arch'].decode('utf8').replace(
             """<separator string="to_replace"/>""", view_part)
         field = self.fields_get(cr, uid, [field_name], context=context)
         fields.update(field)
         res['fields'] = fields
         res['fields'][field_name]['domain'] = [('id', 'in', object_ids)]
         res['fields'][field_name]['required'] = True
     return res
Example #9
0
 def fields_view_get(self,
                     cr,
                     uid,
                     view_id=None,
                     view_type='form',
                     context=None,
                     toolbar=False,
                     submenu=False):
     result = super(field_relation,
                    self).fields_view_get(cr, uid, view_id, view_type,
                                          context, toolbar, submenu)
     fields = {}
     xml = ''
     if context is None:
         context = {}
     multiple_edition_id = context.get('multiple_edition_id')
     multiple_obj = self.pool.get('multiple.edition')
     field_obj = self.pool.get('ir.model.fields')
     if multiple_edition_id:
         multi_edition = multiple_obj.browse(cr,
                                             uid,
                                             multiple_edition_id,
                                             context=context)
         field_data = multi_edition.field_id
         model = multi_edition.model_id
         field_type = multi_edition.field_type
         readonly = field_data.readonly
         if readonly == True:
             raise orm.except_orm(_('Warning'),
                                  _('This field is not editable'))
         if field_type == "selection":
             selection = self.pool.get(
                 model.model)._columns[field_data.name].selection
             fields.update({
                 'field_relation': {
                     'type': field_data.ttype,
                     'string': field_data.name,
                     'selection': selection
                 },
             })
         else:
             fields.update({
                 'field_relation': {
                     'type': field_data.ttype,
                     'relation': field_data.relation,
                     'string': field_data.name
                 },
             })
         xml_field = etree.Element('field', {'name': 'field_relation'})
         root = xml_field.getroottree()
         xml = etree.tostring(root)
         fields.update(result['fields'])
         result['fields'] = fields
         result['arch'] = result['arch'].replace(
             '<separator string="placeholder"/>', xml)
     return result
Example #10
0
    def postprocess(self, cr, user, model, 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 = {}
        Model = self.pool.get(model)
        if not Model:
            self.raise_view_error(cr, user, _('Model not found: %(model)s') % dict(model=model),
                                  view_id, context)

        def encode(s):
            if isinstance(s, unicode):
                return s.encode('utf8')
            return s

        def check_group(node):
            """Apply group restrictions,  may be set at view level or model level::
               * at view level this means the element should be made invisible to
                 people who are not members
               * at model level (exclusively for fields, obviously), this means
                 the field should be completely removed from the view, as it is
                 completely unavailable for non-members

               :return: True if field should be included in the result of fields_view_get
            """
            if node.tag == 'field' and node.get('name') in Model._all_columns:
                column = Model._all_columns[node.get('name')].column
                if column.groups and not self.user_has_groups(
                        cr, user, groups=column.groups, context=context):
                    node.getparent().remove(node)
                    fields.pop(node.get('name'), None)
                    # no point processing view-level ``groups`` anymore, return
                    return False
            if node.get('groups'):
                can_see = self.user_has_groups(
                    cr, user, groups=node.get('groups'), context=context)
                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'])
            return True

        if node.tag in ('field', 'node', 'arrow'):
            if node.get('object'):
                attrs = {}
                views = {}
                xml = "<form>"
                for f in node:
                    if f.tag == 'field':
                        xml += etree.tostring(f, encoding="utf-8")
                xml += "</form>"
                new_xml = etree.fromstring(encode(xml))
                ctx = context.copy()
                ctx['base_model_name'] = model
                xarch, xfields = self.postprocess_and_fields(cr, user, node.get('object'), 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 Model._columns:
                        column = Model._columns[node.get('name')]
                    else:
                        column = Model._inherit_fields[node.get('name')][2]
                except Exception:
                    column = False

                if column:
                    children = False
                    views = {}
                    for f in node:
                        if f.tag in ('form', 'tree', 'graph', 'kanban', 'calendar'):
                            node.remove(f)
                            ctx = context.copy()
                            ctx['base_model_name'] = model
                            xarch, xfields = self.postprocess_and_fields(cr, user, column._obj or None, f, view_id, ctx)
                            views[str(f.tag)] = {
                                'arch': xarch,
                                'fields': xfields
                            }
                    attrs = {'views': views}
                fields[node.get('name')] = attrs

                field = model_fields.get(node.get('name'))
                if field:
                    orm.transfer_field_to_modifiers(field, modifiers)

        elif node.tag in ('form', 'tree'):
            result = Model.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', 'all_day', 'attendee'):
                if node.get(additional_field):
                    fields[node.get(additional_field)] = {}

        if not check_group(node):
            # node must be removed, no need to proceed further with its children
            return fields

        # The view architeture overrides the python model.
        # Get the attrs before they are (possibly) deleted by check_group below
        orm.transfer_node_to_modifiers(node, modifiers, context, in_tree_view)

        # TODO remove attrs counterpart in modifiers when invisible is true ?

        # translate view
        if 'lang' in context:
            Translations = self.pool['ir.translation']
            if node.text and node.text.strip():
                trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.text.strip())
                if trans:
                    node.text = node.text.replace(node.text.strip(), trans)
            if node.tail and node.tail.strip():
                trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.tail.strip())
                if trans:
                    node.tail =  node.tail.replace(node.tail.strip(), trans)

            if node.get('string') and not result:
                trans = Translations._get_source(cr, user, model, '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 = Translations._get_source(cr, user, context['base_model_name'], 'view', context['lang'], node.get('string'))
                if trans:
                    node.set('string', trans)

            for attr_name in ('confirm', 'sum', 'avg', 'help', 'placeholder'):
                attr_value = node.get(attr_name)
                if attr_value:
                    trans = Translations._get_source(cr, user, model, 'view', context['lang'], attr_value)
                    if trans:
                        node.set(attr_name, trans)

        for f in node:
            if children or (node.tag == 'field' and f.tag in ('filter','separator')):
                fields.update(self.postprocess(cr, user, model, f, view_id, in_tree_view, model_fields, context))

        orm.transfer_modifiers_to_node(modifiers, node)
        return fields
Example #11
0
    def postprocess_and_fields(self, cr, user, model, node, view_id, context=None):
        """ Return an architecture and a description of all the fields.

        The field description combines the result of fields_get() and
        postprocess().

        :param node: the architecture as as an etree
        :return: a tuple (arch, fields) where arch is the given node as a
            string and fields is the description of all the fields.

        """
        fields = {}
        Model = self.pool.get(model)
        if not Model:
            self.raise_view_error(cr, user, _("Model not found: %(model)s") % dict(model=model), view_id, context)

        if node.tag == "diagram":
            if node.getchildren()[0].tag == "node":
                node_model = self.pool[node.getchildren()[0].get("object")]
                node_fields = node_model.fields_get(cr, user, None, context)
                fields.update(node_fields)
                if not node.get("create") and not node_model.check_access_rights(
                    cr, user, "create", raise_exception=False
                ):
                    node.set("create", "false")
            if node.getchildren()[1].tag == "arrow":
                arrow_fields = self.pool[node.getchildren()[1].get("object")].fields_get(cr, user, None, context)
                fields.update(arrow_fields)
        else:
            fields = Model.fields_get(cr, user, None, context)

        fields_def = self.postprocess(cr, user, model, node, view_id, False, fields, context=context)
        node = self._disable_workflow_buttons(cr, user, model, node)
        if node.tag in ("kanban", "tree", "form", "gantt"):
            for action, operation in (("create", "create"), ("delete", "unlink"), ("edit", "write")):
                if not node.get(action) and not Model.check_access_rights(cr, user, operation, raise_exception=False):
                    node.set(action, "false")
        if node.tag in ("kanban"):
            group_by_field = node.get("default_group_by")
            if group_by_field and Model._all_columns.get(group_by_field):
                group_by_column = Model._all_columns[group_by_field].column
                if group_by_column._type == "many2one":
                    group_by_model = Model.pool.get(group_by_column._obj)
                    for action, operation in (
                        ("group_create", "create"),
                        ("group_delete", "unlink"),
                        ("group_edit", "write"),
                    ):
                        if not node.get(action) and not group_by_model.check_access_rights(
                            cr, user, operation, raise_exception=False
                        ):
                            node.set(action, "false")

        arch = etree.tostring(node, encoding="utf-8").replace("\t", "")
        for k in fields.keys():
            if k not in fields_def:
                del fields[k]
        for field in fields_def:
            if field == "id":
                # sometime, the view may contain the (invisible) field 'id' needed for a domain (when 2 objects have cross references)
                fields["id"] = {"readonly": True, "type": "integer", "string": "ID"}
            elif field in fields:
                fields[field].update(fields_def[field])
            else:
                message = _("Field `%(field_name)s` does not exist") % dict(field_name=field)
                self.raise_view_error(cr, user, message, view_id, context)
        return arch, fields
Example #12
0
    def synchronize(self, cr, uid, server, object_, context=None):
        '''
        Main controller function for synchronisation
        Establishes server connections, finds ids to sync and then
        either writes or creates them depending on requirement
        @return: True
        '''
        pool1 = RPCProxy(server)#ERPSyste
        pool2 = pooler.get_pool(cr.dbname)#ocentag
        
        self.meta = {}
        ids = []
        model = object_.model_id.model
        _logger.info('****Model**** : %s'%(model))
        if object_.action in ('d', 'b'):
            ids = pool1.get('base.synchro.obj').get_ids(
             cr, uid, model, object_.synchronize_date, eval(object_.domain), {'action':'d'}
                                                        )

        if object_.action in ('u', 'b'):
            ids += pool2.get('base.synchro.obj').get_ids(cr, uid,
                model,
                object_.synchronize_date,
                eval(object_.domain),
                {'action':'u'}
            )
        ids = [list(id_) for id_ in ids]
        ids.sort()
        for idx, (dt, id, action) in enumerate(ids):
            if action == 'd':
                pool_src = pool1
                pool_dest = pool2
            else:
                pool_src = pool2
                pool_dest = pool1

            record_fields = getattr(base_synchro,
                                    '_special_case_%s'.replace('.', '_')
                                    % model, [])

            record = pool_src.get(model).read(cr, uid, [id], record_fields,
                                              context=context)[0]
                                              
            
            if 'create_date' in record:
                del record['create_date']
            [record.update({key:val[0]}) for key, val in record.iteritems() if isinstance(val, tuple)]
            record = self.data_transform(cr, uid, pool_src, pool_dest, model,
                                         record, action, context=context)
            id2 = self.get_id(cr, uid, object_.id, id, action, context=context)
            if not (idx % 50):
                pass
############### Filter fields to not sync
            if object_.sync_only:
                fields = {}
                fields.update(record)
                data=[]
                for record_field in object_.avoid_ids:
                    if record_field.name in record:
                        data.append(record_field.name)
                
                for r in record : 
                    if r not in data :
                        del fields[r]
                record={}
                record.update(fields)
	        print "final fields data : %s"%(record)
            else :
                for record_field in object_.avoid_ids:
                    if  record_field.name in record:
                        del record[record_field.name]

            if id2:
                pool_dest.get(model).write(cr, uid, [id2], record,
                                           context=context)
                self.report_write += 1
            else:
                record = self.input(cr, uid, ids, record, context=context)
                idnew = pool_dest.get(model).create(cr, uid, record,
                                                    context=context)
                self.pool.get('base.synchro.obj.line').create(
                        cr, uid, {'obj_id': object_.id,
                                  'local_id': (action == 'u') and id or idnew,
                                  'remote_id': (action == 'd') and id or idnew
                                  }, context=context
                                                                      )
                self.report_create += 1
            self.meta = {}
        return True
Example #13
0
    def postprocess(self, cr, user, model, 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 = {}
        Model = self.pool.get(model)
        if not Model:
            self.raise_view_error(cr, user, _('Model not found: %(model)s') % dict(model=model),
                                  view_id, context)

        def encode(s):
            if isinstance(s, unicode):
                return s.encode('utf8')
            return s

        def check_group(node):
            """Apply group restrictions,  may be set at view level or model level::
               * at view level this means the element should be made invisible to
                 people who are not members
               * at model level (exclusively for fields, obviously), this means
                 the field should be completely removed from the view, as it is
                 completely unavailable for non-members

               :return: True if field should be included in the result of fields_view_get
            """
            if node.tag == 'field' and node.get('name') in Model._all_columns:
                column = Model._all_columns[node.get('name')].column
                if column.groups and not self.user_has_groups(
                        cr, user, groups=column.groups, context=context):
                    node.getparent().remove(node)
                    fields.pop(node.get('name'), None)
                    # no point processing view-level ``groups`` anymore, return
                    return False
            if node.get('groups'):
                can_see = self.user_has_groups(
                    cr, user, groups=node.get('groups'), context=context)
                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'])
            return True

        if node.tag in ('field', 'node', 'arrow'):
            if node.get('object'):
                attrs = {}
                views = {}
                xml = "<form>"
                for f in node:
                    if f.tag == 'field':
                        xml += etree.tostring(f, encoding="utf-8")
                xml += "</form>"
                new_xml = etree.fromstring(encode(xml))
                ctx = context.copy()
                ctx['base_model_name'] = model
                xarch, xfields = self.postprocess_and_fields(cr, user, node.get('object'), 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 Model._columns:
                        column = Model._columns[node.get('name')]
                    else:
                        column = Model._inherit_fields[node.get('name')][2]
                except Exception:
                    column = False

                if column:
                    children = False
                    views = {}
                    for f in node:
                        if f.tag in ('form', 'tree', 'graph', 'kanban', 'calendar'):
                            node.remove(f)
                            ctx = context.copy()
                            ctx['base_model_name'] = model
                            xarch, xfields = self.postprocess_and_fields(cr, user, column._obj or None, f, view_id, ctx)
                            views[str(f.tag)] = {
                                'arch': xarch,
                                'fields': xfields
                            }
                    attrs = {'views': views}
                fields[node.get('name')] = attrs

                field = model_fields.get(node.get('name'))
                if field:
                    orm.transfer_field_to_modifiers(field, modifiers)

        elif node.tag in ('form', 'tree'):
            result = Model.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', 'all_day', 'attendee'):
                if node.get(additional_field):
                    fields[node.get(additional_field)] = {}

        if not check_group(node):
            # node must be removed, no need to proceed further with its children
            return fields

        # The view architeture overrides the python model.
        # Get the attrs before they are (possibly) deleted by check_group below
        orm.transfer_node_to_modifiers(node, modifiers, context, in_tree_view)

        # TODO remove attrs counterpart in modifiers when invisible is true ?

        # translate view
        if 'lang' in context:
            Translations = self.pool['ir.translation']
            if node.text and node.text.strip():
                trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.text.strip())
                if trans:
                    node.text = node.text.replace(node.text.strip(), trans)
            if node.tail and node.tail.strip():
                trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.tail.strip())
                if trans:
                    node.tail =  node.tail.replace(node.tail.strip(), trans)

            if node.get('string') and not result:
                trans = Translations._get_source(cr, user, model, '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 = Translations._get_source(cr, user, context['base_model_name'], 'view', context['lang'], node.get('string'))
                if trans:
                    node.set('string', trans)

            for attr_name in ('confirm', 'sum', 'avg', 'help', 'placeholder'):
                attr_value = node.get(attr_name)
                if attr_value:
                    trans = Translations._get_source(cr, user, model, 'view', context['lang'], attr_value)
                    if trans:
                        node.set(attr_name, trans)

        for f in node:
            if children or (node.tag == 'field' and f.tag in ('filter','separator')):
                fields.update(self.postprocess(cr, user, model, f, view_id, in_tree_view, model_fields, context))

        orm.transfer_modifiers_to_node(modifiers, node)
        return fields
Example #14
0
 def _order_fields(self, cr, uid, ui_order, context=None):
     fields = super(pos_order, self)._order_fields(cr, uid, ui_order, context=context)
     if ui_order.get('return_status') == 'active':
         fields.update({'return_order': True})
     return fields