diff --git a/bindings/python/example_scripts/account_analysis.py b/bindings/python/example_scripts/account_analysis.py index 0326941575..07dbf4e33f 100644 --- a/bindings/python/example_scripts/account_analysis.py +++ b/bindings/python/example_scripts/account_analysis.py @@ -45,7 +45,7 @@ from gnucash import Session, GncNumeric, Split # That will do an analysis on the account 'Assets:Test Account' from # gnucash_file.xac, all of the debits and all of the credits will be shown # and summed on for 12 monthly periods starting from January (1st month) 2010 -# +# # if you just want to see the credit and debit sums for each period, use # the debits-noshow and credits-noshow argument # @@ -92,7 +92,7 @@ def gnc_numeric_to_python_Decimal(numeric): exponent = int(log10(denominator)) assert( (10 ** exponent) == denominator ) return Decimal( (sign, digit_tuple, -exponent) ) - + def next_period_start(start_year, start_month, period_type): # add numbers of months for the period length @@ -112,7 +112,7 @@ def next_period_start(start_year, start_month, period_type): end_month = ( (end_month-1) % NUM_MONTHS ) + 1 return end_year, end_month - + def period_end(start_year, start_month, period_type): if period_type not in PERIODS: @@ -126,7 +126,7 @@ def period_end(start_year, start_month, period_type): # so we get a period end like # 2010-03-31 for period starting 2010-01 instead of 2010-04-01 return date(end_year, end_month, 1) - ONE_DAY - + def generate_period_boundaries(start_year, start_month, period_type, periods): for i in xrange(periods): @@ -192,7 +192,7 @@ def main(): ] # a copy of the above list with just the period start dates period_starts = [e[0] for e in period_list ] - + # insert and add all splits in the periods of interest for split in account_of_interest.GetSplitList(): trans = split.parent @@ -201,13 +201,13 @@ def main(): # use binary search to find the period that starts before or on # the transaction date period_index = bisect_right( period_starts, trans_date ) - 1 - + # ignore transactions with a date before the matching period start # (after subtracting 1 above start_index would be -1) # and after the last period_end if period_index >= 0 and \ trans_date <= period_list[len(period_list)-1][1]: - + # get the period bucket appropriate for the split in question period = period_list[period_index] @@ -220,7 +220,7 @@ def main(): # and the filtered results from the above if provide all the # protection we need assert( trans_date>= period[0] and trans_date <= period[1] ) - + split_amount = gnc_numeric_to_python_Decimal(split.GetAmount()) # if the amount is negative, this is a credit @@ -235,20 +235,20 @@ def main(): # # if we wanted to be really cool we'd keep the transactions period[2+debit_credit_offset].append( (trans, split) ) - + # add the debit or credit to the sum, using the above offset # to get in the right bucket period[4+debit_credit_offset] += split_amount csv_writer = csv.writer(stdout) csv_writer.writerow( ('period start', 'period end', 'debits', 'credits') ) - + def generate_detail_rows(values): return ( ('', '', '', '', trans.GetDescription(), gnc_numeric_to_python_Decimal(split.GetAmount())) for trans, split in values ) - + for start_date, end_date, debits, credits, debit_sum, credit_sum in \ period_list: diff --git a/bindings/python/example_scripts/change_tax_code.py b/bindings/python/example_scripts/change_tax_code.py index 56aab31834..85255cf214 100644 --- a/bindings/python/example_scripts/change_tax_code.py +++ b/bindings/python/example_scripts/change_tax_code.py @@ -24,7 +24,7 @@ def mark_account_with_code_as_tax_related(account, target_code): if mark_account_with_code_as_tax_related(child, target_code): return True return False - + # Change this path to your own gnucash_session = Session("/home/mark/python-bindings-help/test.xac") diff --git a/bindings/python/example_scripts/test_imbalance_transaction.py b/bindings/python/example_scripts/test_imbalance_transaction.py index 08c7cb7212..aa5eef0d41 100644 --- a/bindings/python/example_scripts/test_imbalance_transaction.py +++ b/bindings/python/example_scripts/test_imbalance_transaction.py @@ -41,7 +41,7 @@ from gnucash import Session, Transaction, Split, Account, GncNumeric, \ # You should try it out with a gnucash file with tranding accounts enabled # and trading accounts disabled -if len(argv) < 2: +if len(argv) < 2: print('not enough parameters') print('usage: test_imbalance_transaction.py {book_url}') print('examples:')