mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Extend csv importer to be able to import voided transactions
This commit is contained in:
parent
95d7e17c7b
commit
49bbbca1d5
@ -46,11 +46,12 @@ G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_IMPORT;
|
||||
/* This map contains a set of strings representing the different column types. */
|
||||
std::map<GncTransPropType, const char*> gnc_csv_col_type_strs = {
|
||||
{ GncTransPropType::NONE, N_("None") },
|
||||
{ GncTransPropType::UNIQUE_ID, N_("Transaction ID") },
|
||||
{ GncTransPropType::DATE, N_("Date") },
|
||||
{ GncTransPropType::NUM, N_("Num") },
|
||||
{ GncTransPropType::DESCRIPTION, N_("Description") },
|
||||
{ GncTransPropType::UNIQUE_ID, N_("Transaction ID") },
|
||||
{ GncTransPropType::NOTES, N_("Notes") },
|
||||
{ GncTransPropType::VOID_REASON, N_("Void Reason") },
|
||||
{ GncTransPropType::ACTION, N_("Action") },
|
||||
{ GncTransPropType::ACCOUNT, N_("Account") },
|
||||
{ GncTransPropType::DEPOSIT, N_("Deposit") },
|
||||
@ -264,6 +265,13 @@ void GncPreTrans::set_property (GncTransPropType prop_type, const std::string& v
|
||||
m_differ = boost::none;
|
||||
break;
|
||||
|
||||
case GncTransPropType::VOID_REASON:
|
||||
if (!value.empty())
|
||||
m_void_reason = value;
|
||||
else
|
||||
m_void_reason = boost::none;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Issue a warning for all other prop_types. */
|
||||
PWARN ("%d is an invalid property for a transaction", static_cast<int>(prop_type));
|
||||
|
@ -47,12 +47,13 @@ extern "C" {
|
||||
* type. */
|
||||
enum class GncTransPropType {
|
||||
NONE,
|
||||
UNIQUE_ID,
|
||||
DATE,
|
||||
NUM,
|
||||
DESCRIPTION,
|
||||
NOTES,
|
||||
UNIQUE_ID,
|
||||
TRANS_PROPS = UNIQUE_ID,
|
||||
VOID_REASON,
|
||||
TRANS_PROPS = VOID_REASON,
|
||||
|
||||
ACTION,
|
||||
ACCOUNT,
|
||||
@ -117,14 +118,16 @@ public:
|
||||
* @returns true if this object is considered to be part of the parent, false otherwise.
|
||||
*/
|
||||
bool is_part_of (std::shared_ptr<GncPreTrans> parent);
|
||||
boost::optional<std::string> get_void_reason() { return m_void_reason; }
|
||||
|
||||
private:
|
||||
int m_date_format;
|
||||
boost::optional<std::string> m_differ;
|
||||
boost::optional<time64> m_date;
|
||||
boost::optional<std::string> m_num;
|
||||
boost::optional<std::string> m_desc;
|
||||
boost::optional<std::string> m_notes;
|
||||
boost::optional<std::string> m_differ;
|
||||
boost::optional<std::string> m_void_reason;
|
||||
bool created = false;
|
||||
};
|
||||
|
||||
|
@ -259,7 +259,21 @@ std::shared_ptr<DraftTransaction> GncTxImport::trans_properties_to_trans (std::v
|
||||
|
||||
if (trans)
|
||||
{
|
||||
/* We're about to continue with a new transaction
|
||||
* Time to do some closing actions on the previous one
|
||||
*/
|
||||
if (current_draft && current_draft->void_reason)
|
||||
{
|
||||
/* The import data specifies this transaction was voided.
|
||||
* So void the created transaction as well.
|
||||
* Attention: this assumes the imported transaction was balanced.
|
||||
* If not, this will cause an imbalance split to be added automatically!
|
||||
*/
|
||||
xaccTransCommitEdit (current_draft->trans);
|
||||
xaccTransVoid (current_draft->trans, current_draft->void_reason->c_str());
|
||||
}
|
||||
current_draft = std::make_shared<DraftTransaction>(trans);
|
||||
current_draft->void_reason = trans_props->get_void_reason();
|
||||
created_trans = true;
|
||||
}
|
||||
else if (multi_split) // in multi_split mode create_trans will return a nullptr for all but the first split
|
||||
|
@ -54,6 +54,7 @@ struct DraftTransaction
|
||||
Transaction* trans;
|
||||
gnc_numeric balance; /**< The expected balance after this transaction takes place */
|
||||
bool balance_set; /**< true if balance has been set from user data, false otherwise */
|
||||
boost::optional<std::string> void_reason;
|
||||
};
|
||||
|
||||
/* A set of currency formats that the user sees. */
|
||||
|
Loading…
Reference in New Issue
Block a user