Skip to content

Commit e4a7159

Browse files
committed
Add alt_str method and enhance docstrings for properties
Introduced the `alt_str` method to provide a concise string representation of accounts. Additionally, improved and detailed the docstrings for `coa_slug` and `entity_slug` properties, ensuring clarity and consistency in code documentation.
1 parent 966361d commit e4a7159

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

django_ledger/models/accounts.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,55 @@ def __str__(self):
472472
x5=self.code
473473
)
474474

475+
def alt_str(self):
476+
"""
477+
Returns a formatted string representation of the object.
478+
479+
The formatted string includes the code, name, role, and balance type
480+
of the object. The role is converted to uppercase for consistency,
481+
and the balance type is displayed as is. This method provides a
482+
concise textual representation for quick identification or display.
483+
484+
Returns:
485+
str: A formatted string in the format 'code: name (ROLE/BALANCE_TYPE)'.
486+
"""
487+
return f'{self.code}: {self.name} ({self.role.upper()}/{self.balance_type})'
488+
475489
@property
476490
def coa_slug(self):
491+
"""
492+
Property that retrieves the `coa_slug` attribute from the object. If the attribute
493+
is not found, it fetches the `slug` attribute from the `coa_model`.
494+
495+
Attributes:
496+
_coa_slug (str): Cached value of the `coa_slug` if it exists.
497+
coa_model (Any): Object containing the `slug` attribute that serves
498+
as a fallback when `_coa_slug` is not present.
499+
500+
Returns:
501+
str: The value of `_coa_slug` if defined, or the `slug` attribute from
502+
`coa_model` if `_coa_slug` is not available.
503+
"""
477504
try:
478505
return getattr(self, '_coa_slug')
479506
except AttributeError:
480507
return self.coa_model.slug
481508

482509
@property
483510
def entity_slug(self):
511+
"""
512+
Retrieve the slug value associated with the entity.
513+
514+
This property method returns the value of the private attribute
515+
'_entity_slug' for the current instance. The purpose of the
516+
slug is typically to provide a URL-friendly string representing
517+
the entity.
518+
519+
Returns
520+
-------
521+
Any
522+
The value of the '_entity_slug' attribute.
523+
"""
484524
return getattr(self, '_entity_slug')
485525

486526
@classmethod

0 commit comments

Comments
 (0)