diff options
-rw-r--r-- | doc/ledger.1 | 7 | ||||
-rw-r--r-- | doc/ledger3.texi | 22 | ||||
-rw-r--r-- | src/lookup.cc | 2 | ||||
-rw-r--r-- | test/baseline/opt-auto-match.test | 47 |
4 files changed, 64 insertions, 14 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1 index 8925e6f9..b5b61b27 100644 --- a/doc/ledger.1 +++ b/doc/ledger.1 @@ -368,8 +368,9 @@ Ignore init files and environment variables for the .Nm run. .It Fl \-auto-match -Automatically match accounts from ledger journal for transactions -during csv convert. +When generating a ledger transaction from a CSV file using the +.Ic convert +command, automatically match an account from the Ledger journal. .It Fl \-aux-date Show auxiliary dates for all calculations. Alias for @@ -878,7 +879,7 @@ postings. Display the sum of the revalued postings as the running total, which serves to show unrealized capital in a gain/losses report. .It Fl \-rich-data -When generating ledger transaction from CSV file using the +When generating a ledger transaction from a CSV file using the .Ic convert command, add CSV, Imported, and UUID meta-data. .It Fl \-seed Ar INT diff --git a/doc/ledger3.texi b/doc/ledger3.texi index a2083e38..24d4cb5c 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -4637,13 +4637,16 @@ Ledger will include @samp{; transid: 767718} in the first transaction from the file above. @findex --invert +@findex --auto-match @findex --account @var{STR} @findex --rich-data -The @command{convert} command accepts three options. They are -@option{--invert} which inverts the amount field, @option{--account -@var{STR}} which you can use to specify the account to balance against, -and @option{--rich-data} which stores additional metadata as tags. +The @command{convert} command accepts four options. They are +@option{--invert} which inverts the amount field, @option{--auto-match} +which automatically matches an account from the Ledger journal for every +CSV line, @option{--account @var{STR}} which you can use to specify the +account to balance against, and @option{--rich-data} which stores +additional tag/value pairs. Using the two first lines of the above csv file, @@ -4688,6 +4691,10 @@ normal ledger file (specified via @option{--file @var{FILE} (-f)} or via the environment variable @env{LEDGER_FILE}) this entry will not be printed again. +In the output above, the account is @samp{Expenses:Unknown} for CSV +lines. You can use the @option{--auto-match} option to automatically +match an account from your Ledger journal. + You can also use @command{convert} with @code{payee} and @code{account} directives. First, you can use the @code{payee} and @code{alias} directive to rewrite the @code{payee} field based on some rules. Then @@ -6119,8 +6126,9 @@ Set the width in characters of the amount column in the Anonymize registry output, mostly for sending in bug reports. @item --auto-match -Automatically match accounts from ledger journal for transactions -during csv convert. +When generating a ledger transaction from a CSV file using the +@command{convert} command, automatically match an account from the +Ledger journal. @item --aux-date @itemx --effective @@ -6670,7 +6678,7 @@ to show unrealized capital in a gain/losses report. @item --rich-data @itemx --detail -When generating ledger transaction from CSV file using the +When generating a ledger transaction from a CSV file using the @command{convert} command, add CSV, Imported, and UUID metadata. @item --seed @var{INT} diff --git a/src/lookup.cc b/src/lookup.cc index 6dbeb502..3b6707e5 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -54,7 +54,7 @@ namespace { struct usage_sorter { bool operator()(const account_use_pair& left, const account_use_pair& right) const { - return left.second > right.second; + return left.second < right.second; } }; } diff --git a/test/baseline/opt-auto-match.test b/test/baseline/opt-auto-match.test index 7c3fb40a..54a1053b 100644 --- a/test/baseline/opt-auto-match.test +++ b/test/baseline/opt-auto-match.test @@ -14,17 +14,58 @@ Expenses:Food 20.00 EUR Liabilities:CC -20.00 EUR +test --input-date-format "%Y-%m-%d" convert test/baseline/opt-auto-match.dat +2012/03/01 * Food + Expenses:Unknown 10 + Equity:Unknown + +2012/03/02 * Phone + Expenses:Unknown 10 + Equity:Unknown + +2012/03/02 * Dining + Expenses:Unknown 10 + Equity:Unknown +end test + test --input-date-format "%Y-%m-%d" --auto-match convert test/baseline/opt-auto-match.dat 2012/03/01 * Food - Assets:Cash 10 + Expenses:Food 10 Equity:Unknown 2012/03/02 * Phone - Assets:Cash 10 + Expenses:Phone 10 Equity:Unknown 2012/03/02 * Dining - Liabilities:CC 10 + Expenses:Food 10 Equity:Unknown end test +test --input-date-format "%Y-%m-%d" --account Assets:Bank convert test/baseline/opt-auto-match.dat +2012/03/01 * Food + Expenses:Unknown 10 + Assets:Bank + +2012/03/02 * Phone + Expenses:Unknown 10 + Assets:Bank + +2012/03/02 * Dining + Expenses:Unknown 10 + Assets:Bank +end test + +test --input-date-format "%Y-%m-%d" --auto-match --account Assets:Bank convert test/baseline/opt-auto-match.dat +2012/03/01 * Food + Expenses:Food 10 + Assets:Bank + +2012/03/02 * Phone + Expenses:Phone 10 + Assets:Bank + +2012/03/02 * Dining + Expenses:Food 10 + Assets:Bank +end test |