Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for Date Type in Metadata #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

patbakdev
Copy link

I needed to use a date type for the metadata. I tried passing in some datetime functions to the spray, but never got it to work pass the eval() function. So I just modified the code to try and convert to an ISO date and use it if successful. This probably means you can't use an ISO date as a string, but I assume that is the less common scenario. Maybe there is a better way to do this.

plugin "beancount_plugins_metadata_spray.plugins.metadata_spray" " {'sprays': [
          { 'spray_type': 'account_open',
            'replace_type': 'dont_overwrite',
            'pattern': 'Assets:.*',
            'metadata_dict': { 'cleared_before': '2019-08-07'}},
          { 'spray_type': 'account_open',
            'replace_type': 'dont_overwrite',
            'pattern': 'Liabilities:.*',
            'metadata_dict': { 'cleared_before': '2019-08-07'}},
          ]}"

@seltzered
Copy link
Owner

Very cool! Will try to review it more closely later next week.

@seltzered
Copy link
Owner

Haven't forgotten about this, honestly still wondering what's the cleanest way to handle this would be (stared at some ideas in https://stackoverflow.com/questions/4235606/python-ast-literal-eval-and-datetime).

Does beancount officially treat metadata of YYYY-MM-DD as datetime dates? Was having trouble finding where the beancount codebase parsed for this.

@patbakdev
Copy link
Author

According the the Beancount Language Syntax documentation (https://docs.google.com/document/d/1wAMVrKIA2qtRGmoVDSUBJGmYZSygUaR0uOMW1GV3YE0/edit#heading=h.dplfcfjm39a1) metadata values can be any of the following data types:

  • Strings
  • Accounts
  • Currency
  • Dates (datetime.date)
  • Tags
  • Numbers (Decimal)
  • Amount (beancount.core.amount.Amount)

I am not family with the inner workings of beancount or a python expert by any means. I was using another plugin (beancount_import I think) which required a date specific metadata. When I used a string it didn't work (probably a type mismatch error; I can't recall). So that was what drove my requirement. Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants