mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Modify Tax Info on Account Page to display or not display sub-account info based on whether row is expanded.
Revert changes made in gnc-ui-util.c in rev 20039 and instead put those changes in new function: gnc_ui_account_get_tax_info_sub_acct_string. Define a new column, GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT, in gnc-tree-model-account.c filled with gnc_ui_account_get_tax_info_sub_acct_string. Modify gnc-tree-view-account.c to define a tax_info_data_func that displays only the the data in the GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO model column if the row is expanded; otherwise it combines it with the data in the GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT model column. Modily the view creation function to use the new tax_info_data_func. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20207 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2897cd4d0e
commit
9968d038a2
@ -468,24 +468,22 @@ gnc_ui_account_get_tax_info_string (const Account *account)
|
||||
SCM category;
|
||||
SCM code_scm;
|
||||
SCM tax_entity_type;
|
||||
const gchar *form, *desc, *copy_txt, *descendant_txt;
|
||||
const gchar *form, *desc, *copy_txt;
|
||||
gint64 copy_number;
|
||||
SCM scm;
|
||||
GList *descendant, *account_descendants;
|
||||
|
||||
if (!account)
|
||||
return NULL;
|
||||
|
||||
account_descendants = gnc_account_get_descendants (account);
|
||||
if (account_descendants)
|
||||
tax_related = xaccAccountGetTaxRelated (account);
|
||||
code = xaccAccountGetTaxUSCode (account);
|
||||
|
||||
if (!code)
|
||||
{
|
||||
gint sub_acct_tax_number = 0;
|
||||
for (descendant = account_descendants; descendant;
|
||||
descendant = g_list_next(descendant))
|
||||
{
|
||||
if (xaccAccountGetTaxRelated (descendant->data))
|
||||
sub_acct_tax_number++;
|
||||
}
|
||||
if (!tax_related)
|
||||
return NULL;
|
||||
/* tax_related && !code */
|
||||
else
|
||||
/* Translators: This and the following strings appear on
|
||||
* the account tab if the Tax Info column is displayed,
|
||||
* i.e. if the user wants to record the tax form number
|
||||
@ -495,34 +493,7 @@ gnc_ui_account_get_tax_info_string (const Account *account)
|
||||
* account generally corresponds to a specific line number
|
||||
* on a paper form and each form has a unique
|
||||
* identification (e.g., Form 1040, Schedule A). */
|
||||
descendant_txt = (sub_acct_tax_number == 0) ? "" :
|
||||
g_strdup_printf (_("(Tax-related subaccounts: %d)"),
|
||||
sub_acct_tax_number);
|
||||
}
|
||||
else
|
||||
descendant_txt = "";
|
||||
|
||||
tax_related = xaccAccountGetTaxRelated (account);
|
||||
code = xaccAccountGetTaxUSCode (account);
|
||||
|
||||
if (!code)
|
||||
{
|
||||
if (!tax_related)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return NULL;
|
||||
else
|
||||
return g_strdup_printf ("%s", descendant_txt);
|
||||
}
|
||||
/* tax_related && !code */
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup (_("Tax-related but has no tax code"));
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Tax-related but has no tax code; %s"), descendant_txt);
|
||||
}
|
||||
return g_strdup (_("Tax-related but has no tax code"));
|
||||
}
|
||||
else /* with tax code */
|
||||
{
|
||||
@ -531,13 +502,7 @@ gnc_ui_account_get_tax_info_string (const Account *account)
|
||||
|
||||
tax_type = gnc_get_current_book_tax_type ();
|
||||
if (tax_type == NULL || (safe_strcmp (tax_type, "") == 0))
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup (_("Tax entity type not specified"));
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Tax entity type not specified; %s"), descendant_txt);
|
||||
}
|
||||
return g_strdup (_("Tax entity type not specified"));
|
||||
atype = xaccAccountGetType (account);
|
||||
/* tax_entity_type = scm_from_locale_string (tax_type); <- requires guile 1.8*/
|
||||
tax_entity_type = scm_makfrom0str (tax_type); /* <-guile 1.6 */
|
||||
@ -602,27 +567,13 @@ gnc_ui_account_get_tax_info_string (const Account *account)
|
||||
if (category == SCM_UNDEFINED)
|
||||
{
|
||||
if (tax_related)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Tax type %s: invalid code %s for account type"),
|
||||
tax_type, num_code);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Tax type %s: invalid code %s for account type; %s"),
|
||||
tax_type, num_code, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Tax type %s: invalid code %s for account type"),
|
||||
tax_type, num_code);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; tax type %s: invalid code %s for account type"),
|
||||
tax_type, num_code);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; tax type %s: invalid code %s for account type; %s"),
|
||||
tax_type, num_code, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; tax type %s: invalid code %s for account type"),
|
||||
tax_type, num_code);
|
||||
}
|
||||
|
||||
code_scm = scm_str2symbol (code);
|
||||
@ -630,107 +581,51 @@ gnc_ui_account_get_tax_info_string (const Account *account)
|
||||
if (!scm_is_string (scm))
|
||||
{
|
||||
if (tax_related)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Invalid code %s for tax type %s"),
|
||||
num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Invalid code %s for tax type %s; %s"),
|
||||
num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Invalid code %s for tax type %s"),
|
||||
num_code, tax_type);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; invalid code %s for tax type %s"),
|
||||
num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; invalid code %s for tax type %s; %s"),
|
||||
num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; invalid code %s for tax type %s"),
|
||||
num_code, tax_type);
|
||||
}
|
||||
|
||||
form = scm_to_locale_string (scm);
|
||||
if (!form)
|
||||
{
|
||||
if (tax_related)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("No form: code %s, tax type %s"), num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("No form: code %s, tax type %s; %s"),
|
||||
num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("No form: code %s, tax type %s"), num_code, tax_type);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no form: code %s, tax type %s"),
|
||||
num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no form: code %s, tax type %s; %s"),
|
||||
num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no form: code %s, tax type %s"),
|
||||
num_code, tax_type);
|
||||
}
|
||||
|
||||
scm = scm_call_3 (get_desc, category, code_scm, tax_entity_type);
|
||||
if (!scm_is_string (scm))
|
||||
{
|
||||
if (tax_related)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("No description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("No description: form %s, code %s, tax type %s; %s"),
|
||||
form, num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("No description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no description: form %s, code %s, tax type %s; %s"),
|
||||
form, num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
}
|
||||
|
||||
desc = scm_to_locale_string (scm);
|
||||
if (!desc)
|
||||
{
|
||||
if (tax_related)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("No description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("No description: form %s, code %s, tax type %s; %s"),
|
||||
form, num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("No description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no description: form %s, code %s, tax type %s; %s"),
|
||||
form, num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; no description: form %s, code %s, tax type %s"),
|
||||
form, num_code, tax_type);
|
||||
}
|
||||
|
||||
copy_number = xaccAccountGetTaxUSCopyNumber (account);
|
||||
@ -740,35 +635,52 @@ gnc_ui_account_get_tax_info_string (const Account *account)
|
||||
if (tax_related)
|
||||
{
|
||||
if (safe_strcmp (form, "") == 0)
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf ("%s", desc);
|
||||
else
|
||||
return g_strdup_printf ("%s; %s", desc, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf ("%s", desc);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf ("%s%s: %s", form, copy_txt, desc);
|
||||
else
|
||||
return g_strdup_printf ("%s%s: %s; %s",
|
||||
form, copy_txt, desc, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf ("%s%s: %s", form, copy_txt, desc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (descendant_txt, "") == 0)
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; %s%s: %s (code %s, tax type %s)"),
|
||||
form, copy_txt, desc, num_code, tax_type);
|
||||
else
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; %s%s: %s (code %s, tax type %s); %s"),
|
||||
form, copy_txt, desc, num_code, tax_type, descendant_txt);
|
||||
}
|
||||
return g_strdup_printf
|
||||
(_("Not tax-related; %s%s: %s (code %s, tax type %s)"),
|
||||
form, copy_txt, desc, num_code, tax_type);
|
||||
}
|
||||
}
|
||||
|
||||
/* Caller is responsible for g_free'ing returned memory */
|
||||
char *
|
||||
gnc_ui_account_get_tax_info_sub_acct_string (const Account *account)
|
||||
{
|
||||
GList *descendant, *account_descendants;
|
||||
|
||||
if (!account)
|
||||
return NULL;
|
||||
|
||||
account_descendants = gnc_account_get_descendants (account);
|
||||
if (account_descendants)
|
||||
{
|
||||
gint sub_acct_tax_number = 0;
|
||||
for (descendant = account_descendants; descendant;
|
||||
descendant = g_list_next(descendant))
|
||||
{
|
||||
if (xaccAccountGetTaxRelated (descendant->data))
|
||||
sub_acct_tax_number++;
|
||||
}
|
||||
/* Translators: This and the following strings appear on
|
||||
* the account tab if the Tax Info column is displayed,
|
||||
* i.e. if the user wants to record the tax form number
|
||||
* and location on that tax form which corresponds to this
|
||||
* gnucash account. For the US Income Tax support in
|
||||
* gnucash, each tax code that can be assigned to an
|
||||
* account generally corresponds to a specific line number
|
||||
* on a paper form and each form has a unique
|
||||
* identification (e.g., Form 1040, Schedule A). */
|
||||
return (sub_acct_tax_number == 0) ? g_strdup ("") :
|
||||
g_strdup_printf (_("(Tax-related subaccounts: %d)"),
|
||||
sub_acct_tax_number);
|
||||
}
|
||||
else
|
||||
return g_strdup ("");
|
||||
}
|
||||
|
||||
static const char *
|
||||
string_after_colon (const char *msgstr)
|
||||
|
@ -177,6 +177,8 @@ gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
|
||||
|
||||
char *gnc_ui_account_get_tax_info_string (const Account *account);
|
||||
|
||||
char *gnc_ui_account_get_tax_info_sub_acct_string (const Account *account);
|
||||
|
||||
gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
|
||||
time_t date,
|
||||
gboolean include_children);
|
||||
|
@ -411,6 +411,7 @@ gnc_tree_model_account_get_column_type (GtkTreeModel *tree_model,
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_TOTAL_PERIOD:
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_NOTES:
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO:
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT:
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_LASTNUM:
|
||||
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_PRESENT:
|
||||
@ -801,6 +802,11 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
||||
g_value_take_string (value, gnc_ui_account_get_tax_info_string (account));
|
||||
break;
|
||||
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT:
|
||||
g_value_init (value, G_TYPE_STRING);
|
||||
g_value_take_string (value, gnc_ui_account_get_tax_info_sub_acct_string (account));
|
||||
break;
|
||||
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_LASTNUM:
|
||||
g_value_init (value, G_TYPE_STRING);
|
||||
g_value_set_string (value, xaccAccountGetLastNum (account));
|
||||
|
@ -78,6 +78,7 @@ typedef enum
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TOTAL_PERIOD,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_NOTES,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_PLACEHOLDER,
|
||||
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_LAST_VISIBLE = GNC_TREE_MODEL_ACCOUNT_COL_PLACEHOLDER,
|
||||
|
@ -71,6 +71,12 @@ static void gtva_setup_column_renderer_edited_cb(GncTreeViewAccount *account_vie
|
||||
GtkCellRenderer *renderer,
|
||||
GncTreeViewAccountColumnTextEdited col_edited_cb);
|
||||
|
||||
static void tax_info_data_func (GtkTreeViewColumn *col,
|
||||
GtkCellRenderer *renderer,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer view);
|
||||
|
||||
typedef struct GncTreeViewAccountPrivate
|
||||
{
|
||||
AccountViewInfo avi;
|
||||
@ -459,6 +465,66 @@ sort_by_total_period_value (GtkTreeModel *f_model,
|
||||
return sort_by_xxx_period_value (f_model, f_iter_a, f_iter_b, TRUE);
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* Tax_Info data function */
|
||||
/************************************************************/
|
||||
|
||||
/*
|
||||
* The tax-info column in the account tree view is based on the
|
||||
* combination of two columns in the account tree model. The data
|
||||
* function displays only the the data in the
|
||||
* GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO model column if the row is
|
||||
* expanded; otherwise it combines it with the data
|
||||
* in the GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT model column.
|
||||
*/
|
||||
static void
|
||||
tax_info_data_func (GtkTreeViewColumn *col,
|
||||
GtkCellRenderer *renderer,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer view)
|
||||
{
|
||||
const gchar *tax_info, *tax_info_sub_acct;
|
||||
GtkTreePath *path;
|
||||
|
||||
gtk_tree_model_get(model,
|
||||
iter,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO,
|
||||
&tax_info,
|
||||
-1);
|
||||
|
||||
if (tax_info == NULL)
|
||||
tax_info = "";
|
||||
path = gtk_tree_model_get_path(model, iter);
|
||||
if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path))
|
||||
g_object_set(renderer, "text", tax_info, NULL);
|
||||
else
|
||||
{
|
||||
gtk_tree_model_get(model,
|
||||
iter,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT,
|
||||
&tax_info_sub_acct,
|
||||
-1);
|
||||
if (tax_info_sub_acct == NULL)
|
||||
tax_info_sub_acct = "";
|
||||
if (safe_strcmp (tax_info_sub_acct, "") == 0)
|
||||
g_object_set(renderer, "text", tax_info, NULL);
|
||||
else
|
||||
{
|
||||
if (safe_strcmp (tax_info, "") == 0)
|
||||
g_object_set(renderer, "text", tax_info_sub_acct, NULL);
|
||||
else
|
||||
{
|
||||
const gchar *combined_tax_info;
|
||||
combined_tax_info = g_strdup_printf ("%s; %s", tax_info,
|
||||
tax_info_sub_acct);
|
||||
g_object_set(renderer, "text", combined_tax_info, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* New View Creation */
|
||||
/************************************************************/
|
||||
@ -477,6 +543,8 @@ gnc_tree_view_account_new_with_root (Account *root, gboolean show_root)
|
||||
GtkTreePath *virtual_root_path = NULL;
|
||||
const gchar *sample_type, *sample_commodity;
|
||||
GncTreeViewAccountPrivate *priv;
|
||||
GtkTreeViewColumn *tax_info_column;
|
||||
GtkCellRenderer *renderer;
|
||||
|
||||
ENTER(" ");
|
||||
/* Create our view */
|
||||
@ -644,11 +712,18 @@ gnc_tree_view_account_new_with_root (Account *root, gboolean show_root)
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_NOTES,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_text_column(view, _("Tax Info"), "tax-info", NULL,
|
||||
tax_info_column
|
||||
= gnc_tree_view_add_text_column(view, _("Tax Info"), "tax-info", NULL,
|
||||
"Sample tax info.",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO,
|
||||
GNC_TREE_VIEW_COLUMN_DATA_NONE,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
sort_by_string);
|
||||
renderer = gnc_tree_view_column_get_renderer(tax_info_column);
|
||||
gtk_tree_view_column_set_cell_data_func(tax_info_column,
|
||||
renderer,
|
||||
tax_info_data_func,
|
||||
GTK_TREE_VIEW(view),
|
||||
NULL);
|
||||
gnc_tree_view_add_toggle_column(view, _("Placeholder"),
|
||||
/* Translators: This string has a context prefix; the translation
|
||||
must only contain the part after the | character. */
|
||||
|
Loading…
Reference in New Issue
Block a user