Пример #1
0
    def get_aml_domain_for_expr(self, expr, date_from, date_to, period_from,
                                period_to, target_move):
        """ Get a domain on account.move.line for an expression.

        Prerequisite: done_parsing() must have been invoked.

        Returns a domain that can be used to search on account.move.line.
        """
        aml_domains = []
        date_domain_by_mode = {}
        for mo in self.ACC_RE.finditer(expr):
            field, mode, account_codes, domain = self._parse_match_object(mo)
            aml_domain = list(domain)
            account_ids = set()
            for account_code in account_codes:
                account_ids.update(self._account_ids_by_code[account_code])
            aml_domain.append(('account_id', 'in', tuple(account_ids)))
            if field == 'crd':
                aml_domain.append(('credit', '>', 0))
            elif field == 'deb':
                aml_domain.append(('debit', '>', 0))
            aml_domains.append(expression.normalize_domain(aml_domain))
            if mode not in date_domain_by_mode:
                date_domain_by_mode[mode] = \
                    self.get_aml_domain_for_dates(date_from, date_to,
                                                  period_from, period_to,
                                                  mode, target_move)
        return expression.OR(aml_domains) + \
            expression.OR(date_domain_by_mode.values())
Пример #2
0
 def name_search(self, name='', args=None, operator='ilike', limit=100):
     if not name:
         return super(StockQuant, self).name_search(name=name,
                                                    args=args,
                                                    operator=operator,
                                                    limit=limit)
     search_domain = []
     quants = self
     product_obj = self.env['product.product']
     product_search = product_obj.name_search(name=name,
                                              args=None,
                                              operator=operator,
                                              limit=limit)
     uom_search = self.env['product.uom'].name_search(name=name,
                                                      args=None,
                                                      operator=operator,
                                                      limit=limit)
     product_uoms = map(lambda x: x[0], uom_search)
     product_uom_ids = product_obj.search([('uom_id', 'in', product_uoms)])
     product_ids = map(lambda x: x[0], product_search) + product_uom_ids.ids
     search_domain = expression.OR(
         [search_domain, [('product_id', 'in', product_ids)]])
     lot_search = self.env['stock.production.lot'].name_search(
         name=name, args=None, operator=operator, limit=limit)
     lot_ids = map(lambda x: x[0], lot_search)
     search_domain = expression.OR(
         [search_domain, [('lot_id', 'in', lot_ids)]])
     search_domain = expression.AND([search_domain, args or []])
     quants = self.search(search_domain, limit=limit)
     result = quants.name_get()
     return result
Пример #3
0
 def name_search(self, name='', args=None, operator='ilike', limit=100):
     # TODO maybe implement negative search operators, although
     #      there is not really a use case for that
     domain = args or []
     splitted_name = name.split('.', 2)
     name_search_domain = []
     if '.' in name:
         kpi_name, subkpi_name = splitted_name[0], splitted_name[1]
         name_search_domain = osv_expression.AND([
             name_search_domain,
             [
                 '|',
                 '|',
                 '&',
                 ('kpi_id.name', '=', kpi_name),
                 ('subkpi_id.name', operator, subkpi_name),
                 ('kpi_id.description', operator, name),
                 ('subkpi_id.description', operator, name),
             ]
         ])
     name_search_domain = osv_expression.OR([
         name_search_domain,
         [
             '|',
             ('kpi_id.name', operator, name),
             ('kpi_id.description', operator, name),
         ]
     ])
     domain = osv_expression.AND([domain, name_search_domain])
     return self.search(domain, limit=limit).name_get()
Пример #4
0
    def get_aml_domain_for_expr(self,
                                expr,
                                date_from,
                                date_to,
                                target_move,
                                account_id=None):
        """ Get a domain on account.move.line for an expression.

        Prerequisite: done_parsing() must have been invoked.

        Returns a domain that can be used to search on account.move.line.
        """
        aml_domains = []
        date_domain_by_mode = {}
        for mo in self._ACC_RE.finditer(expr):
            field, mode, acc_domain, ml_domain = self._parse_match_object(mo)
            aml_domain = list(ml_domain)
            account_ids = set()
            account_ids.update(self._account_ids_by_acc_domain[acc_domain])
            if not account_id:
                aml_domain.append(('account_id', 'in', tuple(account_ids)))
            else:
                # filter on account_id
                if account_id in account_ids:
                    aml_domain.append(('account_id', '=', account_id))
                else:
                    continue
            if field == 'crd':
                aml_domain.append(('credit', '>', 0))
            elif field == 'deb':
                aml_domain.append(('debit', '>', 0))
            aml_domains.append(expression.normalize_domain(aml_domain))
            if mode not in date_domain_by_mode:
                date_domain_by_mode[mode] = \
                    self.get_aml_domain_for_dates(date_from, date_to,
                                                  mode, target_move)
        assert aml_domains
        # TODO we could do this for more precision:
        #      AND(OR(aml_domains[mode]), date_domain[mode]) for each mode
        return expression.OR(aml_domains) + \
            expression.OR(date_domain_by_mode.values())
Пример #5
0
 def _account_codes_to_domain(self, account_codes):
     """Convert a comma separated list of account codes
     (possibly with wildcards) to a domain on account.account.
     """
     elems = []
     for account_code in account_codes.split(','):
         account_code = account_code.strip()
         if '%' in account_code:
             elems.append([('code', '=like', account_code)])
         else:
             elems.append([('code', '=', account_code)])
     return tuple(expression.OR(elems))
Пример #6
0
 def name_search(self, name='', args=None, operator='ilike', limit=100):
     results = super(TrainingPlan, self).name_search(name=name,
                                                     args=args,
                                                     operator=operator,
                                                     limit=limit)
     if not args:
         args = []
     domain = expression.OR([[('name', operator, name)],
                             [('code', operator, name)]])
     domain = expression.AND([domain, args or []])
     more_results = self.search(domain, limit=limit)
     return more_results and more_results.name_get() or results