If fixated price commodities are mixed, show them
For example, if a Ledger file contains transactions with the use of both
EUR and EUR {=PRICE}, then regular reports will always show the
{=PRICE}, disabling the by-name commodity merging that takes place. In
brief, fixated and non-fixated commodities are now non-mergable.
If a file contains all of one, or all of the other, they will still be
merged, since these separate usages do not conflict the way that fixated
and non-fixated together do.
This commit is contained in:
parent
6420390d36
commit
82e43fe125
4 changed files with 95 additions and 23 deletions
|
|
@ -166,15 +166,27 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep)
|
||||||
|
|
||||||
commodity_t * new_comm;
|
commodity_t * new_comm;
|
||||||
|
|
||||||
bool keep_price = (what_to_keep.keep_price &&
|
bool keep_price =
|
||||||
(! what_to_keep.only_actuals ||
|
((what_to_keep.keep_price ||
|
||||||
! details.has_flags(ANNOTATION_PRICE_CALCULATED)));
|
(details.has_flags(ANNOTATION_PRICE_FIXATED) &&
|
||||||
bool keep_date = (what_to_keep.keep_date &&
|
has_flags(COMMODITY_SAW_ANN_PRICE_FLOAT) &&
|
||||||
(! what_to_keep.only_actuals ||
|
has_flags(COMMODITY_SAW_ANN_PRICE_FIXATED))) &&
|
||||||
! details.has_flags(ANNOTATION_DATE_CALCULATED)));
|
(! what_to_keep.only_actuals ||
|
||||||
bool keep_tag = (what_to_keep.keep_tag &&
|
! details.has_flags(ANNOTATION_PRICE_CALCULATED)));
|
||||||
(! what_to_keep.only_actuals ||
|
bool keep_date =
|
||||||
! details.has_flags(ANNOTATION_TAG_CALCULATED)));
|
(what_to_keep.keep_date &&
|
||||||
|
(! what_to_keep.only_actuals ||
|
||||||
|
! details.has_flags(ANNOTATION_DATE_CALCULATED)));
|
||||||
|
bool keep_tag =
|
||||||
|
(what_to_keep.keep_tag &&
|
||||||
|
(! what_to_keep.only_actuals ||
|
||||||
|
! details.has_flags(ANNOTATION_TAG_CALCULATED)));
|
||||||
|
|
||||||
|
DEBUG("commodity.annotated.strip",
|
||||||
|
"Reducing commodity " << *this << std::endl
|
||||||
|
<< " keep price " << keep_price << " "
|
||||||
|
<< " keep date " << keep_date << " "
|
||||||
|
<< " keep tag " << keep_tag);
|
||||||
|
|
||||||
if ((keep_price && details.price) ||
|
if ((keep_price && details.price) ||
|
||||||
(keep_date && details.date) ||
|
(keep_date && details.date) ||
|
||||||
|
|
@ -184,12 +196,24 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep)
|
||||||
(referent(), annotation_t(keep_price ? details.price : none,
|
(referent(), annotation_t(keep_price ? details.price : none,
|
||||||
keep_date ? details.date : none,
|
keep_date ? details.date : none,
|
||||||
keep_tag ? details.tag : none));
|
keep_tag ? details.tag : none));
|
||||||
} else {
|
|
||||||
new_comm = &referent();
|
// Transfer over any relevant annotation flags, as they still apply.
|
||||||
|
if (new_comm->annotated) {
|
||||||
|
annotation_t& new_details(as_annotated_commodity(*new_comm).details);
|
||||||
|
if (keep_price)
|
||||||
|
new_details.add_flags(details.flags() &
|
||||||
|
(ANNOTATION_PRICE_CALCULATED |
|
||||||
|
ANNOTATION_PRICE_FIXATED));
|
||||||
|
if (keep_date)
|
||||||
|
new_details.add_flags(details.flags() & ANNOTATION_DATE_CALCULATED);
|
||||||
|
if (keep_tag)
|
||||||
|
new_details.add_flags(details.flags() & ANNOTATION_TAG_CALCULATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *new_comm;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(new_comm);
|
return referent();
|
||||||
return *new_comm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void annotated_commodity_t::write_annotations
|
void annotated_commodity_t::write_annotations
|
||||||
|
|
|
||||||
|
|
@ -164,16 +164,19 @@ protected:
|
||||||
class base_t : public noncopyable, public supports_flags<uint_least16_t>
|
class base_t : public noncopyable, public supports_flags<uint_least16_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#define COMMODITY_STYLE_DEFAULTS 0x000
|
#define COMMODITY_STYLE_DEFAULTS 0x000
|
||||||
#define COMMODITY_STYLE_SUFFIXED 0x001
|
#define COMMODITY_STYLE_SUFFIXED 0x001
|
||||||
#define COMMODITY_STYLE_SEPARATED 0x002
|
#define COMMODITY_STYLE_SEPARATED 0x002
|
||||||
#define COMMODITY_STYLE_DECIMAL_COMMA 0x004
|
#define COMMODITY_STYLE_DECIMAL_COMMA 0x004
|
||||||
#define COMMODITY_STYLE_THOUSANDS 0x008
|
#define COMMODITY_STYLE_THOUSANDS 0x008
|
||||||
#define COMMODITY_NOMARKET 0x010
|
#define COMMODITY_NOMARKET 0x010
|
||||||
#define COMMODITY_BUILTIN 0x020
|
#define COMMODITY_BUILTIN 0x020
|
||||||
#define COMMODITY_WALKED 0x040
|
#define COMMODITY_WALKED 0x040
|
||||||
#define COMMODITY_KNOWN 0x080
|
#define COMMODITY_KNOWN 0x080
|
||||||
#define COMMODITY_PRIMARY 0x100
|
#define COMMODITY_PRIMARY 0x100
|
||||||
|
#define COMMODITY_SAW_ANNOTATED 0x200
|
||||||
|
#define COMMODITY_SAW_ANN_PRICE_FLOAT 0x400
|
||||||
|
#define COMMODITY_SAW_ANN_PRICE_FIXATED 0x800
|
||||||
|
|
||||||
string symbol;
|
string symbol;
|
||||||
amount_t::precision_t precision;
|
amount_t::precision_t precision;
|
||||||
|
|
|
||||||
12
src/pool.cc
12
src/pool.cc
|
|
@ -172,12 +172,21 @@ commodity_pool_t::create(commodity_t& comm,
|
||||||
const string& mapping_key)
|
const string& mapping_key)
|
||||||
{
|
{
|
||||||
assert(comm);
|
assert(comm);
|
||||||
|
assert(! comm.has_annotation());
|
||||||
assert(details);
|
assert(details);
|
||||||
assert(! mapping_key.empty());
|
assert(! mapping_key.empty());
|
||||||
|
|
||||||
std::auto_ptr<commodity_t> commodity
|
std::auto_ptr<commodity_t> commodity
|
||||||
(new annotated_commodity_t(&comm, details));
|
(new annotated_commodity_t(&comm, details));
|
||||||
|
|
||||||
|
comm.add_flags(COMMODITY_SAW_ANNOTATED);
|
||||||
|
if (details.price) {
|
||||||
|
if (details.has_flags(ANNOTATION_PRICE_FIXATED))
|
||||||
|
comm.add_flags(COMMODITY_SAW_ANN_PRICE_FIXATED);
|
||||||
|
else
|
||||||
|
comm.add_flags(COMMODITY_SAW_ANN_PRICE_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
commodity->qualified_symbol = comm.symbol();
|
commodity->qualified_symbol = comm.symbol();
|
||||||
assert(! commodity->qualified_symbol->empty());
|
assert(! commodity->qualified_symbol->empty());
|
||||||
|
|
||||||
|
|
@ -282,6 +291,9 @@ commodity_pool_t::exchange(const amount_t& amount,
|
||||||
moment->date() : optional<date_t>(), tag);
|
moment->date() : optional<date_t>(), tag);
|
||||||
|
|
||||||
annotation.add_flags(ANNOTATION_PRICE_CALCULATED);
|
annotation.add_flags(ANNOTATION_PRICE_CALCULATED);
|
||||||
|
if (current_annotation &&
|
||||||
|
current_annotation->has_flags(ANNOTATION_PRICE_FIXATED))
|
||||||
|
annotation.add_flags(ANNOTATION_PRICE_FIXATED);
|
||||||
if (moment)
|
if (moment)
|
||||||
annotation.add_flags(ANNOTATION_DATE_CALCULATED);
|
annotation.add_flags(ANNOTATION_DATE_CALCULATED);
|
||||||
if (tag)
|
if (tag)
|
||||||
|
|
|
||||||
33
test/regress/C0212EAC.test
Normal file
33
test/regress/C0212EAC.test
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
reg
|
||||||
|
<<<
|
||||||
|
2007-01-01 Opening balances
|
||||||
|
Assets:Cash 10.00 EUR
|
||||||
|
Equity:Opening balances
|
||||||
|
|
||||||
|
2008-01-01 Buy 5.00 GBP
|
||||||
|
Assets:Cash 5.00 GBP @ 1.4 EUR
|
||||||
|
Assets:Checking
|
||||||
|
|
||||||
|
2009-01-01 Sell 5.00 GBP for 7.50 EUR that I bought for 7.00 EUR
|
||||||
|
Assets:Cash -5.00 GBP {=1.4 EUR} @ 1.5 EUR
|
||||||
|
Assets:Checking 7.50 EUR
|
||||||
|
Income:Gain
|
||||||
|
|
||||||
|
P 2009-02-01 00:00:00 GBP 1.5 EUR
|
||||||
|
>>>
|
||||||
|
07-Jan-01 Opening balances Assets:Cash 10.00 EUR 10.00 EUR
|
||||||
|
Equit:Opening balances -10.00 EUR 0
|
||||||
|
08-Jan-01 Buy 5.00 GBP Assets:Cash 5.00 GBP 5.00 GBP
|
||||||
|
Assets:Checking -7.00 EUR -7.00 EUR
|
||||||
|
5.00 GBP
|
||||||
|
09-Jan-01 Sell 5.00 GBP for 7.. Assets:Cash -5.00 GBP {=1.40 EUR} -7.00 EUR
|
||||||
|
5.00 GBP
|
||||||
|
-5.00 GBP {=1.40 EUR}
|
||||||
|
Assets:Checking 7.50 EUR 0.50 EUR
|
||||||
|
5.00 GBP
|
||||||
|
-5.00 GBP {=1.40 EUR}
|
||||||
|
Income:Gain -0.50 EUR 5.00 GBP
|
||||||
|
-5.00 GBP {=1.40 EUR}
|
||||||
|
Equity:Capital Gains 0.50 EUR 0.50 EUR
|
||||||
|
5.00 GBP
|
||||||
|
-5.00 GBP {=1.40 EUR}
|
||||||
Loading…
Add table
Reference in a new issue