[assistant-stock-transaction] reorder of Pages - date before type.

Because the date may be in the past, and the stock balance at that
date will dictate the available stock txn types available for
creation.

The available stock txn types is thus dependent on the desired date,
and must only be initialized when preparing the txn_type page.
This commit is contained in:
Christopher Lam 2022-05-04 09:18:36 +08:00
parent e6eb0f328c
commit fccd07424d
2 changed files with 85 additions and 83 deletions

View File

@ -58,8 +58,8 @@ static const char* ASSISTANT_STOCK_TRANSACTION_CM_CLASS = "assistant-stock-trans
enum assistant_pages
{
PAGE_INTRO = 0,
PAGE_TRANSACTION_DETAILS,
PAGE_TRANSACTION_TYPE,
PAGE_TRANSATION_DETAILS,
PAGE_STOCK_AMOUNT,
PAGE_STOCK_VALUE,
PAGE_CASH,
@ -817,8 +817,15 @@ stock_assistant_prepare (GtkAssistant *assistant, GtkWidget *page,
switch (currentpage)
{
case PAGE_TRANSACTION_TYPE:
case PAGE_TRANSACTION_TYPE:;
// initialize transaction types.
gnc_numeric balance;
time64 date;
date = gnc_date_edit_get_date_end (GNC_DATE_EDIT (info->date_edit));
balance = xaccAccountGetBalanceAsOfDate (info->acct, date);
info->txn_types = gnc_numeric_zero_p (balance) ? &starting_types
: gnc_numeric_positive_p (balance) ? &long_types
: &short_types;
gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (info->transaction_type_combo));
for (auto& it : *(info->txn_types))
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (info->transaction_type_combo),
@ -1143,11 +1150,6 @@ stock_assistant_create (StockTransactionInfo *info)
// Set the name for this assistant so it can be easily manipulated with css
gtk_widget_set_name (GTK_WIDGET(info->window), "gnc-id-assistant-stock-transaction");
auto balance = xaccAccountGetBalance (info->acct);
info->txn_types = gnc_numeric_zero_p (balance) ? &starting_types
: gnc_numeric_positive_p (balance) ? &long_types
: &short_types;
info->currency = gnc_account_get_currency_or_parent (info->acct);
/* Transaction Page Widgets */

View File

@ -28,6 +28,82 @@
<property name="complete">True</property>
</packing>
</child>
<child>
<object class="GtkBox" id="transaction_details_page">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">12</property>
<property name="border-width">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="transaction_details_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-bottom">6</property>
<property name="label" translatable="yes">Select the date and description for your records.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid" id="transaction_details_table">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">3</property>
<property name="column-spacing">6</property>
<child>
<object class="GtkLabel" id="transaction_date_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Date</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="transaction_description_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Description</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="transaction_description_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="title" translatable="yes">Transaction Details</property>
<property name="complete">True</property>
</packing>
</child>
<child>
<object class="GtkBox" id="transaction_type_page">
<property name="visible">True</property>
@ -110,82 +186,6 @@
<property name="complete">True</property>
</packing>
</child>
<child>
<object class="GtkBox" id="transaction_details_page">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">12</property>
<property name="border-width">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="transaction_details_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-bottom">6</property>
<property name="label" translatable="yes">Select the date and description for your records.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid" id="transaction_details_table">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">3</property>
<property name="column-spacing">6</property>
<child>
<object class="GtkLabel" id="transaction_date_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Date</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="transaction_description_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Description</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="transaction_description_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="title" translatable="yes">Transaction Details</property>
<property name="complete">True</property>
</packing>
</child>
<child>
<object class="GtkBox" id="stock_amount_page">
<property name="visible">True</property>