Commit graph

101 commits

Author SHA1 Message Date
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