Commit graph

329 commits

Author SHA1 Message Date
Brett Smith
2b550a2037 cliutil: Start module.
We're probably going to have a small handful of reporting tools.
This module has all the stuff I end up putting in all of them.
2020-05-29 22:05:26 -04:00
Brett Smith
3a0b85c8f0 tests: Add test for trying to make outgoing report without rt-id.
Changes to other test cases are to make them *not* trip up this
error after adding it to the books.
2020-05-28 17:03:52 -04:00
Brett Smith
d3e0a38073 accrual: Introduce logging infrastructure. 2020-05-28 16:42:36 -04:00
Brett Smith
8b2683d962 accrual: Refactor reports into classes.
Preparation for introducing the aging report. This helps us
distinguish each report's setup requirements (different __init__ arguments).
2020-05-28 15:52:10 -04:00
Brett Smith
9223940213 tests: Refactor accrual tests.
Preparation for adding the aging report.
2020-05-28 15:52:09 -04:00
Brett Smith
eaae2b4a44 tests: Set locale environment variables.
To help tests get consistent formatting of currency.
2020-05-28 15:52:09 -04:00
Brett Smith
f66460f343 accrual: Outgoing report includes total at cost. 2020-05-28 09:05:18 -04:00
Brett Smith
d8df34ebaf reports: Balance.format() accepts None as a format. 2020-05-28 09:03:23 -04:00
Brett Smith
2c44cc8f50 reports: Add Balance.format() method. 2020-05-28 09:03:19 -04:00
Brett Smith
3780c31c59 reports: Add Balance.__eq__() method.
It turns out the provided implementation gets us most of the way there,
we just needed to add handling for the special case of zero balances.
Now it's confirmed with tests.
2020-05-28 09:01:00 -04:00
Brett Smith
81d216f282 reports: Add RelatedPostings.balance_at_cost() method.
This makes it easy to get results similar to `ledger -V`.
2020-05-28 09:01:00 -04:00
Brett Smith
fea306b278 books.Loader: Ensure load_all properly sorts in chronological order.
The test changes make them order-sensitive, which they should be.
It's important that our loader methods return date-sorted entries
just like Beancount itself would.
2020-05-25 11:16:17 -04:00
Brett Smith
9595d3334d books: Add Loader.load_all method. 2020-05-25 10:38:02 -04:00
Brett Smith
6801d12359 tests: Remove unused import. 2020-05-25 10:38:02 -04:00
Brett Smith
b7aae7b3c0 reports.accrual: Exclude payments from default output. RT#11294.
This makes the output more useful for broad searches like on an
entity. Invoices that cross FY boundaries will appear to be paid
without being accrued, and so would appear when we were just
filtering zeroed-out invoices.

If we integrate the aging report into this module in the future,
that'll need to follow different logic, and just filter out
zeroed-out invoices. But the basic balance report and outgoing
report are more workaday tools, where more filtering makes them
more useful.
2020-05-23 10:13:17 -04:00
Brett Smith
13df0390a1 tests: Generate configuration in accrual-report tests.
Usually reduces the amount of testing boilerplate.
2020-05-23 08:49:20 -04:00
Brett Smith
396173b55d reports.Balance: Add eq_zero, ge_zero, and le_zero methods.
Support for RT#11294.
2020-05-21 23:10:03 -04:00
Brett Smith
552ef45f47 plugin: Be more selective about when ! skips validation.
It makes sense to let the bookkeeper skip validations in situations
where the metadata requires information that might not be available
when entered. It does not make sense to skip validations that *must*
be available and affect the structure of the books, like project and
entity.

