示例#1
0
def filter_transactions(xactions, options):
    '''
    Filter a list of transactions by certain criteria.
    '''

    filtered_xactions = xactions

    date_sequence = datetools.DateSequence([])
    if hasattr(options, 'dates') and options.dates is not None:
        date_sequence.extend(options.dates)
    if hasattr(options, 'dates_files'):
        for dates_file in options.dates_files:
            date_sequence.extend(
                datetools.parse_date_sequence_file(dates_file))
    if not date_sequence.is_empty:
        filtered_xactions = _filter_transactions_with_non_matching_dates(
            filtered_xactions, date_sequence)

    if hasattr(options, 'include_regexs') and len(options.include_regexs) > 0:
        filtered_xactions = _filter_transactions_with_non_matching_descriptions(
            filtered_xactions, options.include_regexs)

    if hasattr(options, 'exclude_regexs') and len(options.exclude_regexs) > 0:
        filtered_xactions = _filter_transactions_with_matching_descriptions(
            filtered_xactions, options.exclude_regexs)

    if hasattr(options, 'no_tags') and options.no_tags:
        filtered_xactions = _filter_transactions_without_tags(
            filtered_xactions)

    return filtered_xactions
 def test_two_dates_on_separate_lines(self):
     test_file_path = self._create_test_file('2019-05-21\n2019-05-22')
     self.assertEqual(
         datetools.parse_date_sequence('2019-05-21,2019-05-22'),
         datetools.parse_date_sequence_file(test_file_path)
     )
 def test_single_date_with_trailing_newline(self):
     test_file_path = self._create_test_file('2019-05-21\n')
     self.assertEqual(
         datetools.parse_date_sequence('2019-05-21'),
         datetools.parse_date_sequence_file(test_file_path)
     )
 def test_empty(self):
     test_file_path = self._create_test_file('')
     self.assertEqual(
         datetools.DateSequence([]),
         datetools.parse_date_sequence_file(test_file_path)
     )