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

v0.5.6.3 #188

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Date/Datetime Compatibility Improvements
CFS Purchase or Sale of PPE recognizes depreciation roles.
  • Loading branch information
elarroba committed Feb 5, 2024
commit 1660e6da16f7169d144ce9fc12a5a746bdee69e3
21 changes: 13 additions & 8 deletions django_ledger/io/io_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,14 @@ def get_localdate() -> date:
return datetime.today()


def validate_io_date(
def validate_io_timestamp(
dt: Union[str, date, datetime],
no_parse_localdate: bool = True) -> Optional[Union[datetime, date]]:

if not dt:
return

if isinstance(dt, date):
return dt

elif isinstance(dt, datetime):
if isinstance(dt, datetime):
if is_naive(dt):
return make_aware(
value=dt,
Expand All @@ -178,15 +176,22 @@ def validate_io_date(
))
return datetime.combine(fdt, datetime.min.time())

elif isinstance(dt, date):
if global_settings.USE_TZ:
return make_aware(
value=datetime.combine(dt, datetime.min.time())
)
return datetime.combine(dt, datetime.min.time())

if no_parse_localdate:
return localtime()


def validate_dates(
from_date: Union[str, datetime, date] = None,
to_date: Union[str, datetime, date] = None) -> Tuple[date, date]:
from_date = validate_io_date(from_date, no_parse_localdate=False)
to_date = validate_io_date(to_date)
from_date = validate_io_timestamp(from_date, no_parse_localdate=False)
to_date = validate_io_timestamp(to_date)
return from_date, to_date


Expand Down Expand Up @@ -787,7 +792,7 @@ def commit_txs(self,

# Validates that credits/debits balance.
check_tx_balance(je_txs, perform_correction=False)
je_timestamp = validate_io_date(dt=je_timestamp)
je_timestamp = validate_io_timestamp(dt=je_timestamp)

entity_model = self.get_entity_model_from_io()

Expand Down
4 changes: 4 additions & 0 deletions django_ledger/io/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,14 @@
# Purchase of Assets....
GROUP_CFS_INV_PURCHASE_OR_SALE_OF_PPE = [
ASSET_PPE_BUILDINGS,
ASSET_PPE_BUILDINGS_ACCUM_DEPRECIATION,
ASSET_PPE_PLANT,
ASSET_PPE_PLANT_ACCUM_DEPRECIATION,
ASSET_PPE_EQUIPMENT,
ASSET_PPE_EQUIPMENT_ACCUM_DEPRECIATION,
INCOME_CAPITAL_GAIN_LOSS
]

GROUP_CFS_INV_LTD_OF_PPE = [
LIABILITY_LTL_NOTES_PAYABLE,
LIABILITY_LTL_MORTGAGE_PAYABLE,
Expand Down
9 changes: 7 additions & 2 deletions django_ledger/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,14 +2681,19 @@ def get_closing_entry_for_date(self, io_date: date, inclusive: bool = True) -> O
if ce_lookup in ce_date_list:
return ce_lookup

def get_nearest_next_closing_entry(self, io_date: date) -> Optional[date]:
def get_nearest_next_closing_entry(self, io_date: Union[date, datetime]) -> Optional[date]:
if io_date is None:
return
ce_date_list = self.fetch_closing_entry_dates_meta()
if not len(ce_date_list):
return
if io_date > ce_date_list[0]:

if not isinstance(io_date, datetime) and io_date > ce_date_list[0]:
return ce_date_list[0]

if isinstance(io_date, datetime) and io_date.date() > ce_date_list[0]:
return ce_date_list[0]

for f, p in zip_longest(ce_date_list, ce_date_list[1:]):
if p and p <= io_date < f:
return p
Expand Down
2 changes: 1 addition & 1 deletion django_ledger/models/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def can_delete(self) -> bool:
not self.is_posted(),
])

def can_edit_timestamp(self) -> bool:
def can_edit(self) -> bool:
return not self.is_locked()

def is_posted(self):
Expand Down
4 changes: 2 additions & 2 deletions django_ledger/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from django.utils.translation import gettext_lazy as _
from markdown import markdown

from django_ledger.io.io_core import validate_io_date, check_tx_balance, get_localtime, get_localdate
from django_ledger.io.io_core import validate_io_timestamp, check_tx_balance, get_localtime, get_localdate
from django_ledger.models.utils import lazy_loader

logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
Expand Down Expand Up @@ -748,7 +748,7 @@ def migrate_state(self,
unit_uuids = list(set(k[1] for k in idx_keys))

if je_timestamp:
je_timestamp = validate_io_date(dt=je_timestamp)
je_timestamp = validate_io_timestamp(dt=je_timestamp)

now_timestamp = get_localtime() if not je_timestamp else je_timestamp
je_list = {
Expand Down
6 changes: 3 additions & 3 deletions django_ledger/models/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from django.db.models import Q, QuerySet
from django.utils.translation import gettext_lazy as _

from django_ledger.io.io_core import validate_io_date
from django_ledger.io.io_core import validate_io_timestamp
from django_ledger.models.accounts import AccountModel
from django_ledger.models.bill import BillModel
from django_ledger.models.entity import EntityModel
Expand Down Expand Up @@ -156,7 +156,7 @@ def to_date(self, to_date: Union[str, date, datetime]):
"""

if isinstance(to_date, str):
to_date = validate_io_date(to_date)
to_date = validate_io_timestamp(to_date)

if isinstance(to_date, date):
return self.filter(journal_entry__timestamp__date__lte=to_date)
Expand All @@ -180,7 +180,7 @@ def from_date(self, from_date: Union[str, date, datetime]):
Returns a TransactionModelQuerySet with applied filters.
"""
if isinstance(from_date, str):
from_date = validate_io_date(from_date)
from_date = validate_io_timestamp(from_date)

if isinstance(from_date, date):
return self.filter(journal_entry__timestamp__date__gte=from_date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVESTMENT_GAINS.description }}
</td>
<td class="has-text-right">
{% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVESTMENT_GAINS.balance }}</td>
{% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVESTMENT_GAINS.balance | currency_format }}</td>
</tr>

{# Non-cash Charges to Current Accounts #}
Expand Down
2 changes: 1 addition & 1 deletion django_ledger/views/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class JournalEntryUpdateView(DjangoLedgerSecurityMixIn, JournalEntryModelModelVi

def get_form(self, form_class=None):
je_model: JournalEntryModel = self.object
if not je_model.can_edit_timestamp():
if not je_model.can_edit():
return JournalEntryModelCannotEditForm(
entity_slug=self.kwargs['entity_slug'],
ledger_model=je_model.ledger,
Expand Down