This commit ensures every plugin hook has a test for flagged
transactions, even for hooks that currently have the desired
behavior where no code changes were required for the test to
pass.
2020-05-21 21:58:48 -04:00
Brett Smith
e3e782c028 tests: Style cleanup. 2020-05-21 21:57:29 -04:00
Brett Smith
b8d76ec5a0 meta_entity: Don't validate entries out of date range. 2020-05-19 10:30:50 -04:00
Brett Smith
47235f694c accrual: Outgoing report doesn't put RT web links in < >.
The RT web interface doesn't handle angle brackets well, making the
`>` part of the link.
2020-05-18 17:05:01 -04:00
Brett Smith
f64143db44 accrual: Outgoing report handles requestors without RealName. 2020-05-18 14:44:34 -04:00
Brett Smith
18800b249d config: Let user specify books dir with ~. 2020-05-17 14:52:23 -04:00
Brett Smith
55de5627f2 reports.accrual: Outgoing report uses payment-to custom field. RT#10656. 2020-05-16 11:31:00 -04:00
Brett Smith
aa488effb0 books.Loader: New loading strategy based on load_file. RT#11034.
Building a string and loading it means Beancount can never cache any
load. It only caches top-level file loads because options in the
top-level file can change the semantics of included entries.

Instead use load_file as much as possible, and filter entries as
needed.
2020-05-16 10:29:06 -04:00
Brett Smith
1e09339b32 config: Make payment threshold configurable. 2020-05-16 09:51:02 -04:00
Brett Smith
2b7c1acff4 meta_receipt: Allow invoice as fallback documentation for checking credits.
We need this for incoming ACH where there is neither a receipt nor check.
2020-05-15 16:48:45 -04:00
Brett Smith
51db04dc20 test_meta_receipt: Prepare for multiple fallback meta keys. 2020-05-15 16:46:20 -04:00
Brett Smith
66cd27e7f0 test_rtutil: Capture debug logs for test_read_only_cache.
To help with SUSE installation, RT#10543.
2020-05-13 10:25:24 -04:00
Brett Smith
30e386f645 test_rtutil: Implement our own nullcontext.
contextlib.nullcontext does not exist in Python 3.6.
2020-05-13 10:12:08 -04:00
Brett Smith
536b50b478 plugin: Don't validate transactions flagged with !. RT#10591. 2020-05-11 09:52:05 -04:00
Brett Smith
56b644f1db meta_entity: More battle testing.
See the test cases for examples of real entities in the books
that we should accept for now.
2020-05-06 10:26:25 -04:00
Brett Smith
072937eff5 books.Loader: New loading strategy.
The old loading strategy didn't load options, which yielded some
spurious errors. It also created awkward duplication of plugin
information in the code as well as the books.

Implement a new loading strategy that works by reading one of the
"main files" under the books/ subdirectory and includes entries
for additional FYs beyond that.

