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

trading between commodities in automatic transaction does not balance #2268

Open
dbear496 opened this issue Jul 5, 2023 · 4 comments · May be fixed by #2272
Open

trading between commodities in automatic transaction does not balance #2268

dbear496 opened this issue Jul 5, 2023 · 4 comments · May be fixed by #2272

Comments

@dbear496
Copy link
Contributor

dbear496 commented Jul 5, 2023

When an automatic transaction deals with trading between commodities -- even with an explicit price -- the transaction will not balance. For example, the following does not balance when the automatic transaction is applied even though 100 apples at $0.20 per apple is clearly $20.

= expr 'tag("thetag") == "foo"'
  Assets:My Larder           100 apples        @ $0.200000
  Assets:Checking           $-20

2010/05/31 Farmer's Market
  Assets:My Larder           100 apples        @ $0.200000
  Assets:My Larder           100 pineapples    @ $0.33
  Assets:My Larder           100 "crab apples" @ $0.04
  Assets:Checking
    ; thetag: foo
@tdenny
Copy link

tdenny commented Jul 13, 2023

Seeing the same issue. Scares me off of using the commodities feature. I suppose I will just do the math myself and use sub accounts.

2010/05/31 Farmer's Market
    Assets:My Larder:Apples        $  20
    Assets:My Larder:Pineapples    $  33
    Assets:My Larder:Crab Apples   $   4
    Assets:Checking                $ -57

@dbear496
Copy link
Contributor Author

dbear496 commented Jul 13, 2023

@tdenny What issue are you seeing exactly? From your example, it doesn't look like you are using automated transactions.

dbear496 added a commit to dbear496/ledger-cli that referenced this issue Jul 14, 2023
dbear496 added a commit to dbear496/ledger-cli that referenced this issue Jul 14, 2023
@dbear496 dbear496 linked a pull request Jul 14, 2023 that will close this issue
@tdenny
Copy link

tdenny commented Jul 17, 2023

@tdenny What issue are you seeing exactly? From your example, it doesn't look like you are using automated transactions.

My fault. I think I misunderstood your OP.

I'm seeing the error transaction does not balance when I used commodities in an explicit transaction. I'm fairly certain my problems are a result of trying to use floating point values on my commodities. eg. 3.77 "ground beef" @ $ 3.07.

Apologies for the noise.

@dbear496
Copy link
Contributor Author

@tdenny

I'm seeing the error transaction does not balance when I used commodities in an explicit transaction. I'm fairly certain my problems are a result of trying to use floating point values on my commodities. eg. 3.77 "ground beef" @ $ 3.07.

I recommend you put this directive at the top of your journal:

commodity $
  format $0,000.00
  alias USD

If you do this, then transactions will only have to balance to the nearest cent. For example:

2023-07-18 *
  freezer       3.77 "ground beef" @ $ 3.07
  bank account  $-11.57

Ledger shouldn't complain about the unbalanced $0.0039 because the format directive specifies only two decimal places. If you still have problems where there is an unbalanced penny or two, then I would recommend any of 1) adding an adjustements posting with a blank amount to soak up the residual pennies, 2) omitting the explicit $-11.57 and let ledger calculate that automatically, or 3) omitting the explicit $3.07. If you still have issues, then it's probably from a syntax mistake like a wrong whitespace.

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 a pull request may close this issue.

2 participants