Factory method to create an expense or income Item instance. Args: name (str): The name for the item. amount (float): The amount associated with the item. This could be +ve or -ve. description (str): Additional details about the item.
(
cls,
name: str,
amount: float,
description: str,
date_str: str,
category: Optional[Category] = None,
)
| 71 | |
| 72 | @classmethod |
| 73 | def create( |
| 74 | cls, |
| 75 | name: str, |
| 76 | amount: float, |
| 77 | description: str, |
| 78 | date_str: str, |
| 79 | category: Optional[Category] = None, |
| 80 | ): |
| 81 | """ |
| 82 | Factory method to create an expense or income Item instance. |
| 83 | |
| 84 | Args: |
| 85 | name (str): The name for the item. |
| 86 | amount (float): The amount associated with the item. This could be +ve or -ve. |
| 87 | description (str): Additional details about the item. |
| 88 | date_str (str): The date and time when the item occurred, in "YYYY-MM-DD" format. |
| 89 | category (Optional[Category]): The category of the item. Defaults to None. |
| 90 | |
| 91 | Returns: |
| 92 | Item: An instance of the Item class representing the created item. |
| 93 | """ |
| 94 | item_id = str(uuid.uuid4()) # Generate a unique ID |
| 95 | # item_id = str(name + '-' + date_str) # Generate a unique ID |
| 96 | date = datetime.strptime( |
| 97 | date_str, "%Y-%m-%d" |
| 98 | ) # Parse the date string into a datetime object |
| 99 | return cls( |
| 100 | item_id=item_id, |
| 101 | name=name, |
| 102 | amount=amount, |
| 103 | description=description, |
| 104 | date=date, |
| 105 | category=category, |
| 106 | ) |
| 107 | |
| 108 | @classmethod |
| 109 | def create_expense_item( |
no outgoing calls