gnucash/libgnucash/app-utils/prefs.scm

101 lines
4.0 KiB
Scheme
Raw Normal View History

;; Preferences
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
;; (define gnc:*double-entry-restriction*
;; (gnc:make-config-var
;; "Determines how the splits in a transaction will be balanced.
;; The following values have significance:
;;
;; #f anything goes
;;
;; 'force The sum of all splits in a transaction will be
;; forced to be zero, even if this requires the
;; creation of additional splits. Note that a split
;; whose value is zero (e.g. a stock price) can exist
;; by itself. Otherwise, all splits must come in at
;; least pairs.
;;
;; 'collect splits without parents will be forced into a
;; lost & found account. (Not implemented)"
;; (lambda (var value)
;; (cond
;; ((eq? value #f)
;; (_gnc_set_force_double_entry_ 0)
;; (list value))
;; ((eq? value 'force)
;; (_gnc_set_force_double_entry_ 1)
;; (list value))
;; ((eq? value 'collect)
;; (gnc:warn
;; "gnc:*double-entry-restriction* -- 'collect not supported yet. "
;; "Ignoring.")
;; #f)
;; (else
;; (gnc:warn
;; "gnc:*double-entry-restriction* -- " value " not supported. Ignoring.")
;; #f)))
;; eq?
;; #f))
(use-modules (gnucash gettext))
;; Old-school config files depend on this API
(define (gnc:config-file-format-version version) #t)
;;;;;; Create config vars
(define gnc:*debit-strings*
(list (cons ACCT-TYPE-NONE (N_ "Funds In"))
(cons ACCT-TYPE-BANK (N_ "Deposit"))
(cons ACCT-TYPE-CASH (N_ "Receive"))
(cons ACCT-TYPE-CREDIT (N_ "Payment"))
(cons ACCT-TYPE-ASSET (N_ "Increase"))
(cons ACCT-TYPE-LIABILITY (N_ "Decrease"))
(cons ACCT-TYPE-STOCK (N_ "Buy"))
(cons ACCT-TYPE-MUTUAL (N_ "Buy"))
(cons ACCT-TYPE-CURRENCY (N_ "Buy"))
(cons ACCT-TYPE-INCOME (N_ "Charge"))
(cons ACCT-TYPE-EXPENSE (N_ "Expense"))
(cons ACCT-TYPE-PAYABLE (N_ "Payment"))
(cons ACCT-TYPE-RECEIVABLE (N_ "Invoice"))
Bug #537476: Implement currency trading accounts optionally, to be enabled per-book. Patch by Mike Alexander: This patch implements trading accounts somewhat as described in Peter Selinger's document at <http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he describes it as a multiple currency problem, it really applies to any transactions involving multiple commodities (for example buying or selling a stock) Hence I've called the trading accounts "commodity exchange accounts" which seems more descriptive. In summary these patches add an option to use commodity exchange accounts and if it is on a transaction must be balanced both in value (in the transaction currency) and in each commodity or currency used in any split in the transaction. If a transaction only contains splits in the transaction currency then this is the same rule as Gnucash has always enforced. In this patch, the option to use trading accounts has been moved from Edit->Preferences to File->Properties and is now associated with the active book instead of being a global option. If you have set the global value on in a previous version you will need to set it on again in each file for which you want trading accounts, the previous global setting will be ignored. A more detailed list of changes follows: 1. Added a "Use commodity exchange accounts" per-book option. 2. Added gnc_monetary and MonetaryList data types. 3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new xaccTransGetImbalance that returns a MonetaryList. Also added xaccTransIsBalanced to see if the transaction is balanced without returning a GList that needs to be freed. It calls both xaccTransGetImbalance and xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to either without being unbalanced with regard to the other. 4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced. 5. Changed gnc_split_register_balance_trans to not offer to adjust an existing split if there imbalances in multiple currencies. Because of bugs in the register code this is rarely called. 6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance, assuming that they won't create multiple currency trasactions. 7. Changed xaccTransScrubImbalance to create a balancing split for each imbalanced commodity in the transaction. Also balances the transaction value. The commodity balancing splits go into accounts in the hierarchy Trading:NAMESPACE:COMMODITY. The value balancing splits go into Imbalance-CURRENCY as before. 8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of xaccTransGetImbalance. 9. Changed gnc_split_register_get_debcred_entry to sometimes use the split amount instead of value if using currency accounts. If the register is a stock register (i.e., shows shares and prices), it uses the value if the split is in the register commodity (i.e. is for the stock) and the amount otherwise. It shows the currency symbol unless the commodity is the default currency. If the register is not a stock register it always uses the amount and shows the currency symbol if the split is not in the register commodity. Also changed it to not return a value for a null split unless the transaction is unbalanced in exactly one currency. This is what goes in a blank split as the proposed value. 10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the imbalance, assuming that importers don't create transactions in multiple currencies. Also same change in gnc_import_process_trans_item, downloaded_transaction_append, and gnc_import_TransInfo_is_balanced. 11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use xaccTransGetImbalanceValue. As far as I can tell this is only used by the "pd-balance" query type in gnc_scm2query_term_query_v1() defined in engine-helpers.c. This query type only tests the result for zero/non-zero. 12. Changed xaccTransGetAccountConvRate to accept any split into the correct commodity instead of insisting on one into the provided account. Then can use it in xaccTransScrubImbalance to set the value of the imbalance split from its amount, however later changed xaccTransScrubImbalance to not use it. Instead it sets the value for the new split correctly to keep the value of the whole transaction balanced. 13. Changed the balance sheet report to include a new option to not compute unrealized gains and losses. 14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything if given a stock register where the value cell doesn't contain the value. 15. Also related to 9, changed gnc_split_register_save_amount_values to set the amount and value fields in the split correctly when using trading accounts. 16. Changed the new account and edit account dialogs to allow any commodity or currency for an income account if using trading accounts. It would be better to add a new account type for trading accounts, but that's a big deal and I'll leave that for later after we see whether this set of changes is going to be accepted or rejected. 17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value is really the split's amount if using trading accounts. 18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity exchange accounts. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 14:11:03 -06:00
(cons ACCT-TYPE-TRADING (N_ "Decrease"))
(cons ACCT-TYPE-EQUITY (N_ "Decrease"))))
(define gnc:*credit-strings*
(list (cons ACCT-TYPE-NONE (N_ "Funds Out"))
(cons ACCT-TYPE-BANK (N_ "Withdrawal"))
(cons ACCT-TYPE-CASH (N_ "Spend"))
(cons ACCT-TYPE-CREDIT (N_ "Charge"))
(cons ACCT-TYPE-ASSET (N_ "Decrease"))
(cons ACCT-TYPE-LIABILITY (N_ "Increase"))
(cons ACCT-TYPE-STOCK (N_ "Sell"))
(cons ACCT-TYPE-MUTUAL (N_ "Sell"))
(cons ACCT-TYPE-CURRENCY (N_ "Sell"))
(cons ACCT-TYPE-INCOME (N_ "Income"))
(cons ACCT-TYPE-EXPENSE (N_ "Rebate"))
(cons ACCT-TYPE-PAYABLE (N_ "Bill"))
(cons ACCT-TYPE-RECEIVABLE (N_ "Payment"))
Bug #537476: Implement currency trading accounts optionally, to be enabled per-book. Patch by Mike Alexander: This patch implements trading accounts somewhat as described in Peter Selinger's document at <http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he describes it as a multiple currency problem, it really applies to any transactions involving multiple commodities (for example buying or selling a stock) Hence I've called the trading accounts "commodity exchange accounts" which seems more descriptive. In summary these patches add an option to use commodity exchange accounts and if it is on a transaction must be balanced both in value (in the transaction currency) and in each commodity or currency used in any split in the transaction. If a transaction only contains splits in the transaction currency then this is the same rule as Gnucash has always enforced. In this patch, the option to use trading accounts has been moved from Edit->Preferences to File->Properties and is now associated with the active book instead of being a global option. If you have set the global value on in a previous version you will need to set it on again in each file for which you want trading accounts, the previous global setting will be ignored. A more detailed list of changes follows: 1. Added a "Use commodity exchange accounts" per-book option. 2. Added gnc_monetary and MonetaryList data types. 3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new xaccTransGetImbalance that returns a MonetaryList. Also added xaccTransIsBalanced to see if the transaction is balanced without returning a GList that needs to be freed. It calls both xaccTransGetImbalance and xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to either without being unbalanced with regard to the other. 4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced. 5. Changed gnc_split_register_balance_trans to not offer to adjust an existing split if there imbalances in multiple currencies. Because of bugs in the register code this is rarely called. 6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance, assuming that they won't create multiple currency trasactions. 7. Changed xaccTransScrubImbalance to create a balancing split for each imbalanced commodity in the transaction. Also balances the transaction value. The commodity balancing splits go into accounts in the hierarchy Trading:NAMESPACE:COMMODITY. The value balancing splits go into Imbalance-CURRENCY as before. 8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of xaccTransGetImbalance. 9. Changed gnc_split_register_get_debcred_entry to sometimes use the split amount instead of value if using currency accounts. If the register is a stock register (i.e., shows shares and prices), it uses the value if the split is in the register commodity (i.e. is for the stock) and the amount otherwise. It shows the currency symbol unless the commodity is the default currency. If the register is not a stock register it always uses the amount and shows the currency symbol if the split is not in the register commodity. Also changed it to not return a value for a null split unless the transaction is unbalanced in exactly one currency. This is what goes in a blank split as the proposed value. 10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the imbalance, assuming that importers don't create transactions in multiple currencies. Also same change in gnc_import_process_trans_item, downloaded_transaction_append, and gnc_import_TransInfo_is_balanced. 11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use xaccTransGetImbalanceValue. As far as I can tell this is only used by the "pd-balance" query type in gnc_scm2query_term_query_v1() defined in engine-helpers.c. This query type only tests the result for zero/non-zero. 12. Changed xaccTransGetAccountConvRate to accept any split into the correct commodity instead of insisting on one into the provided account. Then can use it in xaccTransScrubImbalance to set the value of the imbalance split from its amount, however later changed xaccTransScrubImbalance to not use it. Instead it sets the value for the new split correctly to keep the value of the whole transaction balanced. 13. Changed the balance sheet report to include a new option to not compute unrealized gains and losses. 14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything if given a stock register where the value cell doesn't contain the value. 15. Also related to 9, changed gnc_split_register_save_amount_values to set the amount and value fields in the split correctly when using trading accounts. 16. Changed the new account and edit account dialogs to allow any commodity or currency for an income account if using trading accounts. It would be better to add a new account type for trading accounts, but that's a big deal and I'll leave that for later after we see whether this set of changes is going to be accepted or rejected. 17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value is really the split's amount if using trading accounts. 18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity exchange accounts. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 14:11:03 -06:00
(cons ACCT-TYPE-TRADING (N_ "Increase"))
(cons ACCT-TYPE-EQUITY (N_ "Increase"))))
(define (gnc:get-debit-string type)
(_ (assoc-ref gnc:*debit-strings* type)))
(define (gnc:get-credit-string type)
(_ (assoc-ref gnc:*credit-strings* type)))