flash-oss / medici

Double-entry accounting system for nodejs + mongoose
MIT License
309 stars 85 forks source link

Invalid entry gets accepted #8

Closed muenzel closed 6 years ago

muenzel commented 6 years ago

I have the following code

  const myBook = new book("test");

  let entry = myBook.entry("This is a test entry");

  entry.debit("Assets:Cash", 99.9, {});
  entry.credit("Income", 99.8, {});

  entry.commit().then(journal => console.log(journal));

which leads to a valid journal entry instead of raising an INVALID JOURNAL exception, as expected.


{ __v: 0,
  book: 'test',
  datetime: 2018-03-02T10:36:24.244Z,
  _id: 5a992928b7323207c3713991,
  approved: true,
  voided: false,
  _transactions: [ 5a992928b7323207c3713992, 5a992928b7323207c3713993 ],
  memo: 'This is a test entry' }
muenzel commented 6 years ago

If I am doing this the other way around (debit 99.8 and credit 99.9), I get the error:

Journal is invalid. Total is: 0.10000000000000853 (node:2018) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: INVALID_JOURNAL

Maybe a missing abs() in the boundary check function?

koresar commented 6 years ago

Don't have any time today. Would attempt to fix on Monday.

koresar commented 6 years ago

Fixed and published as v1.0.3

Thanks again!