mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-02 05:29:20 -06:00
[assistant-stock-transaction] support additional txn_types
This commit is contained in:
parent
55046f22d2
commit
0d9dd3b789
@ -99,6 +99,7 @@ enum class FieldMask : unsigned
|
||||
ALLOW_NEGATIVE = 8,
|
||||
INPUT_NEW_BALANCE = 16, // stock_amt only: instead of amount, get new balance
|
||||
CAPITALIZE_DEFAULT = 32, // fees only: capitalize by default into stock acct
|
||||
CAPGAINS_IN_STOCK = 64, // capg only: add a balancing split in stock acct
|
||||
};
|
||||
|
||||
FieldMask operator |(FieldMask lhs, FieldMask rhs)
|
||||
@ -182,7 +183,7 @@ static const TxnTypeVec long_types
|
||||
FieldMask::ENABLED_DEBIT, // cash_amt
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::ALLOW_ZERO, // fees_amt
|
||||
FieldMask::DISABLED, // dividend_amt
|
||||
FieldMask::ENABLED_CREDIT | FieldMask::ALLOW_ZERO | FieldMask::ALLOW_NEGATIVE, // capgains_amt
|
||||
FieldMask::ENABLED_CREDIT | FieldMask::ALLOW_ZERO | FieldMask::ALLOW_NEGATIVE | FieldMask::CAPGAINS_IN_STOCK, // capgains_amt
|
||||
// Translators: this is a stock transaction describing new
|
||||
// sale of stock, and recording capital gain/loss
|
||||
N_("Sell"),
|
||||
@ -213,6 +214,18 @@ reinvested must be subsequently recorded as a regular stock purchase.")
|
||||
N_("Return of capital"),
|
||||
N_("Company returns capital, reducing the cost basis without affecting # units.")
|
||||
},
|
||||
{
|
||||
FieldMask::DISABLED, // stock_amt
|
||||
FieldMask::ENABLED_CREDIT, // stock_val
|
||||
FieldMask::DISABLED, // cash_amt
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::ALLOW_ZERO | FieldMask::CAPITALIZE_DEFAULT, // fees_amt
|
||||
FieldMask::ENABLED_DEBIT, // dividend_amt
|
||||
FieldMask::DISABLED, // capg_amt
|
||||
// Translators: this is a stock transaction describing return
|
||||
// of capital, reclassifying a dividend into return of capital
|
||||
N_("Return of capital (reclassification)"),
|
||||
N_("Company returns capital, reducing the cost basis without affecting # units. A distribution previously recorded as a dividend is reclassified to return of capital, often due to end-of-year tax information.")
|
||||
},
|
||||
{
|
||||
FieldMask::DISABLED, // stock_amt
|
||||
FieldMask::ENABLED_DEBIT, // stock_val
|
||||
@ -221,10 +234,22 @@ reinvested must be subsequently recorded as a regular stock purchase.")
|
||||
FieldMask::ENABLED_CREDIT, // dividend_amt
|
||||
FieldMask::DISABLED, // capg_amt
|
||||
// Translators: this is a stock transaction describing a
|
||||
// notional distribution
|
||||
N_("Notional distribution"),
|
||||
// notional distribution recorded as dividend
|
||||
N_("Notional distribution (dividend)"),
|
||||
N_("Company issues a notional distribution, which is recorded as dividend income and increases the cost basis without affecting # units.")
|
||||
},
|
||||
{
|
||||
FieldMask::DISABLED, // stock_amt
|
||||
FieldMask::ENABLED_DEBIT, // stock_val
|
||||
FieldMask::DISABLED, // cash_amt
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::ALLOW_ZERO, // fees_amt
|
||||
FieldMask::DISABLED, // dividend_amt
|
||||
FieldMask::ENABLED_CREDIT, // capg_amt
|
||||
// Translators: this is a stock transaction describing a
|
||||
// notional distribution recorded as capital gain
|
||||
N_("Notional distribution (capital gain)"),
|
||||
N_("Company issues a notional distribution, which is recorded as capital gain and increases the cost basis without affecting # units.")
|
||||
},
|
||||
{
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::INPUT_NEW_BALANCE, // stock_amt
|
||||
FieldMask::DISABLED, // stock_val
|
||||
@ -274,7 +299,7 @@ static const TxnTypeVec short_types
|
||||
FieldMask::ENABLED_CREDIT, // cash_amt
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::ALLOW_ZERO, // fees_amt
|
||||
FieldMask::DISABLED, // dividend_amt
|
||||
FieldMask::ENABLED_CREDIT | FieldMask::ALLOW_ZERO | FieldMask::ALLOW_NEGATIVE, // capg_amt
|
||||
FieldMask::ENABLED_CREDIT | FieldMask::ALLOW_ZERO | FieldMask::ALLOW_NEGATIVE | FieldMask::CAPGAINS_IN_STOCK, // capg_amt
|
||||
// Translators: this is a stock transaction describing cover
|
||||
// buying stock, and recording capital gain/loss
|
||||
N_("Buy to cover short"),
|
||||
@ -304,6 +329,19 @@ static const TxnTypeVec short_types
|
||||
N_("Compensatory return of capital"),
|
||||
N_("Company returns capital, and the short stock holder must make a compensatory payment for the returned capital. This reduces the cost basis (less negative, towards 0.00 value) without affecting # units.")
|
||||
},
|
||||
{
|
||||
FieldMask::DISABLED, // stock_amt
|
||||
FieldMask::ENABLED_DEBIT, // stock_val
|
||||
FieldMask::DISABLED, // cash_amt
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::ALLOW_ZERO | FieldMask::CAPITALIZE_DEFAULT, // fees_amt
|
||||
FieldMask::ENABLED_CREDIT, // dividend_amt
|
||||
FieldMask::DISABLED, // capg_amt
|
||||
// Translators: this is a stock transaction describing
|
||||
// reclassifying a compensatory dividend into compensatory
|
||||
// return of capital when shorting stock
|
||||
N_("Compensatory return of capital (reclassification)"),
|
||||
N_("Company returns capital, and the short stock holder must make a compensatory payment for the returned capital. This reduces the cost basis (less negative, towards 0.00 value) without affecting # units. A distribution previously recorded as a compensatory dividend is reclassified to compensatory return of capital, often due to end-of-year tax information.")
|
||||
},
|
||||
{
|
||||
FieldMask::DISABLED, // stock_amt
|
||||
FieldMask::ENABLED_CREDIT, // stock_val
|
||||
@ -312,10 +350,24 @@ static const TxnTypeVec short_types
|
||||
FieldMask::ENABLED_DEBIT, // dividend_amt
|
||||
FieldMask::DISABLED, // capg_amt
|
||||
// Translators: this is a stock transaction describing a
|
||||
// notional distribution when shorting stock
|
||||
N_("Compensatory notional distribution"),
|
||||
// notional distribution recorded as dividend when shorting
|
||||
// stock
|
||||
N_("Compensatory notional distribution (dividend)"),
|
||||
N_("Company issues a notional distribution, and the short stock holder must make a compensatory payment for the notional distribution. This is recorded as a loss/negative dividend income amount, and increases the cost basis (more negative, away from 0.00 value) without affecting # units.")
|
||||
},
|
||||
{
|
||||
FieldMask::DISABLED, // stock_amt
|
||||
FieldMask::ENABLED_CREDIT, // stock_val
|
||||
FieldMask::DISABLED, // cash_amt
|
||||
FieldMask::ENABLED_DEBIT | FieldMask::ALLOW_ZERO, // fees_amt
|
||||
FieldMask::DISABLED, // dividend_amt
|
||||
FieldMask::ENABLED_DEBIT, // capg_amt
|
||||
// Translators: this is a stock transaction describing a
|
||||
// notional distribution recorded as capital gain when
|
||||
// shorting stock
|
||||
N_("Compensatory notional distribution (capital gain)"),
|
||||
N_("Company issues a notional distribution, and the short stock holder must make a compensatory payment for the notional distribution. This is recorded as a capital loss amount, and increases the cost basis (more negative, away from 0.00 value) without affecting # units.")
|
||||
},
|
||||
{
|
||||
FieldMask::ENABLED_CREDIT | FieldMask::INPUT_NEW_BALANCE, // stock_amt
|
||||
FieldMask::DISABLED, // stock_val
|
||||
@ -756,20 +808,23 @@ to ensure proper recording."), new_date_str, last_split_date_str);
|
||||
// swap the debit/credit flags.
|
||||
if (this->capgains_enabled)
|
||||
{
|
||||
if (this->txn_type->capgains_value & FieldMask::CAPGAINS_IN_STOCK)
|
||||
{
|
||||
line = check_page (debit, credit, errors, this->txn_type->capgains_value ^
|
||||
(FieldMask::ENABLED_CREDIT | FieldMask::ENABLED_DEBIT),
|
||||
this->acct, this->capgains_memo, this->capgains_value,
|
||||
NC_ ("Stock Assistant: Page name", "capital gains"),
|
||||
this->curr_pinfo);
|
||||
line.units_numeric = gnc_numeric_zero();
|
||||
this->list_of_splits.push_back (std::move (line));
|
||||
}
|
||||
|
||||
line = check_page (debit, credit, errors, this->txn_type->capgains_value,
|
||||
this->capgains_account, this->capgains_memo,
|
||||
this->capgains_value,
|
||||
NC_ ("Stock Assistant: Page name", "capital gains"),
|
||||
this->curr_pinfo);
|
||||
this->list_of_splits.push_back (std::move (line));
|
||||
|
||||
line = check_page (debit, credit, errors, this->txn_type->capgains_value ^
|
||||
(FieldMask::ENABLED_CREDIT | FieldMask::ENABLED_DEBIT),
|
||||
this->acct, this->capgains_memo, this->capgains_value,
|
||||
NC_ ("Stock Assistant: Page name", "capital gains"),
|
||||
this->curr_pinfo);
|
||||
line.units_numeric = gnc_numeric_zero();
|
||||
this->list_of_splits.push_back (std::move (line));
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal (debit, credit))
|
||||
|
@ -62,7 +62,7 @@ TestCase easyTestCase = {
|
||||
{ 0, 1 , 4 , 2020, "Buy" , 250 , 4200000 , 4200995 , true , 995 , 0 , 0 , 325 },
|
||||
{ 3, 16, 4 , 2020, "ROC" , 0 , 250000 , 250000 , true , 0 , 0 , 0 , 325 },
|
||||
{ 0, 2 , 5 , 2020, "Buy" , 125 , 4750000 , 4750000 , true , 0 , 0 , 0 , 450 },
|
||||
{ 5, 11, 5 , 2020, "Split 2:1" , 900 , 0 , 0 , true , 0 , 0 , 0 , 900 },
|
||||
{ 7, 11, 5 , 2020, "Split 2:1" , 900 , 0 , 0 , true , 0 , 0 , 0 , 900 },
|
||||
{ 1, 21, 5 , 2020, "Sell" , 135 , 2150000 , 2149005 , false , 995 , 0 , 574702, 765 },
|
||||
{ 0, 3 , 6 , 2020, "Buy" , 150 , 2100000 , 2100000 , true , 0 , 0 , 0 , 915 },
|
||||
{ 1, 10, 6 , 2020, "Sell" , 915 , 12810000, 12809005, false , 995 , 0 , 1783309, 0 },
|
||||
@ -73,11 +73,11 @@ TestCase easyTestCase = {
|
||||
// bal<0. next lines are short_types
|
||||
{ 0, 15, 6 , 2020, "Short Sell" , 65 , 1105000 , 1104005 , true , 995 , 0 , 0 , -150 },
|
||||
{ 1, 16, 6 , 2020, "Cover Buy" , 50 , 500000 , 500995 , false , 995 , 0 ,-264337, -100 },
|
||||
{ 5, 17, 6 , 2020, "Split 2:1" , -200 , 0 , 0 , false , 0 , 0 , 0 , -200 },
|
||||
{ 6, 18, 6 , 2020, "Reverse Split" , -100 , 0 , 0 , false , 0 , 0 , 0 , -100 },
|
||||
{ 7, 17, 6 , 2020, "Split 2:1" , -200 , 0 , 0 , false , 0 , 0 , 0 , -200 },
|
||||
{ 8, 18, 6 , 2020, "Reverse Split" , -100 , 0 , 0 , false , 0 , 0 , 0 , -100 },
|
||||
{ 2, 19, 6 , 2020, "Comp Dividend" , 0 , 0 , 50000 , false , 0 , 50000, 0 , -100 },
|
||||
{ 3, 19, 6 , 2020, "Comp ROC" , 0 , 250000 , 250000 , false , 0 , 0 , 0 , -100 },
|
||||
{ 4, 19, 6 , 2020, "Comp ND" , 0 , 20000 , 0 , false , 0 , 20000, 0 , -100 },
|
||||
{ 5, 19, 6 , 2020, "Comp ND" , 0 , 20000 , 0 , false , 0 , 20000, 0 , -100 },
|
||||
{ 1, 20, 6 , 2020, "Cover Buy" , 100 , 800000 , 800498 , false , 498 , 0 ,-498673, 0 },
|
||||
|
||||
// bal=0. next line is "open long".
|
||||
@ -88,8 +88,8 @@ TestCase easyTestCase = {
|
||||
{ 2, 25, 6 , 2020, "Dividend" , 0 , 0 , 11000 , false , 0 , 11000, 0 , 100 },
|
||||
{ 0, 25, 6 , 2020, "+ Reinv" , 1 , 10000 , 10000 , false , 0 , 0 , 0 , 101 },
|
||||
{ 1, 26, 6 , 2020, "Sell remainder" , 1 , 10000 , 10000 , false , 0 , 0 , 1975 , 100 },
|
||||
{ 6, 26, 6 , 2020, "Reverse Split 1:2", 50 , 0 , 0 , false , 0 , 0 , 0 , 50 },
|
||||
{ 4, 27, 6 , 2020, "ND" , 0 , 10000 , 0 , false , 0 , 10000, 0 , 50 }
|
||||
{ 8, 26, 6 , 2020, "Reverse Split 1:2", 50 , 0 , 0 , false , 0 , 0 , 0 , 50 },
|
||||
{ 5, 27, 6 , 2020, "ND" , 0 , 10000 , 0 , false , 0 , 10000, 0 , 50 }
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user