Ejemplo n.º 1
0
 def _search_full_name(self, operator, operand):
     lst = True
     if isinstance(operand, bool):
         domains = [[('name', operator, operand)],
                    [('category_id.name', operator, operand)]]
         if operator in expression.NEGATIVE_TERM_OPERATORS == (not operand):
             return expression.AND(domains)
         else:
             return expression.OR(domains)
     if isinstance(operand, pycompat.string_types):
         lst = False
         operand = [operand]
     where = []
     for group in operand:
         values = [v for v in group.split('/') if v]
         group_name = values.pop().strip()
         category_name = values and '/'.join(values).strip() or group_name
         group_domain = [('name', operator, lst and [group_name]
                          or group_name)]
         category_domain = [('category_id.name', operator,
                             lst and [category_name] or category_name)]
         if operator in expression.NEGATIVE_TERM_OPERATORS and not values:
             category_domain = expression.OR(
                 [category_domain, [('category_id', '=', False)]])
         if (operator
                 in expression.NEGATIVE_TERM_OPERATORS) == (not values):
             sub_where = expression.AND([group_domain, category_domain])
         else:
             sub_where = expression.OR([group_domain, category_domain])
         if operator in expression.NEGATIVE_TERM_OPERATORS:
             where = expression.AND([where, sub_where])
         else:
             where = expression.OR([where, sub_where])
     return where
Ejemplo n.º 2
0
 def get_mention_suggestions(self, search, limit=8):
     """ Return 'limit'-first channels' id, name and public fields such that the name matches a
         'search' string. Exclude channels of type chat (DM), and private channels the current
         user isn't registered to. """
     domain = expression.AND([
                     [('name', 'ilike', search)],
                     [('channel_type', '=', 'channel')],
                     expression.OR([
                         [('public', '!=', 'private')],
                         [('channel_partner_ids', 'in', [self.env.user.partner_id.id])]
                     ])
                 ])
     return self.search_read(domain, ['id', 'name', 'public'], limit=limit)
Ejemplo n.º 3
0
    def get_mention_suggestions(self, search, limit=8):
        """ Return 'limit'-first partners' id, name and email such that the name or email matches a
            'search' string. Prioritize users, and then extend the research to all partners. """
        search_dom = expression.OR([[('name', 'ilike', search)], [('email', 'ilike', search)]])
        fields = ['id', 'name', 'email']

        # Search users
        domain = expression.AND([[('user_ids.id', '!=', False)], search_dom])
        users = self.search_read(domain, fields, limit=limit)

        # Search partners if less than 'limit' users found
        partners = []
        if len(users) < limit:
            partners = self.search_read(search_dom, fields, limit=limit)
            # Remove duplicates
            partners = [p for p in partners if not len([u for u in users if u['id'] == p['id']])] 

        return [users, partners]
Ejemplo n.º 4
0
    def _compute_domain(self, model_name, mode="read"):
        if mode not in self._MODES:
            raise ValueError('Invalid mode: %r' % (mode, ))

        if self._uid == SUPERUSER_ID:
            return None

        query = """ SELECT r.id FROM ir_rule r JOIN ir_model m ON (r.model_id=m.id)
                    WHERE m.model=%s AND r.active AND r.perm_{mode}
                    AND (r.id IN (SELECT rule_group_id FROM rule_group_rel rg
                                  JOIN res_groups_users_rel gu ON (rg.group_id=gu.gid)
                                  WHERE gu.uid=%s)
                         OR r.global)
                """.format(mode=mode)
        self._cr.execute(query, (model_name, self._uid))
        rule_ids = [row[0] for row in self._cr.fetchall()]
        if not rule_ids:
            return []

        # browse user and rules as SUPERUSER_ID to avoid access errors!
        eval_context = self._eval_context()
        user_groups = self.env.user.groups_id
        global_domains = []  # list of domains
        group_domains = []  # list of domains
        for rule in self.browse(rule_ids).sudo():
            # evaluate the domain for the current user
            dom = safe_eval(rule.domain_force,
                            eval_context) if rule.domain_force else []
            dom = expression.normalize_domain(dom)
            if not rule.groups:
                global_domains.append(dom)
            elif rule.groups & user_groups:
                group_domains.append(dom)

        # combine global domains and group domains
        return expression.AND(global_domains + [expression.OR(group_domains)])
Ejemplo n.º 5
0
 def _get_translation_frontend_modules_domain(cls):
     domain = super(IrHttp, cls)._get_translation_frontend_modules_domain()
     return expression.OR([domain, [('name', '=', 'portal')]])
Ejemplo n.º 6
0
 def name_search(self, name='', args=None, operator='ilike', limit=100):
     if not args:
         args = []
     if name:
         positive_operators = ['=', 'ilike', '=ilike', 'like', '=like']
         products = self.env['product.product']
         if operator in positive_operators:
             products = self.search([('default_code', '=', name)] + args,
                                    limit=limit)
             if not products:
                 products = self.search([('barcode', '=', name)] + args,
                                        limit=limit)
         if not products and operator not in expression.NEGATIVE_TERM_OPERATORS:
             # Do not merge the 2 next lines into one single search, SQL search performance would be abysmal
             # on a database with thousands of matching products, due to the huge merge+unique needed for the
             # OR operator (and given the fact that the 'name' lookup results come from the ir.translation table
             # Performing a quick memory merge of ids in Python will give much better performance
             products = self.search(args +
                                    [('default_code', operator, name)],
                                    limit=limit)
             if not limit or len(products) < limit:
                 # we may underrun the limit because of dupes in the results, that's fine
                 limit2 = (limit - len(products)) if limit else False
                 products += self.search(args +
                                         [('name', operator, name),
                                          ('id', 'not in', products.ids)],
                                         limit=limit2)
         elif not products and operator in expression.NEGATIVE_TERM_OPERATORS:
             domain = expression.OR([
                 [
                     '&', ('default_code', operator, name),
                     ('name', operator, name)
                 ],
                 [
                     '&', ('default_code', '=', False),
                     ('name', operator, name)
                 ],
             ])
             domain = expression.AND([args, domain])
             products = self.search(domain, limit=limit)
         if not products and operator in positive_operators:
             ptrn = re.compile('(\[(.*?)\])')
             res = ptrn.search(name)
             if res:
                 products = self.search(
                     [('default_code', '=', res.group(2))] + args,
                     limit=limit)
         # still no results, partner in context: search on supplier info as last hope to find something
         if not products and self._context.get('partner_id'):
             suppliers = self.env['product.supplierinfo'].search([
                 ('name', '=', self._context.get('partner_id')), '|',
                 ('product_code', operator, name),
                 ('product_name', operator, name)
             ])
             if suppliers:
                 products = self.search(
                     [('product_tmpl_id.seller_ids', 'in', suppliers.ids)],
                     limit=limit)
     else:
         products = self.search(args, limit=limit)
     return products.name_get()
Ejemplo n.º 7
0
 def _analytic_compute_delivered_quantity_domain(self):
     domain = super(SaleOrderLine, self)._analytic_compute_delivered_quantity_domain()
     domain = expression.AND([domain, [('project_id', '=', False)]])
     timesheet_domain = self._timesheet_compute_delivered_quantity_domain()
     return expression.OR([domain, timesheet_domain])