Ejemplo n.º 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())
Ejemplo n.º 2
0
 def get_aml_domain_for_dates(self, date_from, date_to,
                              mode,
                              target_move):
     if mode == self.MODE_VARIATION:
         domain = [('date', '>=', date_from), ('date', '<=', date_to)]
     elif mode in (self.MODE_INITIAL, self.MODE_END):
         # for income and expense account, sum from the beginning
         # of the current fiscal year only, for balance sheet accounts
         # sum from the beginning of time
         date_from_date = fields.Date.from_string(date_from)
         fy_date_from = \
             self.company.\
             compute_fiscalyear_dates(date_from_date)['date_from']
         domain = ['|',
                   ('date', '>=', fields.Date.to_string(fy_date_from)),
                   ('user_type_id.include_initial_balance', '=', True)]
         if mode == self.MODE_INITIAL:
             domain.append(('date', '<', date_from))
         elif mode == self.MODE_END:
             domain.append(('date', '<=', date_to))
     elif mode == self.MODE_UNALLOCATED:
         date_from_date = fields.Date.from_string(date_from)
         fy_date_from = \
             self.company.\
             compute_fiscalyear_dates(date_from_date)['date_from']
         domain = [('date', '<', fields.Date.to_string(fy_date_from)),
                   ('user_type_id.include_initial_balance', '=', False)]
     if target_move == 'posted':
         domain.append(('move_id.state', '=', 'posted'))
     return expression.normalize_domain(domain)
 def get_aml_domain_for_dates(self, date_from, date_to, mode, target_move):
     if mode == self.MODE_VARIATION:
         domain = [('date', '>=', date_from), ('date', '<=', date_to)]
     elif mode in (self.MODE_INITIAL, self.MODE_END):
         # for income and expense account, sum from the beginning
         # of the current fiscal year only, for balance sheet accounts
         # sum from the beginning of time
         date_from_date = fields.Date.from_string(date_from)
         fy_date_from = \
             self.company.\
             compute_fiscalyear_dates(date_from_date)['date_from']
         domain = [
             '|', ('date', '>=', fields.Date.to_string(fy_date_from)),
             ('user_type_id.include_initial_balance', '=', True)
         ]
         if mode == self.MODE_INITIAL:
             domain.append(('date', '<', date_from))
         elif mode == self.MODE_END:
             domain.append(('date', '<=', date_to))
     elif mode == self.MODE_UNALLOCATED:
         date_from_date = fields.Date.from_string(date_from)
         fy_date_from = \
             self.company.\
             compute_fiscalyear_dates(date_from_date)['date_from']
         domain = [('date', '<', fields.Date.to_string(fy_date_from)),
                   ('user_type_id.include_initial_balance', '=', False)]
     if target_move == 'posted':
         domain.append(('move_id.state', '=', 'posted'))
     return expression.normalize_domain(domain)
Ejemplo n.º 4
0
 def search(self, args, offset=0, limit=None, order=None, count=False):
     """Include commercial name in direct name search."""
     args = expression.normalize_domain(args)
     for arg in args:
         if isinstance(arg, (list, tuple)):
             if arg[0] in ['name', 'display_name']:
                 index = args.index(arg)
                 args = (
                     args[:index] + ['|', ('comercial', arg[1], arg[2])] +
                     args[index:]
                 )
                 break
     return super(ResPartner, self).search(
         args, offset=offset, limit=limit, order=order, count=count,
     )
Ejemplo n.º 5
0
 def get_aml_domain_for_dates(self, date_from, date_to, period_from,
                              period_to, mode, target_move):
     if period_from and period_to:
         period_ids = self._get_period_ids_for_mode(period_from, period_to,
                                                    mode)
         domain = [('period_id', 'in', period_ids)]
     else:
         if mode == MODE_VARIATION:
             domain = [('date', '>=', date_from), ('date', '<=', date_to)]
         else:
             raise UserError(
                 _("Modes i and e are only applicable for "
                   "fiscal periods"))
     if target_move == 'posted':
         domain.append(('move_id.state', '=', 'posted'))
     return expression.normalize_domain(domain)
Ejemplo n.º 6
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())
Ejemplo n.º 7
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, 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])
            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
        return expression.OR(aml_domains) + \
            expression.OR(date_domain_by_mode.values())