コード例 #1
0
ファイル: res_partner.py プロジェクト: Jarsa/partner-contact
 def search(self, args, offset=0, limit=None, order=None, count=False):
     """Inject searching for current relation date if we search for
     relation properties and no explicit date was given.
     """
     # pylint: disable=arguments-differ
     # pylint: disable=no-value-for-parameter
     date_args = []
     for arg in args:
         if (is_leaf(arg) and isinstance(arg[0], str)
                 and arg[0].startswith("search_relation")):
             if arg[0] == "search_relation_date":
                 date_args = []
                 break
             if not date_args:
                 date_args = [("search_relation_date", "=",
                               fields.Date.today())]
     # because of auto_join, we have to do the active test by hand
     active_args = []
     if self.env.context.get("active_test", True):
         for arg in args:
             if (is_leaf(arg) and isinstance(arg[0], str)
                     and arg[0].startswith("search_relation")):
                 active_args = [("relation_all_ids.active", "=", True)]
                 break
     return super(ResPartner, self).search(
         args + date_args + active_args,
         offset=offset,
         limit=limit,
         order=order,
         count=count,
     )
コード例 #2
0
 def _compute_is_frozen(self):
     '''determine if this is fixed list of ids'''
     for this in self:
         domain = self._eval_domain(this.domain)
         this.is_frozen = (
             len(domain) == 1
             and expression.is_leaf(domain[0])
             and domain[0][0] == "id"
             and domain[0][1] == "in"
         )
コード例 #3
0
    def button_save(self):
        self.ensure_one()
        domain = json.loads(self.domain)
        is_frozen = (len(domain) == 1 and expression.is_leaf(domain[0])
                     and domain[0][0] == "id" and domain[0][1] == "in")

        if self.action == 'union':
            if is_frozen and self.filter_id.is_frozen:
                domain[0][2] = list(
                    set(domain[0][2]).union(
                        set(safe_eval(self.filter_id.domain)[0][2])))
                self.filter_id.write({'domain': repr(domain)})
            else:
                self.filter_id.write({
                    'union_filter_ids': [(0, 0, {
                        'name':
                        '%s_%s_%d' % (self.filter_id.name, 'add', time.time()),
                        'active':
                        False,
                        'domain':
                        repr(domain),
                        'context':
                        repr(json.loads(self.context)),
                        'model_id':
                        self.model,
                        'user_id':
                        self.filter_id.user_id.id or False,
                    })],
                })
        elif self.action == 'complement':
            if is_frozen and self.filter_id.is_frozen:
                complement_set = set(safe_eval(self.filter_id.domain)[0][2])
                domain[0][2] = list(
                    complement_set.difference(set(domain[0][2])))
                self.filter_id.write({'domain': repr(domain)})
            else:
                self.filter_id.write({
                    'complement_filter_ids': [(0, 0, {
                        'name':
                        '%s_%s_%d' %
                        (self.filter_id.name, 'remove', time.time()),
                        'active':
                        False,
                        'domain':
                        repr(domain),
                        'context':
                        repr(json.loads(self.context)),
                        'model_id':
                        self.model,
                        'user_id':
                        self.filter_id.user_id.id or False,
                    })],
                })

        return {'type': 'ir.actions.act_window_close'}
コード例 #4
0
ファイル: product_product.py プロジェクト: CURE-EMR/oca10
 def _get_expired_quants_domain(self, removal_date=None):
     """ Compute the domain used to retrieve all the quants in
     stock and reserved for an outgoing move and for an expired stock
     production lot
     :return: quant_domain, quant_out_domain
     """
     from_date = self.env.context.get('from_date', removal_date)
     self_with_context = self.with_context(compute_expired_only=True,
                                           from_date=from_date)
     quant_domain, move_in_domain, move_out_domain = \
         self_with_context._get_domain_locations()
     quant_out_domain = copy.copy(quant_domain)
     for element in move_out_domain:
         if expression.is_leaf(element):
             quant_out_domain.append(
                 ('reservation_id.' + element[0], element[1], element[2]))
         else:
             quant_out_domain.append(element)
     if self:
         quant_domain = expression.AND([[('product_id', 'in', self.ids)],
                                        quant_domain])
     return quant_domain, quant_out_domain
コード例 #5
0
 def is_relation_search_arg(arg):
     """Check whether search argument is a search on relations."""
     return (is_leaf(arg) and isinstance(arg[0], str)
             and arg[0].startswith("search_relation"))
コード例 #6
0
    def _compute_pre_evaluate(self):
        """Check if this filter contains problematic fields.

        Domains with certain fields can't be negated or joined properly.
        They have to be evaluated in advance. In particular:

        - Negating a query on a 2many field doesn't invert the matched records.
          ``foo.bar != 3`` will yield all records with a ``foo.bar`` that
          isn't ``3``, not all records without a ``foo.bar`` that is ``3``.
          So just putting a ``!`` in front of the domain doesn't do what we
          want.

        - Querying an autojoined field constrains the entire search, even if
          it's joined with ``|``. If ``('user_ids.login', '=', 'admin')`` is
          used anywhere in the domain then only records that satisfy that leaf
          are found.

        - Fields with custom search logic (``search=...``) might do one of the
          above, or some other strange thing.

        Examples can be found in the tests for this module.
        """
        for this in self:
            evaluate_before_negate = False
            evaluate_before_join = False
            domain = self._eval_domain(this.domain)
            for arg in domain:
                if not expression.is_leaf(arg) or not isinstance(arg[0], str):
                    continue
                current_model = self.env.get(this.model_id)
                if current_model is None:
                    _logger.error(
                        "Unknown model %s used in filter %d",
                        this.model_id,
                        this.id,
                    )
                    continue
                for field_name in arg[0].split('.'):
                    if field_name in models.MAGIC_COLUMNS:
                        continue
                    field = current_model._fields[field_name]
                    evaluate_before_negate = (
                        evaluate_before_negate
                        or field.search
                        or field.type in self._evaluate_before_negate
                        or getattr(field, "auto_join", False)
                    )
                    evaluate_before_join = (
                        evaluate_before_join
                        or field.search
                        or getattr(field, "auto_join", False)
                    )
                    if field.comodel_name:
                        current_model = self.env.get(field.comodel_name)
                    if current_model is None or (
                        evaluate_before_negate and evaluate_before_join
                    ):
                        break
                if evaluate_before_negate and evaluate_before_join:
                    break
            this.evaluate_before_negate = evaluate_before_negate
            this.evaluate_before_join = evaluate_before_join