mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Support for having an account scu that doesn't match the account
commodity's scu. This allows a user to notice/correct a case where the two are out of whack and correct it (#100295), or to intentionally set them that way. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7677 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
45ba7f6cfd
commit
c98a3a1a8d
20
ChangeLog
20
ChangeLog
@ -1,3 +1,23 @@
|
||||
2002-12-11 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/gnc-ui.h: New help URLs for Wilddev.
|
||||
|
||||
* src/engine/Account.c:
|
||||
* src/gnome/glade/account.glade:
|
||||
* src/gnome-utils/dialog-account.c: Support for having an account
|
||||
scu that doesn't match the account commodity's scu. This allows a
|
||||
user to notice/correct a case where the two are out of whack and
|
||||
corect them (#100295), or to intentionally set them that
|
||||
way. (E.G. A currency trading account that trades in $0.0001 USD
|
||||
even though the scu for USD is $0.01.)
|
||||
|
||||
* src/backend/file/io-gncxml-v2.c: Call new routines to set the
|
||||
account non-standard scu flag, and to get the actual scu on the
|
||||
account regardless of the flag.
|
||||
|
||||
* src/backend/file/gnc-account-xml-v2.c: Read/write new indicator
|
||||
that the account scu doesn't match the account commodity's scu.
|
||||
|
||||
2002-12-11 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
* src/gnome-utils/dialog-transfer.c -- lookup and store entries in
|
||||
|
@ -59,6 +59,7 @@ const gchar *account_version_string = "2.0.0";
|
||||
#define act_type_string "act:type"
|
||||
#define act_commodity_string "act:commodity"
|
||||
#define act_commodity_scu_string "act:commodity-scu"
|
||||
#define act_non_standard_scu_string "act:non-standard-scu"
|
||||
#define act_code_string "act:code"
|
||||
#define act_description_string "act:description"
|
||||
#define act_slots_string "act:slots"
|
||||
@ -97,7 +98,10 @@ gnc_account_dom_tree_create(Account *act)
|
||||
xaccAccountGetCommodity(act)));
|
||||
|
||||
xmlAddChild(ret, int_to_dom_tree(act_commodity_scu_string,
|
||||
xaccAccountGetCommoditySCU(act)));
|
||||
xaccAccountGetCommoditySCUi(act)));
|
||||
|
||||
if (xaccAccountGetNonStdSCU(act))
|
||||
xmlNewChild(ret, NULL, act_non_standard_scu_string, NULL);
|
||||
|
||||
str = xaccAccountGetCode(act);
|
||||
if (str && strlen(str) > 0)
|
||||
@ -228,6 +232,16 @@ account_commodity_scu_handler (xmlNodePtr node, gpointer act_pdata)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
account_non_standard_scu_handler (xmlNodePtr node, gpointer act_pdata)
|
||||
{
|
||||
struct account_pdata *pdata = act_pdata;
|
||||
|
||||
xaccAccountSetNonStdSCU(pdata->account, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* The following depricated routines are here only to service
|
||||
* older XML files. */
|
||||
@ -372,6 +386,7 @@ static struct dom_tree_handler account_handlers_v2[] = {
|
||||
{ act_type_string, account_type_handler, 1, 0 },
|
||||
{ act_commodity_string, account_commodity_handler, 0, 0 },
|
||||
{ act_commodity_scu_string, account_commodity_scu_handler, 0, 0 },
|
||||
{ act_non_standard_scu_string, account_non_standard_scu_handler, 0, 0 },
|
||||
{ act_code_string, account_code_handler, 0, 0 },
|
||||
{ act_description_string, account_description_handler, 0, 0},
|
||||
{ act_slots_string, account_slots_handler, 0, 0 },
|
||||
@ -448,10 +463,9 @@ dom_tree_to_account (xmlNodePtr node, GNCBook *book)
|
||||
|
||||
successful = dom_tree_generic_parse (node, account_handlers_v2,
|
||||
&act_pdata);
|
||||
xaccAccountCommitEdit (accToRet);
|
||||
|
||||
if (!successful)
|
||||
{
|
||||
if (successful) {
|
||||
xaccAccountCommitEdit (accToRet);
|
||||
} else {
|
||||
PERR ("failed to parse account tree");
|
||||
xaccAccountDestroy (accToRet);
|
||||
accToRet = NULL;
|
||||
|
@ -169,7 +169,7 @@ clear_up_account_commodity(
|
||||
static void
|
||||
clear_up_transaction_commodity(
|
||||
gnc_commodity_table *tbl, Transaction *trans,
|
||||
gnc_commodity * (*getter) (Transaction *trans),
|
||||
gnc_commodity * (*getter) (const Transaction *trans),
|
||||
void (*setter) (Transaction *trans, gnc_commodity *comm))
|
||||
{
|
||||
gnc_commodity *gcom;
|
||||
@ -223,8 +223,8 @@ add_account_local(sixtp_gdv2 *data, Account *act)
|
||||
clear_up_account_commodity(table, act,
|
||||
xaccAccountGetCommodity,
|
||||
xaccAccountSetCommodity,
|
||||
xaccAccountGetCommoditySCU,
|
||||
xaccAccountSetCommoditySCU);
|
||||
xaccAccountGetCommoditySCUi,
|
||||
xaccAccountSetCommoditySCUandFlag);
|
||||
|
||||
xaccAccountScrubCommodity (act, data->book);
|
||||
|
||||
|
@ -108,6 +108,7 @@ xaccInitAccount (Account * acc, GNCBook *book)
|
||||
|
||||
acc->commodity = NULL;
|
||||
acc->commodity_scu = 0;
|
||||
acc->non_standard_scu = FALSE;
|
||||
|
||||
acc->splits = NULL;
|
||||
acc->lots = NULL;
|
||||
@ -172,6 +173,7 @@ xaccCloneAccountSimple(const Account *from, GNCBook *book)
|
||||
|
||||
ret->commodity = from->commodity;
|
||||
ret->commodity_scu = from->commodity_scu;
|
||||
ret->non_standard_scu = from->non_standard_scu;
|
||||
ret->core_dirty = TRUE;
|
||||
|
||||
LEAVE (" ");
|
||||
@ -206,6 +208,7 @@ xaccCloneAccount (const Account *from, GNCBook *book)
|
||||
|
||||
ret->commodity = from->commodity;
|
||||
ret->commodity_scu = from->commodity_scu;
|
||||
ret->non_standard_scu = from->non_standard_scu;
|
||||
ret->core_dirty = TRUE;
|
||||
|
||||
/* make a note of where the copy came from */
|
||||
@ -1032,7 +1035,7 @@ xaccAccountInsertSplit (Account *acc, Split *split)
|
||||
/* if the denominator can't be exactly converted, it's an error */
|
||||
/* FIXME : need to enforce ordering of insertion/value */
|
||||
split->amount = gnc_numeric_convert(split->amount,
|
||||
acc->commodity_scu,
|
||||
xaccAccountGetCommoditySCU(acc),
|
||||
GNC_RND_ROUND);
|
||||
|
||||
/* if this split belongs to another account, remove it from there
|
||||
@ -1444,7 +1447,7 @@ update_split_commodity(Account * acc)
|
||||
|
||||
xaccTransBeginEdit (trans);
|
||||
s->amount = gnc_numeric_convert(s->amount,
|
||||
acc->commodity_scu,
|
||||
xaccAccountGetCommoditySCU(acc),
|
||||
GNC_RND_ROUND);
|
||||
xaccTransCommitEdit (trans);
|
||||
}
|
||||
@ -1489,12 +1492,66 @@ xaccAccountSetCommoditySCU (Account *acc, int scu)
|
||||
xaccAccountCommitEdit(acc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the account scu and then check to see if it is the same as the
|
||||
* commodity scu. This function is called when parsing the data file
|
||||
* and is designed to catch cases where the two were accidentally set
|
||||
* to mismatched values in the past.
|
||||
*/
|
||||
void
|
||||
xaccAccountSetCommoditySCUandFlag (Account *acc, int scu)
|
||||
{
|
||||
if (!acc) return;
|
||||
|
||||
xaccAccountBeginEdit(acc);
|
||||
{
|
||||
acc->commodity_scu = scu;
|
||||
if (scu != gnc_commodity_get_fraction(acc->commodity))
|
||||
acc->non_standard_scu = TRUE;
|
||||
mark_account (acc);
|
||||
}
|
||||
acc->core_dirty = TRUE;
|
||||
xaccAccountCommitEdit(acc);
|
||||
}
|
||||
|
||||
int
|
||||
xaccAccountGetCommoditySCUi (Account * acc)
|
||||
{
|
||||
if (!acc) return 0;
|
||||
|
||||
return acc->commodity_scu;
|
||||
}
|
||||
|
||||
int
|
||||
xaccAccountGetCommoditySCU (Account * acc)
|
||||
{
|
||||
if (!acc) return 0;
|
||||
|
||||
return acc->commodity_scu;
|
||||
if (acc->non_standard_scu)
|
||||
return acc->commodity_scu;
|
||||
return gnc_commodity_get_fraction(acc->commodity);
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetNonStdSCU (Account *acc, gboolean flag)
|
||||
{
|
||||
if (!acc) return;
|
||||
|
||||
xaccAccountBeginEdit(acc);
|
||||
{
|
||||
acc->non_standard_scu = flag;
|
||||
mark_account (acc);
|
||||
}
|
||||
acc->core_dirty = TRUE;
|
||||
xaccAccountCommitEdit(acc);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xaccAccountGetNonStdSCU (Account * acc)
|
||||
{
|
||||
if (!acc) return 0;
|
||||
|
||||
return acc->non_standard_scu;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
|
@ -266,7 +266,11 @@ const char * xaccAccountGetLastNum (Account *account);
|
||||
void xaccAccountSetCommodity (Account *account, gnc_commodity *comm);
|
||||
gnc_commodity * xaccAccountGetCommodity (Account *account);
|
||||
int xaccAccountGetCommoditySCU (Account *account);
|
||||
int xaccAccountGetCommoditySCUi (Account *account);
|
||||
void xaccAccountSetCommoditySCU (Account *account, int frac);
|
||||
void xaccAccountSetCommoditySCUandFlag (Account *account, int frac);
|
||||
void xaccAccountSetNonStdSCU (Account *account, gboolean flag);
|
||||
gboolean xaccAccountGetNonStdSCU (Account *account);
|
||||
|
||||
|
||||
gnc_numeric xaccAccountGetBalance (Account *account);
|
||||
|
@ -101,6 +101,7 @@ struct account_s
|
||||
*/
|
||||
gnc_commodity * commodity;
|
||||
int commodity_scu;
|
||||
gboolean non_standard_scu;
|
||||
|
||||
/* The parent and children pointers are used to implement an account
|
||||
* hierarchy, of accounts that have sub-accounts ("detail accounts").
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <gnome.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "AccWindow.h"
|
||||
@ -79,6 +80,7 @@ struct _AccountWindow
|
||||
GtkWidget * notes_text;
|
||||
|
||||
GtkWidget * commodity_edit;
|
||||
GtkWidget * account_scu;
|
||||
|
||||
GList * valid_types;
|
||||
GtkWidget * type_list;
|
||||
@ -159,8 +161,8 @@ gnc_account_to_ui(AccountWindow *aw)
|
||||
Account *account = aw_get_account (aw);
|
||||
gnc_commodity * commodity;
|
||||
const char *string;
|
||||
gboolean tax_related, placeholder;
|
||||
gint pos = 0;
|
||||
gboolean tax_related, placeholder, nonstd_scu;
|
||||
gint pos = 0, index;
|
||||
|
||||
if (!account)
|
||||
return;
|
||||
@ -177,6 +179,15 @@ gnc_account_to_ui(AccountWindow *aw)
|
||||
gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
|
||||
commodity);
|
||||
|
||||
nonstd_scu = xaccAccountGetNonStdSCU (account);
|
||||
if (nonstd_scu) {
|
||||
index = xaccAccountGetCommoditySCUi(account);
|
||||
index = log10(index) + 1;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
gtk_option_menu_set_history(GTK_OPTION_MENU(aw->account_scu), index);
|
||||
|
||||
string = xaccAccountGetCode (account);
|
||||
if (string == NULL) string = "";
|
||||
gtk_entry_set_text(GTK_ENTRY(aw->code_entry), string);
|
||||
@ -293,8 +304,9 @@ gnc_ui_to_account(AccountWindow *aw)
|
||||
const char *string;
|
||||
gboolean tax_related, placeholder;
|
||||
gnc_numeric balance;
|
||||
gboolean use_equity;
|
||||
gboolean use_equity, nonstd;
|
||||
time_t date;
|
||||
gint index, old_scu, new_scu;
|
||||
|
||||
if (!account)
|
||||
return;
|
||||
@ -317,8 +329,20 @@ gnc_ui_to_account(AccountWindow *aw)
|
||||
commodity = (gnc_commodity *)
|
||||
gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
|
||||
if (commodity &&
|
||||
!gnc_commodity_equiv(commodity, xaccAccountGetCommodity (account)))
|
||||
!gnc_commodity_equiv(commodity, xaccAccountGetCommodity (account))) {
|
||||
xaccAccountSetCommodity (account, commodity);
|
||||
old_scu = 0;
|
||||
} else {
|
||||
old_scu = xaccAccountGetCommoditySCU(account);
|
||||
}
|
||||
|
||||
index = gnc_option_menu_get_active(aw->account_scu);
|
||||
nonstd = (index != 0);
|
||||
if (nonstd != xaccAccountGetNonStdSCU(account))
|
||||
xaccAccountSetNonStdSCU(account, nonstd);
|
||||
new_scu = (nonstd ? pow(10,index-1) : gnc_commodity_get_fraction(commodity));
|
||||
if (old_scu != new_scu)
|
||||
xaccAccountSetCommoditySCU(account, new_scu);
|
||||
|
||||
string = gtk_entry_get_text (GTK_ENTRY(aw->code_entry));
|
||||
old_string = xaccAccountGetCode (account);
|
||||
@ -1502,6 +1526,9 @@ gnc_account_window_create(AccountWindow *aw)
|
||||
gtk_signal_connect (GTK_OBJECT (aw->commodity_edit), "changed",
|
||||
GTK_SIGNAL_FUNC (commodity_changed_cb), aw);
|
||||
|
||||
aw->account_scu = glade_xml_get_widget (xml, "account_scu");
|
||||
gnc_option_menu_init(aw->account_scu);
|
||||
|
||||
if (gnc_price_source_have_fq()) {
|
||||
gtk_widget_destroy(glade_xml_get_widget (xml, "finance_quote_warning"));
|
||||
} else {
|
||||
|
@ -154,6 +154,23 @@
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label811</name>
|
||||
<label>Account Code:</label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label808</name>
|
||||
@ -190,8 +207,8 @@
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label811</name>
|
||||
<label>Account Code:</label>
|
||||
<name>label8477389</name>
|
||||
<label>Smallest Fraction:</label>
|
||||
<justify>GTK_JUSTIFY_RIGHT</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
@ -233,6 +250,21 @@
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkEntry</class>
|
||||
<name>code_entry</name>
|
||||
<can_focus>True</can_focus>
|
||||
<editable>True</editable>
|
||||
<text_visible>True</text_visible>
|
||||
<text_max_length>0</text_max_length>
|
||||
<text></text>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkEntry</class>
|
||||
<name>description_entry</name>
|
||||
@ -265,13 +297,20 @@
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkEntry</class>
|
||||
<name>code_entry</name>
|
||||
<class>GtkOptionMenu</class>
|
||||
<name>account_scu</name>
|
||||
<tooltip>Smallest fraction of this commodity that can be referenced.</tooltip>
|
||||
<can_focus>True</can_focus>
|
||||
<editable>True</editable>
|
||||
<text_visible>True</text_visible>
|
||||
<text_max_length>0</text_max_length>
|
||||
<text></text>
|
||||
<items>Use Commodity Value
|
||||
1
|
||||
1/10
|
||||
1/100
|
||||
1/1000
|
||||
1/10000
|
||||
1/100000
|
||||
1/1000000
|
||||
</items>
|
||||
<initial_choice>0</initial_choice>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
|
Loading…
Reference in New Issue
Block a user