macxred / pyledger

Python package to streamline the implementation and management of accounting systems.
MIT License
0 stars 0 forks source link

Implement assets entity #46

Closed AlexTheWizardL closed 3 weeks ago

AlexTheWizardL commented 1 month ago

Complete Interfaces and Implement Accessor, Mutator, and Mirroring Methods for TextLedger and MemoryLedger

Overview:

This pull request finalizes several key interfaces and introduces robust asset management functionality for both MemoryLedger and TextLedger, focusing on accessor, mutator, and mirroring methods. It also includes updates to precision handling, asset standardization, and test coverage.

Key Changes:

  1. Completion of Interfaces:

    • Finalized the implementation of asset-related interfaces across both MemoryLedger and TextLedger.
    • Ensured consistency in schema enforcement and method signatures for handling assets in both ledger systems.
  2. Implementation of Mirroring Logic and Introduction of sanitize_assets Method:

    • Implemented the mirror_assets method to synchronize the current ledger state with a target state. The method adds missing assets, updates existing ones, and (optionally) deletes assets that are no longer present in the target.
    • Introduced a sanitize_assets method to ensure that asset data adheres to the required schema before mirroring operations. This improves data integrity and consistency across operations.
  3. Implementing Accessor and Mutator Methods for MemoryLedger:

    • Added accessor and mutator methods (add_asset, modify_asset, and delete_asset) for managing assets in MemoryLedger.
    • Each method ensures correct handling of assets uniquely identified by ticker and date, with proper error handling for duplicates or non-existent assets.
  4. Adding Base Tests for Assets:

    • Added base tests covering accessor, mutator, and mirroring methods for assets. These tests ensure that the logic is thoroughly validated and works consistently in both MemoryLedger and TextLedger.
    • Included test cases for handling precision and date-related edge cases (such as assets with None dates).
  5. Updating Usage of Precision:

    • Updated the precision method to correctly retrieve the increment value for assets based on the ticker and date.
    • Ensured that None dates are properly handled by treating them as pd.NaT, making it easier to compare and manipulate assets with or without specific dates.
  6. Implementing Accessor and Mutator Methods for TextLedger:

    • Implemented accessor and mutator methods for managing assets in TextLedger, including reading and writing assets to CSV files.
    • Methods such as add_asset, modify_asset, and delete_asset now work with TextLedger, ensuring assets are correctly read from and written to assets.csv files in a fixed-width format suitable for version control.

Review Recommendation:

It is recommended to review the changes commit by commit to understand the incremental updates and ensure proper context for each stage of implementation.

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 99.34211% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyledger/standalone_ledger.py 96.77% 1 Missing :warning:
Flag Coverage Δ
unittests 80.10% <99.34%> (+2.49%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pyledger/constants.py 100.00% <100.00%> (ø)
pyledger/ledger_engine.py 69.46% <100.00%> (+2.50%) :arrow_up:
pyledger/memory_ledger.py 94.17% <100.00%> (+1.67%) :arrow_up:
pyledger/text_ledger.py 96.09% <100.00%> (+0.88%) :arrow_up:
pyledger/standalone_ledger.py 73.17% <96.77%> (+3.12%) :arrow_up:
lasuk commented 3 weeks ago

Merged. Thanks for the good foundation for accessors and mutators of future entities ...