Added --lots-actual, to not print calc'd details

This commit is contained in:
John Wiegley 2009-02-27 15:45:21 -04:00
parent cbd66ba1c9
commit 38cf0e56f5
5 changed files with 57 additions and 29 deletions

View file

@ -155,6 +155,7 @@ See \fB\-\-tail\fR.
.It Fl \-lot-prices .It Fl \-lot-prices
.It Fl \-lot-tags .It Fl \-lot-tags
.It Fl \-lots .It Fl \-lots
.It Fl \-lots-actual
.It Fl \-market Pq Fl V .It Fl \-market Pq Fl V
.It Fl \-monthly Pq Fl M .It Fl \-monthly Pq Fl M
.It Fl \-only Ar EXPR .It Fl \-only Ar EXPR

View file

@ -434,9 +434,16 @@ commodity_t::exchange(const amount_t& amount,
DEBUG("commodity.prices.add", DEBUG("commodity.prices.add",
"exchange: basis-cost = " << breakdown.basis_cost); "exchange: basis-cost = " << breakdown.basis_cost);
breakdown.amount = annotation_t annotation(per_unit_cost, moment ?
amount_t(amount, annotation_t(per_unit_cost, moment ? moment->date() : optional<date_t>(), tag);
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", DEBUG("commodity.prices.add",
"exchange: amount = " << breakdown.amount); "exchange: amount = " << breakdown.amount);
@ -720,16 +727,24 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep)
commodity_t * new_comm; commodity_t * new_comm;
if (what_to_keep.keep_any(*this) && bool keep_price = (what_to_keep.keep_price &&
((what_to_keep.keep_price && details.price) || (! what_to_keep.only_actuals ||
(what_to_keep.keep_date && details.date) || ! details.has_flags(ANNOTATION_PRICE_CALCULATED)));
(what_to_keep.keep_tag && details.tag))) 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 new_comm = parent().find_or_create
(referent(), (referent(), annotation_t(keep_price ? details.price : none,
annotation_t(what_to_keep.keep_price ? details.price : none, keep_date ? details.date : none,
what_to_keep.keep_date ? details.date : none, keep_tag ? details.tag : none));
what_to_keep.keep_tag ? details.tag : none));
} else { } else {
new_comm = parent().find_or_create(base_symbol()); new_comm = parent().find_or_create(base_symbol());
} }

View file

@ -359,8 +359,13 @@ inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
* *
* Long. * 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<amount_t> price;
optional<date_t> date; optional<date_t> date;
optional<string> tag; optional<string> tag;
@ -368,14 +373,14 @@ struct annotation_t : public equality_comparable<annotation_t>
explicit annotation_t(const optional<amount_t>& _price = none, explicit annotation_t(const optional<amount_t>& _price = none,
const optional<date_t>& _date = none, const optional<date_t>& _date = none,
const optional<string>& _tag = 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"); TRACE_CTOR(annotation_t, "const optional<amount_t>& + date_t + string");
} }
annotation_t(const annotation_t& other) 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"); TRACE_CTOR(annotation_t, "copy");
} }
~annotation_t() { ~annotation_t() {
TRACE_DTOR(annotation_t); TRACE_DTOR(annotation_t);
} }
@ -405,31 +410,34 @@ struct keep_details_t
bool keep_price; bool keep_price;
bool keep_date; bool keep_date;
bool keep_tag; bool keep_tag;
bool only_actuals;
explicit keep_details_t(bool _keep_price = false, explicit keep_details_t(bool _keep_price = false,
bool _keep_date = false, bool _keep_date = false,
bool _keep_tag = false) bool _keep_tag = false,
bool _only_actuals = false)
: keep_price(_keep_price), : keep_price(_keep_price),
keep_date(_keep_date), 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_details_t(const keep_details_t& other)
: keep_price(other.keep_price), keep_date(other.keep_date), : 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"); TRACE_CTOR(keep_details_t, "copy");
} }
~keep_details_t() throw() { ~keep_details_t() throw() {
TRACE_DTOR(keep_details_t); TRACE_DTOR(keep_details_t);
} }
bool keep_all() const { 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 { 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 { 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); details.print(out);
return out; return out;
} }

View file

@ -232,7 +232,6 @@ value_t report_t::fn_justify(call_scope_t& scope)
interactive_t args(scope, "vl&lbs"); interactive_t args(scope, "vl&lbs");
std::ostringstream out; std::ostringstream out;
args.value_at(0) args.value_at(0)
.strip_annotations(what_to_keep())
.print(out, args.get<long>(1), .print(out, args.get<long>(1),
args.has(2) ? args.get<long>(2) : -1, args.has(2) ? args.get<long>(2) : -1,
args.has(3), 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_prices);
else OPT(lot_tags); else OPT(lot_tags);
else OPT(lots); else OPT(lots);
else OPT(lots_actual);
else OPT_ALT(tail_, last_); else OPT_ALT(tail_, last_);
else OPT_ALT(price_exp_, leeway_); else OPT_ALT(price_exp_, leeway_);
break; break;

View file

@ -168,9 +168,11 @@ public:
} }
keep_details_t what_to_keep() { keep_details_t what_to_keep() {
return keep_details_t(HANDLED(lots) || HANDLED(lot_prices), bool lots = HANDLED(lots) || HANDLED(lots_actual);
HANDLED(lots) || HANDLED(lot_dates), return keep_details_t(lots || HANDLED(lot_prices),
HANDLED(lots) || HANDLED(lot_tags)); lots || HANDLED(lot_dates),
lots || HANDLED(lot_tags),
HANDLED(lots_actual));
} }
bool maybe_import(const string& module); bool maybe_import(const string& module);
@ -438,6 +440,7 @@ public:
OPTION(report_t, lot_prices); OPTION(report_t, lot_prices);
OPTION(report_t, lot_tags); OPTION(report_t, lot_tags);
OPTION(report_t, lots); OPTION(report_t, lots);
OPTION(report_t, lots_actual);
OPTION_(report_t, market, DO() { // -V OPTION_(report_t, market, DO() { // -V
parent->HANDLER(revalued).on_only(); parent->HANDLER(revalued).on_only();