This is still not ideal in a lot of ways. In particular, Beancount can't
cache any results, causing any load to be slower than it theoretically could
be. I expect more commits to follow. But some of them might require
restructuring the books, and that should happen separately.
2020-05-05 14:31:08 -04:00
Brett Smith
ca1f6d0059 tests: Add accruals.beancount required for tests in last commit. 2020-05-05 14:30:39 -04:00
Brett Smith
ad81c45f2a reports.accrual: Begin reporting.
This module basically reimplements the old payment-report+income-report,
in a single tool (after setting aside some of the checks that have moved
to the plugin). The aging report can be implemented here too when we need
that.
2020-05-04 16:36:59 -04:00
Brett Smith
e429a6c6fd meta_approval: Not required for chargebacks. RT#10978. 2020-05-01 16:24:24 -04:00
Brett Smith
23e1ed7cee Revert "meta_receipt: Don't check chargebacks. RT#10978."
This reverts commit 6aadb740e6.
This is supposed to be done in meta_approval, not meta_receipt.
2020-05-01 16:20:22 -04:00
Brett Smith
6aadb740e6 meta_receipt: Don't check chargebacks. RT#10978. 2020-05-01 16:18:46 -04:00
Brett Smith
be35f36d26 meta_tax_implication: Add Chargeback value. 2020-05-01 15:54:40 -04:00
Brett Smith
08a3151bfa meta_tax_implication: Remove unused values. 2020-05-01 15:52:27 -04:00
Brett Smith
1b81375294 reports: Add Balance.__neg__() method. 2020-04-29 14:35:20 -04:00
Brett Smith
68acb86e7e reports: Add Balance.__str__() method. 2020-04-29 11:37:38 -04:00
Brett Smith
5a1f7122bd rtutil: Add RT.iter_urls() method. 2020-04-29 11:23:48 -04:00
Brett Smith
9fef177d2d reports: Add RelatedPostings.all_meta_links() method. 2020-04-29 10:12:08 -04:00
Brett Smith
46ac91e86e test_rtutil: Simplify setup. 2020-04-28 17:20:59 -04:00
Brett Smith
999ca2c5e1 rtutil: Add RT.txn_with_urls() method. 2020-04-28 16:20:25 -04:00
Brett Smith
701ccdc192 tests: Test where Transactions are real NamedTuples.
This makes methods like _replace available in real code, and caught the
bug where we can't use @functools.lru_cache with Transaction arguments,
because they're unhashable due to their mutable members.
2020-04-28 15:33:30 -04:00
Brett Smith
d01df054ab reports: Let RelatedPostings be initialized with an Iterable[Posting]. 2020-04-27 15:51:30 -04:00
Brett Smith
bd00822b8f reports: Add RelatedPostings.group_by_meta() classmethod. 2020-04-24 13:37:35 -04:00
Brett Smith
fdd067b10e tests: Add sample configuration file.
This should've been included in 7f45788.
2020-04-23 11:41:07 -04:00
Brett Smith
d8507a1a35 rtutil: Add RTUtil.metadata_regexp() classmethod.
The accruals check script wants to be able to search RT links in
all kinds of metadata, not just rt-id as the filter currently
handles.
2020-04-23 10:27:47 -04:00
Brett Smith
d41bc5e9b6 reports: Add RelatedPostings.clear() method. 2020-04-22 12:02:06 -04:00
Brett Smith
ed4258daf7 reports: Add RelatedPostings.meta_values() method.
This corresponds to the ledtag_onevalue check in the
payment-report and income-report scripts.
2020-04-22 11:59:12 -04:00
Brett Smith
54a1bc4600 filters: Add filter_for_rt_id function. 2020-04-22 10:59:12 -04:00
Brett Smith
4420873c96 filters: Add filter_meta_match function. 2020-04-22 10:34:55 -04:00
Brett Smith
26762e11ef test_filters: Test non-string metadata values. 2020-04-22 10:31:52 -04:00
Brett Smith
cc03c4beb6 filters: Add filter_meta_equal function. 2020-04-22 10:04:24 -04:00
Brett Smith
99dbd1ac95 tests: Promote date_seq to testutil. 2020-04-22 09:17:58 -04:00
Brett Smith
8d584734ec data: Add Posting.from_entries() method. 2020-04-21 15:24:04 -04:00
Brett Smith
3000aeee09 config: Add Config.books_loader() method. 2020-04-21 13:35:56 -04:00
Brett Smith
96a363633f books: Add Loader.load_fy_range() method. 2020-04-21 11:58:28 -04:00
Brett Smith
855c1c2bf0 books: Start Loader class. 2020-04-21 10:47:13 -04:00
Brett Smith
51137815d3 config: fiscal_year_begin returns a FiscalYear. 2020-04-21 09:07:14 -04:00
Brett Smith
5c60666619 books: Start FiscalYear class. 2020-04-20 17:20:26 -04:00
Brett Smith
894f044093 config: Add Config.fiscal_year_begin() method. 2020-04-20 14:31:22 -04:00
Brett Smith
7f45788235 config: Start configuration file with books path.
Ultimately I would like to make it possible to configure the software
entirely through this file, rather than the hodgepodge system we have
now. But that can come later.
2020-04-12 22:27:52 -04:00
Brett Smith
8fa9a0ffe6 tests: Set XDG_CONFIG_HOME for safety. 2020-04-12 22:24:34 -04:00
Brett Smith
b28646aa12 core.RelatedPostings: Add iter_with_balance method.
payment-report and accrual-report query to find the last date a
series of postings had a non/zero balance. This method is a good
building block for that.
2020-04-12 15:18:19 -04:00
Brett Smith
5aa30e5456 reports.core: Start Balance class. 2020-04-12 14:56:00 -04:00
Brett Smith
219cd4bc37 reports.core: Start RelatedPostings class. 2020-04-12 09:47:41 -04:00
Brett Smith
01c3b975d8 data: Fix Amount.__new__.
See the comments for background and rationale.
2020-04-11 22:26:01 -04:00
Brett Smith
14a87e792b data: Move iter_posting into Posting class methods.
As I move into reporting code, having Posting.from_beancount() is
handy, and then from_txn() might as well come along for the ride.
2020-04-11 16:16:35 -04:00
Brett Smith
eb7f73e644 data.PostingMeta: Add date property.
This is something reporting tools will want a lot. This will make it
easier for them to look at just postings without worrying about the
parent transaction.
2020-04-11 09:20:35 -04:00
Brett Smith
a156617b4d config: Add Config.config_file_path() method. 2020-04-10 10:53:39 -04:00
Brett Smith
24813a9b81 config: Ignore non-absolute XDG_CACHE_HOME.
Per the spec.
2020-04-10 08:34:55 -04:00
Brett Smith
c7fbf5b5d5 config: s/XDG_CACHE_DIR/XDG_CACHE_HOME/g
Per the spec.
2020-04-10 08:24:34 -04:00
Brett Smith
9f0c30738d plugin: Most validations skip opening balance transactions. RT#10642. 2020-04-09 15:12:04 -04:00
Brett Smith
4eaba1ebf6 data: Add is_opening_balance_txn function. 2020-04-09 15:11:16 -04:00
Brett Smith
d66ba8773f data: Make balance_of currency-aware. 2020-04-09 14:13:07 -04:00
Brett Smith
c6dc2d83ac data.Amount: Introduce class and simplify code to use it.
See docstring for full rationale. This greatly reduces the need for other
plugin code to handle the case of `post.units.number is None`, eliminating
the need for entire methods and letting it do plain numeric comparisons.
2020-04-09 12:00:38 -04:00
Brett Smith
e00ec95d93 Account: Add is_opening_balance method. 2020-04-08 15:04:25 -04:00
Brett Smith
bb84cb5741 data.balance_of: Take account predicates, not just names.
For increased flexibility.
In particular, now you can pass in Account boolean methods to
call those directly.
2020-04-08 14:16:57 -04:00
Brett Smith
28e59e7a3b data: Add balance_of() function. 2020-04-08 11:55:00 -04:00
Brett Smith
212036b25e meta_approval: Stop checking payables.
That's handled by meta_payable_documentation now.
2020-04-07 15:45:29 -04:00
Brett Smith
ce34554bd4 meta_payable_documentation: Don't check Liabilites:Payable:Vacation. 2020-04-07 15:44:40 -04:00
Brett Smith
3dfe266945 meta_payable_documentation: Bugfix which metadata we're checking.
Checking approval/contract was in the original specification,
looking at invoice instead of approval was a pure brain fart.
2020-04-07 15:31:58 -04:00
Brett Smith
dd19e2a7a6 meta_payable_documentation: Start validation. RT#10643. 2020-04-07 15:29:15 -04:00
Brett Smith
f7bb036366 meta_receipt: Stop checking Assets:PayPal. RT#10637.
We only want to enforce paypal-id on these postings, and that's done with
the introduction of MetaPayPalID.
2020-04-07 14:47:02 -04:00
Brett Smith
21bea11beb meta_paypal_id: Start validator. RT#10260. 2020-04-07 14:41:06 -04:00
Brett Smith
0bf44ade7a plugin: Add HookRegistry.load_included_hooks() method.
This lets us import the plugin module without importing all of the included
hooks. This provides better isolation and error reporting in case there's
something like a syntax problem in one of the hooks: it doesn't cause
importing any plugin module to fail.
2020-04-07 13:31:09 -04:00
Brett Smith
fdb62dd1c6 plugin.core: _RequireLinksPostingMetadataHook can check several metadata.
Extend the base class from checking 1 metadata value to checking N.

