Commit graph

459 commits

Author SHA1 Message Date
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
3aee1efdc1 data: Define __slots__ for core classes.
Because these are the classes that get instantiated many times while
iterating transactions, the performance benefit of defining __slots__
is worth the development overhead.
2020-03-31 15:00:15 -04:00
Brett Smith
fd2830f483 plugin: Load all existing hooks to registry. 2020-03-31 14:52:38 -04:00
Brett Smith
5566672cd6 plugin: Ensure run() can deal with all possible directives. 2020-03-31 14:30:49 -04:00
Brett Smith
87f35fe27f rtutil: Remove debug print. 2020-03-31 14:01:01 -04:00
Brett Smith
7a4e1c52f3 errors: InvalidMetadataError stores its key and value.
This makes it easier to introspect than trying to parse the message,
which is meant primarily for human readers.
2020-03-31 11:50:27 -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
5a5caf0ddc meta_receipt: Clean unused import. 2020-03-30 15:16:04 -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
959bda307b typing: Refine any generics when possible.
These were tightened up by running mypy with --disallow-any-generics
and cleaning up reported errors.

There are still a couple of cases I don't know how to deal with
right now that prevent me from setting that option permanently:

* plugin/__init__.py sets up a dict where the key is a Directive
  and its value is a set of hooks that correspond to that type
  of directive. The relationship between key and value is not
  expressable through the type system, and any other solution would
  make the code way more involved and less dynamic.

* The type variable used in _GenericRange still isn't quite right,
  in the sense that specifying a value for CT creates more errors
  I don't know how to deal with. Protocols seem like the right
  solution for that but they apparently didn't land for Python 3.7
  that I can see.
2020-03-29 23:28:03 -04:00
Brett Smith
22d5b7e90a setup: Disallow untyped calls. 2020-03-29 23:22:35 -04:00
Brett Smith
747ef25da6 setup: Disallow untyped defs.
Mostly this meant giving annotations to low-value functions like
the error classes and __init_subclass__, but it's worth it for
the future strictness+documentation value.
2020-03-29 23:18:40 -04:00
Brett Smith
e6894c2b46 setup: Enable stricter type checking.
This caught the "return instead of raise" bug in meta_project.
2020-03-29 19:39:09 -04:00
Brett Smith
d9dca2cd68 data: Posting.is_payment casts threshold to address typing issue. 2020-03-29 15:32:51 -04:00
Brett Smith
d8c7242208 meta_approval: Pass configured payment_threshold to is_payment. 2020-03-29 14:41:57 -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
7658aaedf8 plugin: Refactor _RequireLinksPostingMetadataHook out of MetaInvoice.
This will be a common hook type.
2020-03-28 14:48: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
a3630ab04e rtutil: Add docstring with basic rationale. 2020-03-25 10:18:01 -04:00
Brett Smith
2fb7826ab4 rtutil: Clean unused code. 2020-03-25 10:12:50 -04:00
Brett Smith
a61b74308f rtutil: Make RT.parse a classmethod.
Because it works, and I can imagine it being useful to have this
method more handy to other code.
2020-03-25 00:13:18 -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
d49173725a tests: Ignore the DeprecationWarning from the socks module.
The socks package in Debian buster does a deprecated import from
the collections module. That's not directly relevant to our own
code (Conservancy has no business requirement for SOCKS support)
so ignore it.
2020-03-24 09:16:38 -04:00