Ejemplo n.º 1
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)
         # TODO this takes the fy from the first company
         # make that user controllable (nice to have)?
         fy_date_from = \
             self.companies.\
             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)
         # TODO this takes the fy from the first company
         # make that user controllable (nice to have)?
         fy_date_from = \
             self.companies.\
             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.º 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)
         # TODO this takes the fy from the first company
         # make that user controllable (nice to have)?
         fy_date_from = self.companies[0].compute_fiscalyear_dates(
             date_from_date)["date_from"]
         domain = [
             "|",
             ("date", ">=", fields.Date.to_string(fy_date_from)),
             ("account_id.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)
         # TODO this takes the fy from the first company
         # make that user controllable (nice to have)?
         fy_date_from = self.companies[0].compute_fiscalyear_dates(
             date_from_date)["date_from"]
         domain = [
             ("date", "<", fields.Date.to_string(fy_date_from)),
             ("account_id.user_type_id.include_initial_balance", "=",
              False),
         ]
     if target_move == "posted":
         domain.append(("move_id.state", "=", "posted"))
     return expression.normalize_domain(domain)
Ejemplo n.º 3
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
        # 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())