This is preparation for RT#10643, letting payables be documented with
invoice or contract.

This does unify error reporting, because now we always report all
type/invalid value errors *plus* a missing error if appropriate.
I think this consistency and thoroughness is appropriate, although
it did require some adjustments to the tests.
2020-04-06 22:02:14 -04:00
Brett Smith
0413fed8b9 meta_entity: Use payee as entity when metadata not available. RT#10529. 2020-04-06 16:03:56 -04:00
Brett Smith
0d80c2282c test_meta_invoice: Add explicit "missing invoice" tests.
I wrote this while debugging something else, and I don't want to let
a good test go to waste.
2020-04-06 10:15:17 -04:00
Brett Smith
600c9d9d6f meta_receipt: Correctly fall back to other metadata on zero-value postings.
RT#10633.
2020-04-05 15:29:04 -04:00
Brett Smith
4437a130d6 meta_receivable_docs: Not required for paid receivables. RT#10634. 2020-04-05 15:06:10 -04:00
Brett Smith
f24f941cfb meta_approval: Not required for bank transfers. RT#10635. 2020-04-05 14:49:39 -04:00
Brett Smith
bce438167c meta_approval: Required when payables are accrued. RT#10259. 2020-04-05 14:49:16 -04:00
Brett Smith
6658696d06 meta_receipt: Use check-id as fallback metadata for outgoing checks.
When we send checks, we don't have a check document anywhere (for
security reasons), we just note the check number. Update the
validation to match. RT#10507.
2020-04-04 10:54:08 -04:00
Brett Smith
c712105bed Revise chart of accounts used throughout.
The main impetus of this change is to rename accounts that were outside
Beancount's accepted five root accounts, to move them into that
structure. This includes:

  Accrued:*Payable: → Liabilities:Payable:*
  Accrued:*Receivable: → Assets:Receivable:*
  UneanedIncome:* → Liabilities:UnearnedIncome:*

Note the last change did inspire in a change to our validation rules. We no
longer require income-type on unearned income, because it's no longer
considered income at all. Once it's earned and converted to an Income
account, that has an income-type of course.

This did inspire another rename that was not required, but
provided more consistency with the other account names above:

  Assets:Prepaid* → Assets:Prepaid:*

Where applicable, I have generally extended tests to make sure one of each
of the five account types is tested. (This mostly meant adding an Equity
account to the tests.) I also added tests for key parts of the hierarchy,
like Assets:Receivable and Liabilities:Payable, where applicable.

As part of this change, Account.is_real_asset() got renamed to
Account.is_cash_equivalent(), to better self-document its purpose.
2020-04-03 10:34:10 -04:00
Brett Smith
3e20b863e0 test_meta_entity: Test more punctuation as invalid values. 2020-04-01 14:13:36 -04:00
Brett Smith
499f18ff62 meta_entity: Adjust what entities are allowed based on today's books.
See the comments throughout for more discussion about what cases are
or aren't allowed, and why.
2020-04-01 13:38:37 -04:00
Brett Smith
90a58ef112 meta_project: Not required on Equity accounts. 2020-04-01 11:10:14 -04:00
Brett Smith
3a4c8526b2 meta_entity: Not required for Equity accounts. 2020-03-31 15:04:15 -04:00
Brett Smith
5566672cd6 plugin: Ensure run() can deal with all possible directives. 2020-03-31 14:30:49 -04:00
Brett Smith
a9eab2d4ea meta_receivable_documentation: Start hook. 2020-03-31 11:42:21 -04:00
Brett Smith
1fc9363b26 data: Add is_credit() and is_debit() methods to Posting.
The main motivation for this change is to make sure that higher-level
code deals with the fact that self.units.number can be None, and has
an easy way to do so.

I'm not sure all our code is *currently* doing the right thing for this
case, because I'm not sure it will ever actually come up. It's possible
that earlier Beancount plugins fill in decimal amounts for postings
that are originally loaded with self.units.number=None. I'll have to see
later whether this case comes up in reality, and then deal with it if so.
For now the safest strategy seems to be that most code should operate
when self.units.number is None.
2020-03-31 10:07:25 -04:00
Brett Smith
a0a3b04e50 meta_receipt: Accept paypal-id in lieu of receipt for PayPal credits. 2020-03-30 15:48:19 -04:00
Brett Smith
381160f0de meta_receipt: Accept invoice in lieu of receipt for credit card charges. 2020-03-30 15:48:19 -04:00
Brett Smith
7cac21b780 meta_receipt: Applies to both credits and debits. 2020-03-30 15:47:30 -04:00
Brett Smith
258099264e tests: Improve name spread in test_meta_receipt. 2020-03-30 15:16:37 -04:00
Brett Smith
2d49f7dfbc data: Add Account.is_checking() method. 2020-03-30 15:01:25 -04:00
Brett Smith
8a2721ec0f tests: Prepare test_meta_receipt to test more credits and fallbacks.
I'm getting to ready to extend this hook to deal with income receipts as
well as expense receipts. These changes let me write the tests in a more
declarative style, so I don't have to duplicate them all again to test
credits as well as debits.

Note that we're only testing debits right now, just like the existing tests,
because the default check_type for check() is PostType.DEBIT. Part of making
the changes will be changing that to PostType.BOTH.
2020-03-30 14:49:46 -04:00
Brett Smith
043644d194 meta_approval: Start hook. 2020-03-29 11:14:51 -04:00
Brett Smith
30d371278a plugin: Refactor hooks to use new payment-related methods. 2020-03-29 10:30:54 -04:00
Brett Smith
5f85d9c747 config: Add Config.payment_threshold() method.
This just returns a constant for now, but we know it may need to be
configurable in the future.  Other code can start using this now
to be configurable in the future.
2020-03-29 10:21:37 -04:00
Brett Smith
93feb2f4a3 data: Add Posting.is_payment() method. 2020-03-29 10:18:51 -04:00
Brett Smith
2909c405e6 meta_receipt: Start hook. 2020-03-28 22:19:49 -04:00
Brett Smith
d9420ac2b6 meta_invoice: Start hook. 2020-03-28 14:31:17 -04:00
Brett Smith
f996139070 tests: Test Metadata.get_links() with whitespace on one side. 2020-03-28 13:38:18 -04:00
Brett Smith
46cfc558ec plugin: Link checkers use Metadata class. 2020-03-28 13:36:56 -04:00
Brett Smith
9b63d898af data: Add Metadata class.
As I start writing more link-checking hooks, I want a common place to
write link-parsing code.  This new class will be that place.
2020-03-28 13:35:38 -04:00
Brett Smith
2cb131423f errors: Redo InvalidMetadataError.
This needs to be generally usable for transactions.
2020-03-28 09:47:40 -04:00
Brett Smith
33cb734b19 config: Create cache database files with 0o600 mode.
I wasn't too worried about this earlier because the cache mainly stores
a bunch of numbers, but there's a little more than that: the generated
URLs also include original attachment filenames, which might be sensitive
(referencing people's names, bank names, etc.). Tighten security
accordingly.
2020-03-27 10:55:30 -04:00
Brett Smith
a8407c7b6a rtutil: Add RTLinkCache class to cache links to disk.
This will greatly reduce RT requests across multiple runs
and speed up link checking/conversion.
2020-03-27 07:35:45 -04:00
Brett Smith
f227593655 tests: New RT client classes start with seeded ticket data.
This reduces the amount of setup many tests need to do before they modify
the ticket data.
2020-03-25 15:24:32 -04:00
Brett Smith
1155212376 config: Add Config.cache_dir_path method. 2020-03-25 15:15:38 -04:00
Brett Smith
96ef7c9cbb test_config: Make update_environ more robust against failures. 2020-03-25 14:04:47 -04:00
Brett Smith
d8b0a56fb4 tests: Set a default CONSERVANCY_REPOSITORY for testing. 2020-03-25 14:03:25 -04:00
Brett Smith
91a436abd5 testutil: Fix missing return typo. 2020-03-25 10:50:50 -04:00
Brett Smith
e8e7137216 rtutil: Fix parsing server URLs that include /REST/. 2020-03-25 10:18:09 -04:00
Brett Smith
4874a107e8 meta_rt_links: Start hook. 2020-03-25 00:12:20 -04:00
Brett Smith
c4ce59da75 config: Add Config.rt_wrapper method.
This returns a cached version of the new rtutil.RT class,
so that a single process can easily grab references to one
instance with one cache of ticket/attachment data, etc.
2020-03-24 23:30:31 -04:00
Brett Smith
9fbc658aa6 rtutil: Add RT.parse method.
This method can parse the ticket and (optional) attachment IDs
out of our short-hand link formats, both for Ledger and Beancount.
2020-03-24 18:24:31 -04:00
Brett Smith
d5a6141f6d rtutil: Start module.
For now, this is basically the Python version of
ledger-tag-convert.plx.  It knows how to create RT web links from
ticket and attachment IDs.  It confirms that those objects actually
exist too.  It may grow to encompass other functionality in the
future.
2020-03-24 17:23:54 -04:00
Brett Smith
f09f029fc4 config: Add Config.rt_client method. 2020-03-24 09:08:08 -04:00
Brett Smith
8d3816a8fd config: Add Config.rt_credentials method.
This loads settings from the same environment variables and ~/.rtrc
file as the rt CLI.

Note that it does *not* support RTCONFIG and the config file
searching, because right now that seems like more work for more
trouble to me.
2020-03-23 15:19:15 -04:00
Brett Smith
5140ca64f6 tests: Clean the environment before running tests.
As we start reading more sensitive user configuration (like RT credentials),
this fixture makes it simpler to ensure that the tests never read the user's
real configuration, which could lead to problems like passwords in tracebacks.
2020-03-23 12:01:02 -04:00
Brett Smith
ad268f049d meta_entity: Start hook. 2020-03-21 13:53:33 -04:00
Brett Smith
5c6043311b meta_repo_links: Start hook. 2020-03-20 16:47:06 -04:00
Brett Smith
1500d2d9d8 meta_project: Start hook. 2020-03-20 12:08:10 -04:00
Brett Smith
0d370c445b plugin: User configuration is passed to hooks on initialization. 2020-03-19 17:23:27 -04:00
Brett Smith
84d8adb7f6 plugin: Move hook initialization from HookRegistry to run().
Makes more sense here so run can report errors in hook configuration.
2020-03-19 16:42:13 -04:00
Brett Smith
e424173216 test_plugin: Restore negative assert to test_registry_group_by_directive. 2020-03-19 16:11:29 -04:00
Brett Smith
484c47a680 test_plugin: Parametrize HookRegistry.group_by_directive tests. 2020-03-19 16:00:22 -04:00
Brett Smith
d4d9bd6554 tests: Test HookRegistry using test instance, not real one.
This is better testing praxis and more prep for hooks-get-config.
2020-03-19 15:49:56 -04:00
Brett Smith
501bd251cb tests: Turn tested hooks into fixtures.
This is in preparation for passing configuration to hooks.
That'll be a big change already, so I wanted this to be a
boring diff first.
2020-03-19 15:04:53 -04:00
Brett Smith
71531913d5 config: Start module.
Ultimately all values that come from user configuration will be generated
here.
2020-03-19 14:31:21 -04:00
Brett Smith
7cd569be7b data.Account: Add is_income method. 2020-03-19 10:23:55 -04:00
Brett Smith
b7089f5ddf plugin: Add meta_income_type validator. 2020-03-19 09:52:43 -04:00
Brett Smith
9b8563f3f0 data.Account: is_under accepts multiple arguments. 2020-03-19 09:47:10 -04:00
Brett Smith
f1c115de49 testutil: Improve check_post_meta error reporting.
This version makes it easier to get diffs between the expected
and actual metadata.
2020-03-19 09:32:06 -04:00
Brett Smith
7bc0ded9c6 tests: Check Account.is_under works on account boundaries. 2020-03-18 16:26:56 -04:00
Brett Smith
89aaae821b data.Account: Exclude PrepaidVacation from "real" assets.
Same rationale as PrepaidExpenses.
2020-03-18 16:25:37 -04:00
Brett Smith
3f9e67de3a meta_tax_implication: Don't enforce on Assets:PrepaidExpenses. 2020-03-18 09:00:47 -04:00
Brett Smith
28238643a3 data.Account: Add is_real_asset method. 2020-03-18 08:59:03 -04:00
Brett Smith
163ecbc7d3 data: iter_postings uses Account. 2020-03-17 18:06:43 -04:00
Brett Smith
6c0f23b2fa data: Start Account class. 2020-03-17 18:05:24 -04:00
Brett Smith
8dd611c669 tests: Remove unused import. 2020-03-17 17:47:23 -04:00
Brett Smith
e9096b9500 tests: Test metadata deletion through iter_postings. 2020-03-17 17:47:00 -04:00
Brett Smith
3a73bc2239 data: Start iter_postings function. 2020-03-17 17:08:47 -04:00
Brett Smith
f4978046b8 data: Start module with PostingMeta class.
As I'm pushing to reimplement payment-report/income-report, I see query and
reporting tools will want easy access to these kinds of views, so here it
starts.
2020-03-17 17:08:05 -04:00
Brett Smith
e7720b8fb8 tests: Add check_post_meta.
This makes it simple to conveniently check all posting metadata in tests.
2020-03-16 10:15:31 -04:00
Brett Smith
3fbc14d377 Improve organization between modules.
* Rename _typing to beancount_types to better reflect what it is.
* LessComparable isn't a Beancount type, so move that to
  plugin.core with its dependent helper classes.
* Errors are a core Beancount concept, so move that module to the
  top level and have it include appropriate type definitions.
2020-03-15 16:03:57 -04:00
Brett Smith
a41feb94b3 plugin: Transform posting hooks into transaction hooks.
I feel like posting hooks a case of premature optimization in early
development. This approach reduces the number of special cases in
the code and allows us to more strongly reason about hooks in the
type system.
2020-03-15 15:50:14 -04:00
Brett Smith
c9ff4ab746 plugin: Settle on words-with-dashes metadata keys. 2020-03-15 10:36:49 -04:00
Brett Smith
547ae65780 plugin.core: _meta_set properly handles when post.meta is None.
post is a NamedTuple, so attribute assignment is not allowed.
Instead we have to construct a whole new Posting.
2020-03-08 11:32:03 -04:00
Brett Smith
d34db71542 plugin: Introduce HookRegistry.
This is the layer that keeps track of the different groups of hooks and
can filter them before runtime. The idea here is that you'll be able
to do things like skip hooks that require network access when you don't
have it, or skip CPU-intensive hooks when you don't need them, etc.
2020-03-06 09:22:55 -05:00
Brett Smith
d145e22734 test_plugin_run: Simplify testing strategy.
Avoid keeping state in the hook classes/instances.
2020-03-05 19:31:07 -05:00
Brett Smith
e9e2bb9b00 plugin: Rename the main method of hooks from check to run.
This will be more appropriate when we have hooks that do more than
check metadata.
2020-03-05 17:48:59 -05:00
Brett Smith
53329c7a23 plugin: Start entry point.
This doesn't integrate with existing hooks but at least sketches out the
main loop.
2020-03-05 17:41:58 -05:00
Brett Smith
dbe9362987 meta_tax_implication: Initial module and tests. 2020-03-05 15:48:10 -05:00
Brett Smith
16c47c64b2 expenseAllocation: Date-limit the transactions we work on.
This prevents the plugin from giving meaning to postings that
might not really be there.
2020-03-05 14:37:47 -05:00
Brett Smith
34090df23f expenseAllocation: Set default values by account. 2020-03-05 13:44:36 -05:00
Brett Smith
a1ec25a33d expenseAllocation: Test typos as invalid values. 2020-03-05 12:23:52 -05:00
Brett Smith
99f97d3f58 expenseAllocation: Accept 'admin' shorthand for 'administration'. 2020-03-05 12:23:03 -05:00
Brett Smith
2ac434b616 expenseAllocation: Test setting at transaction level. 2020-03-05 12:21:20 -05:00
Brett Smith
d436a388f7 expenseAllocation: Only check Expenses postings. 2020-03-05 12:10:05 -05:00
Brett Smith
7862919022 expenseAllocation: Start checker.
This is the simplest version of a common validation we're going to do:
make sure that a particular piece of metadata has one of a set of
values.

This checker needs some bounds checking but I wanted to err on the
side of committing this early because it introduces so much base
infrastructure.
2020-03-05 12:05:13 -05:00
Brett Smith
c5dd7984bc Initial commit: license, setup.py, gitignore, skeleton structure. 2020-03-05 09:33:23 -05:00