diff options
-rw-r--r-- | doc/ledger.1 | 1 | ||||
-rw-r--r-- | src/commodity.cc | 37 | ||||
-rw-r--r-- | src/commodity.h | 37 | ||||
-rw-r--r-- | src/report.cc | 2 | ||||
-rw-r--r-- | src/report.h | 9 |
5 files changed, 57 insertions, 29 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1 index aa7ab24e..d15bf82d 100644 --- a/doc/ledger.1 +++ b/doc/ledger.1 @@ -155,6 +155,7 @@ See \fB\-\-tail\fR. .It Fl \-lot-prices .It Fl \-lot-tags .It Fl \-lots +.It Fl \-lots-actual .It Fl \-market Pq Fl V .It Fl \-monthly Pq Fl M .It Fl \-only Ar EXPR diff --git a/src/commodity.cc b/src/commodity.cc index 18bafc8e..524e333a 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -434,9 +434,16 @@ commodity_t::exchange(const amount_t& amount, DEBUG("commodity.prices.add", "exchange: basis-cost = " << breakdown.basis_cost); - breakdown.amount = - amount_t(amount, annotation_t(per_unit_cost, moment ? - moment->date() : optional<date_t>(), tag)); + annotation_t annotation(per_unit_cost, moment ? + moment->date() : optional<date_t>(), tag); + + annotation.add_flags(ANNOTATION_PRICE_CALCULATED); + if (moment) + annotation.add_flags(ANNOTATION_DATE_CALCULATED); + if (tag) + annotation.add_flags(ANNOTATION_TAG_CALCULATED); + + breakdown.amount = amount_t(amount, annotation); DEBUG("commodity.prices.add", "exchange: amount = " << breakdown.amount); @@ -720,16 +727,24 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep) commodity_t * new_comm; - if (what_to_keep.keep_any(*this) && - ((what_to_keep.keep_price && details.price) || - (what_to_keep.keep_date && details.date) || - (what_to_keep.keep_tag && details.tag))) + bool keep_price = (what_to_keep.keep_price && + (! what_to_keep.only_actuals || + ! details.has_flags(ANNOTATION_PRICE_CALCULATED))); + bool keep_date = (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))); + + if ((keep_price && details.price) || + (keep_date && details.date) || + (keep_tag && details.tag)) { new_comm = parent().find_or_create - (referent(), - annotation_t(what_to_keep.keep_price ? details.price : none, - what_to_keep.keep_date ? details.date : none, - what_to_keep.keep_tag ? details.tag : none)); + (referent(), annotation_t(keep_price ? details.price : none, + keep_date ? details.date : none, + keep_tag ? details.tag : none)); } else { new_comm = parent().find_or_create(base_symbol()); } diff --git a/src/commodity.h b/src/commodity.h index 93b5bf1d..310a0a89 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -359,8 +359,13 @@ inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) { * * Long. */ -struct annotation_t : public equality_comparable<annotation_t> +struct annotation_t : public supports_flags<>, + public equality_comparable<annotation_t> { +#define ANNOTATION_PRICE_CALCULATED 0x01 +#define ANNOTATION_DATE_CALCULATED 0x02 +#define ANNOTATION_TAG_CALCULATED 0x04 + optional<amount_t> price; optional<date_t> date; optional<string> tag; @@ -368,14 +373,14 @@ struct annotation_t : public equality_comparable<annotation_t> explicit annotation_t(const optional<amount_t>& _price = none, const optional<date_t>& _date = none, const optional<string>& _tag = none) - : price(_price), date(_date), tag(_tag) { + : supports_flags<>(), price(_price), date(_date), tag(_tag) { TRACE_CTOR(annotation_t, "const optional<amount_t>& + date_t + string"); } annotation_t(const annotation_t& other) - : price(other.price), date(other.date), tag(other.tag) { + : supports_flags<>(other.flags()), + price(other.price), date(other.date), tag(other.tag) { TRACE_CTOR(annotation_t, "copy"); } - ~annotation_t() { TRACE_DTOR(annotation_t); } @@ -405,31 +410,34 @@ struct keep_details_t bool keep_price; bool keep_date; bool keep_tag; + bool only_actuals; - explicit keep_details_t(bool _keep_price = false, - bool _keep_date = false, - bool _keep_tag = false) + explicit keep_details_t(bool _keep_price = false, + bool _keep_date = false, + bool _keep_tag = false, + bool _only_actuals = false) : keep_price(_keep_price), keep_date(_keep_date), - keep_tag(_keep_tag) + keep_tag(_keep_tag), + only_actuals(_only_actuals) { - TRACE_CTOR(keep_details_t, "bool, bool, bool"); + TRACE_CTOR(keep_details_t, "bool, bool, bool, bool"); } keep_details_t(const keep_details_t& other) : keep_price(other.keep_price), keep_date(other.keep_date), - keep_tag(other.keep_tag) { + keep_tag(other.keep_tag), only_actuals(other.only_actuals) { TRACE_CTOR(keep_details_t, "copy"); } - ~keep_details_t() throw() { TRACE_DTOR(keep_details_t); } bool keep_all() const { - return keep_price && keep_date && keep_tag; + return keep_price && keep_date && keep_tag && ! only_actuals; } bool keep_all(const commodity_t& comm) const { - return ! comm.annotated || (keep_price && keep_date && keep_tag); + return (! comm.annotated || + (keep_price && keep_date && keep_tag && ! only_actuals)); } bool keep_any() const { @@ -440,7 +448,8 @@ struct keep_details_t } }; -inline std::ostream& operator<<(std::ostream& out, const annotation_t& details) { +inline std::ostream& operator<<(std::ostream& out, + const annotation_t& details) { details.print(out); return out; } diff --git a/src/report.cc b/src/report.cc index 5e4ba48d..a79a938b 100644 --- a/src/report.cc +++ b/src/report.cc @@ -232,7 +232,6 @@ value_t report_t::fn_justify(call_scope_t& scope) interactive_t args(scope, "vl&lbs"); std::ostringstream out; args.value_at(0) - .strip_annotations(what_to_keep()) .print(out, args.get<long>(1), args.has(2) ? args.get<long>(2) : -1, args.has(3), @@ -492,6 +491,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT(lot_prices); else OPT(lot_tags); else OPT(lots); + else OPT(lots_actual); else OPT_ALT(tail_, last_); else OPT_ALT(price_exp_, leeway_); break; diff --git a/src/report.h b/src/report.h index f8563a03..11af9644 100644 --- a/src/report.h +++ b/src/report.h @@ -168,9 +168,11 @@ public: } keep_details_t what_to_keep() { - return keep_details_t(HANDLED(lots) || HANDLED(lot_prices), - HANDLED(lots) || HANDLED(lot_dates), - HANDLED(lots) || HANDLED(lot_tags)); + bool lots = HANDLED(lots) || HANDLED(lots_actual); + return keep_details_t(lots || HANDLED(lot_prices), + lots || HANDLED(lot_dates), + lots || HANDLED(lot_tags), + HANDLED(lots_actual)); } bool maybe_import(const string& module); @@ -438,6 +440,7 @@ public: OPTION(report_t, lot_prices); OPTION(report_t, lot_tags); OPTION(report_t, lots); + OPTION(report_t, lots_actual); OPTION_(report_t, market, DO() { // -V parent->HANDLER(revalued).on_only(); |