Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions gnucash/import-export/csv-exp/assistant-csv-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ csv_export_simple_cb (GtkToggleButton *button, gpointer user_data)
gtk_label_set_text (GTK_LABEL(info->start_label), msg);
g_free (msg);

gtk_widget_set_sensitive(info->gdpdu_layout_check, !info->gdpdu_layout);
gtk_widget_set_sensitive(info->comma_radio, !info->gdpdu_layout);
gtk_widget_set_sensitive(info->colon_radio, !info->gdpdu_layout);
gtk_widget_set_sensitive(info->semicolon_radio, !info->gdpdu_layout);
Expand All @@ -296,7 +295,6 @@ csv_export_gdpdu_cb (GtkToggleButton *button, gpointer user_data)

gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(info->semicolon_radio), info->gdpdu_layout);

gtk_widget_set_sensitive(info->simple_layout_check, !info->simple_layout);
gtk_widget_set_sensitive(info->comma_radio, !info->gdpdu_layout);
gtk_widget_set_sensitive(info->colon_radio, !info->gdpdu_layout);
gtk_widget_set_sensitive(info->semicolon_radio, !info->gdpdu_layout);
Expand Down
52 changes: 41 additions & 11 deletions gnucash/import-export/csv-exp/csv-transaction-export-line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CsvTransactionExportLine::CsvTransactionExportLine(Split *split,
m_transaction(transaction),
m_separator(separator),
m_use_quotes(use_quotes),
m_simple(simple),
m_simple(simple && !gdpdu),
m_gdpdu(gdpdu),
m_is_trading_acc(is_trading_acc),
m_ss(ss),
Expand Down Expand Up @@ -249,9 +249,11 @@ CsvTransactionExportLine::get_commodity(Transaction *trans)

// Amount with Symbol or not
std::string
CsvTransactionExportLine::get_amount(Split *split, bool t_void, bool symbol)
CsvTransactionExportLine::get_amount(Split *split, bool t_void, bool symbol, bool positive)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple boolean function args is poor design, it's too easy to screw up the order.

{
auto amt_num{t_void ? xaccSplitVoidFormerAmount(split) : xaccSplitGetAmount(split)};
if (positive)
amt_num = gnc_numeric_abs(amt_num);
auto pinfo{gnc_split_amount_print_info(split, symbol)};
if (!symbol)
pinfo.use_separators = 0;
Expand Down Expand Up @@ -300,6 +302,11 @@ bool CsvTransactionExportLine::print_csv()

if (m_simple || (!is_split_transaction() && m_gdpdu))
{
auto amount = xaccSplitGetAmount(m_split);
/* Ignore bookings with zero value in gdpdu export*/
if (gnc_numeric_zero_p(amount) && m_gdpdu)
return true;

auto line = m_gdpdu ? make_gdpdu_trans_line(m_split) : make_simple_trans_line(m_split);
return gnc_csv_add_line(m_ss, line, m_use_quotes,
m_separator);
Expand All @@ -312,6 +319,11 @@ bool CsvTransactionExportLine::print_csv()
{
Split *s = static_cast<Split *>(split->data);

auto amount = xaccSplitGetAmount(s);
/* Ignore bookings with zero value in gdpdu export*/
if (gnc_numeric_zero_p(amount))
continue;

auto split_account = xaccSplitGetAccount(s);
if (!split_account)
{
Expand All @@ -321,7 +333,7 @@ bool CsvTransactionExportLine::print_csv()
if (xaccAccountEqual(split_account, m_base_split_account, true))
continue;

auto line = make_gdpdu_trans_split_line(m_split);
auto line = make_gdpdu_trans_split_line(s);
ok = gnc_csv_add_line(m_ss, line, m_use_quotes,
m_separator);
if (!ok)
Expand Down Expand Up @@ -360,28 +372,46 @@ StringVec
CsvTransactionExportLine::make_gdpdu_trans_split_line(Split *split)
{
auto t_void{xaccTransGetVoidStatus(m_transaction)};
gnc_numeric amount = xaccSplitGetAmount(split);
bool pos = gnc_numeric_positive_p(amount);

auto base_acc_code = xaccAccountGetCode(m_base_split_account);
if (!base_acc_code)
base_acc_code = _("Unknown");

return {
get_date(m_transaction),
get_number(m_transaction),
pos ? get_account_number(m_base_split) : get_account_number(split),
pos ? get_account_number(split) : get_account_number(m_base_split),
m_is_credit_split ? base_acc_code : get_account_number(split),
m_is_credit_split ? get_account_number(split) : base_acc_code,
get_description(m_transaction),
get_amount(split, t_void, false)};
get_amount(split, t_void, false, true)};
}

StringVec
CsvTransactionExportLine::make_gdpdu_trans_line(Split *split)
{
auto t_void{xaccTransGetVoidStatus(m_transaction)};
auto amount = xaccSplitGetAmount(split);
auto account = xaccSplitGetAccount(split);
auto type = xaccAccountGetType(account);
bool pos = gnc_numeric_positive_p(amount);

/* It is possible that other types of accounts need to be taken into account here */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a FIXME: GnuCash's account types aren't tested hierarchically so even though ACCT_TYPE_INCOME and ACCT_TYPE_EXPENSE are Equity they won't set exchange true.

A comment explaining why the presence of an Equity account justifies switching the order of the account numbers in a single transaction would be useful.

bool exchange = false;
switch (type) {
case ACCT_TYPE_EQUITY:
exchange = true;
break;
default:
break;
}

return {
get_date(m_transaction),
get_number(m_transaction),
get_account_number(split),
get_other_account_number(split),
pos || exchange ? get_other_account_number(split) : get_account_number(split),
pos || exchange ? get_account_number(split) : get_other_account_number(split),
get_description(m_transaction),
get_amount(split, t_void, false)};
get_amount(split, t_void, false, true)};
}

StringVec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CsvTransactionExportLine
std::string get_action(Split *split);
std::string get_reconcile(Split *split);
std::string get_commodity(Transaction *trans);
std::string get_amount(Split *split, bool t_void, bool symbol);
std::string get_amount(Split *split, bool t_void, bool symbol, bool positive = false);
std::string get_value(Split *split, bool t_void, bool symbol);
std::string get_rate(Split *split, bool t_void);
std::string get_price(Split *split, bool t_void);
Expand Down