Skip to content

Commit

Permalink
Bug 554391 - Select account if Tax Options dialog opened from CoA
Browse files Browse the repository at this point in the history
If the Tax options dialog is opened from the Chart of Accounts and an
account is selected then the tax dialog will preselect that account.
  • Loading branch information
Bob-IT committed Sep 24, 2020
1 parent 227bbda commit 7f7ae2e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-ui.h
Expand Up @@ -111,7 +111,7 @@ int gnc_choose_radio_option_dialog (GtkWidget *parent,
int default_value,
GList *radio_list);

void gnc_tax_info_dialog (GtkWidget *parent);
void gnc_tax_info_dialog (GtkWidget *parent, Account *account);
void gnc_stock_split_dialog (GtkWidget *parent, Account * initial);

typedef enum
Expand Down
40 changes: 39 additions & 1 deletion gnucash/gnome/dialog-tax-info.c
Expand Up @@ -103,6 +103,7 @@ typedef struct
GtkWidget * tax_identity_edit_button;

GtkWidget * acct_info;
GtkWidget * income_radio;
GtkWidget * expense_radio;
GtkWidget * asset_radio;
GtkWidget * liab_eq_radio;
Expand Down Expand Up @@ -883,6 +884,39 @@ gnc_tax_info_update_accounts (TaxInfoDialog *ti_dialog)
return num_accounts;
}

static void
gnc_tax_info_set_acct (TaxInfoDialog *ti_dialog, Account *account)
{
if (account == NULL)
return;

ti_dialog->account_type = xaccAccountGetType (account);

This comment has been minimized.

Copy link
@christopherlam

christopherlam Sep 24, 2020

Contributor

There are more (unused) types. Wouldn't the xaccAccountTypeGetFundamental be useful here? Also the ti_dialog->account_type is tested against ACCT_TYPE_EQUITY twice.

xaccAccountTypeGetFundamental (GNCAccountType t)

This comment has been minimized.

Copy link
@Bob-IT

Bob-IT Sep 24, 2020

Author Contributor

@christopherlam Interesting, I did not see that will change it, thank you.


if (ti_dialog->account_type == ACCT_TYPE_INCOME)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->income_radio), TRUE);
else if (ti_dialog->account_type == ACCT_TYPE_EXPENSE)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->expense_radio), TRUE);
else if ((ti_dialog->account_type == ACCT_TYPE_ASSET) ||
(ti_dialog->account_type == ACCT_TYPE_BANK) ||
(ti_dialog->account_type == ACCT_TYPE_CASH) ||
(ti_dialog->account_type == ACCT_TYPE_STOCK) ||
(ti_dialog->account_type == ACCT_TYPE_MUTUAL) ||
(ti_dialog->account_type == ACCT_TYPE_RECEIVABLE))
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->asset_radio), TRUE);
else if ((ti_dialog->account_type == ACCT_TYPE_LIABILITY) ||
(ti_dialog->account_type == ACCT_TYPE_EQUITY) ||
(ti_dialog->account_type == ACCT_TYPE_CREDIT) ||
(ti_dialog->account_type == ACCT_TYPE_PAYABLE))
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->liab_eq_radio), TRUE);
else if (ti_dialog->account_type == ACCT_TYPE_EQUITY)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ti_dialog->liab_eq_radio), TRUE);
else
return;

gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview),
account);
}

static void
gnc_tax_info_acct_type_cb (GtkWidget *w, gpointer data)
{
Expand Down Expand Up @@ -1440,6 +1474,7 @@ gnc_tax_info_dialog_create (GtkWidget * parent, TaxInfoDialog *ti_dialog)
gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));

income_radio = GTK_WIDGET(gtk_builder_get_object (builder, "income_radio"));
ti_dialog->income_radio = income_radio;
expense_radio = GTK_WIDGET(gtk_builder_get_object (builder, "expense_radio"));
ti_dialog->expense_radio = expense_radio;
asset_radio = GTK_WIDGET(gtk_builder_get_object (builder, "asset_radio"));
Expand Down Expand Up @@ -1520,7 +1555,7 @@ refresh_handler (GHashTable *changes, gpointer user_data)
* Return: nothing *
\********************************************************************/
void
gnc_tax_info_dialog (GtkWidget * parent)
gnc_tax_info_dialog (GtkWidget * parent, Account * account)
{
TaxInfoDialog *ti_dialog;
gint component_id;
Expand All @@ -1529,6 +1564,9 @@ gnc_tax_info_dialog (GtkWidget * parent)

gnc_tax_info_dialog_create (parent, ti_dialog);

if (account)
gnc_tax_info_set_acct (ti_dialog, account);

component_id = gnc_register_gui_component (DIALOG_TAX_INFO_CM_CLASS,
refresh_handler, close_handler,
ti_dialog);
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome/gnc-plugin-basic-commands.c
Expand Up @@ -524,7 +524,7 @@ gnc_main_window_cmd_edit_tax_options (GtkAction *action, GncMainWindowActionData
{
g_return_if_fail (data != NULL);

gnc_tax_info_dialog (GTK_WIDGET (data->window));
gnc_tax_info_dialog (GTK_WIDGET (data->window), NULL);
}

static void
Expand Down
26 changes: 25 additions & 1 deletion gnucash/gnome/gnc-plugin-page-account-tree.c
Expand Up @@ -165,6 +165,7 @@ static void gnc_plugin_page_account_tree_cmd_refresh (GtkAction *action, GncPlug
static void gnc_plugin_page_account_tree_cmd_autoclear (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_transfer (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_stock_split (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_edit_tax_options (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_lots (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_scrub (GtkAction *action, GncPluginPageAccountTree *page);
static void gnc_plugin_page_account_tree_cmd_scrub_sub (GtkAction *action, GncPluginPageAccountTree *page);
Expand Down Expand Up @@ -272,7 +273,18 @@ static GtkActionEntry gnc_plugin_page_account_tree_actions [] =
N_("Renumber the children of the selected account"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_renumber_accounts)
},

{
"EditTaxOptionsAction", NULL,
/* Translators: remember to reuse this *
* translation in dialog-account.glade */
N_("Ta_x Report Options"), NULL,
/* Translators: currently implemented are *
* US: income tax and *
* DE: VAT *
* So adjust this string */
N_("Setup relevant accounts for tax reports, e.g. US income tax"),
G_CALLBACK (gnc_plugin_page_account_tree_cmd_edit_tax_options)
},
/* View menu */
{
"ViewFilterByAction", NULL, N_("_Filter By..."), NULL, NULL,
Expand Down Expand Up @@ -1922,6 +1934,18 @@ gnc_plugin_page_account_tree_cmd_stock_split (GtkAction *action,
gnc_stock_split_dialog (window, account);
}

static void
gnc_plugin_page_account_tree_cmd_edit_tax_options (GtkAction *action,
GncPluginPageAccountTree *page)
{
GtkWidget *window;
Account *account;

account = gnc_plugin_page_account_tree_get_current_account (page);
window = GNC_PLUGIN_PAGE (page)->window;
gnc_tax_info_dialog (window, account);
}

static void
gnc_plugin_page_account_tree_cmd_lots (GtkAction *action,
GncPluginPageAccountTree *page)
Expand Down
1 change: 1 addition & 0 deletions gnucash/ui/gnc-plugin-page-account-tree-ui.xml
Expand Up @@ -10,6 +10,7 @@
<separator name="EditSep2"/>
<menuitem name="FileOpenAccount" action="FileOpenAccountAction"/>
<menuitem name="FileOpenSubaccounts" action="FileOpenSubaccountsAction"/>
<menuitem name="EditTaxOptions" action="EditTaxOptionsAction"/>
</placeholder>
</menu>
<menu name="Actions" action="ActionsAction">
Expand Down

0 comments on commit 7f7ae2e

Please sign in to comment.