Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Apply mutations on the user's saved selection and report back to the client in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 266
    Comment on it

    In OpenERp we first create report of the client and apply mutations on the user's saved selection of the search domain to be processed. The domain is only processed if no ids are present. If both domain and ids are missing, this will lead to all resources of the model being processed and than The model should correspond to the model in the current to reutrn the verbose summary of the mutation.

    Use this function show in given below


    def update_client(
            self, cr, uid, model, mode, ids, domain, pass_ids = False, context=None):
            selection_id = False
            me = self.pool.get('res.users').read(
                cr, uid, uid, ['saved_selection_id'], context=context)
            if me['saved_selection_id']:
                selection_id = me['saved_selection_id'][0]
                # autoinitialize a new selection
                model_id = self.pool.get('ir.model').search(
                    cr, uid,
                    [('model', '=', model)], context=context)[0]
                selection_id = self.create(
                    cr, uid, {'user_ids': [(6, 0, [uid])], 'model_id': model_id},
            # retrieve selection and check model
            selection = self.browse(cr, uid, selection_id, context)
            if selection.model_id.model != model:
                return (_("Error: selection is initialized for items of type %s") %
              , False)
            model_obj = self.pool.get(model)
            search_context = context and context.copy() or {}
            # convert ids argument to domain
            if ids:
                domain = [('id', 'in', ids)]
                # There might be inactive ids, add active_test key
                # Note that active_test in the case of an added domain
                # should emphatically apply!
                search_context['active_test'] = False
            # apply communication filters
            filter_domain = self.compose_filter_domain(
                cr, uid, selection, model_obj, context=context)
            if filter_domain or not ids:
                ids =
                    cr, uid, domain + filter_domain, limit=0, context=search_context)
            # perform mutations
            orig_ids = selection.ids and [
                        int(x) for x in selection.ids.split(',')] or []
            new_ids = self.operations[mode](orig_ids, ids)
                cr, uid, selection_id, {
                    'ids': ','.join([str(x) for x in new_ids])
                    }, context=context
            new_len = len(new_ids)
            mutations = new_len - len(orig_ids)
            msg = (
                mutations > 0 and (
                    _("%d added, total %d") % (mutations, new_len)
                    ) or
                mutations < 0 and (
                    _("%d removed, total %d") % (abs(mutations), new_len)
                    ) or
                (_("Nothing to do, total %d") % new_len)
            return (msg, pass_ids and new_ids or [])


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: