Add name_of_asset field to receipt processing and update related logic in DocumentProcessor

This commit is contained in:
bolade
2025-10-07 20:35:43 +01:00
parent 5116fb5efb
commit f582110674
4 changed files with 23 additions and 6 deletions
+15 -2
View File
@@ -77,6 +77,7 @@ class DocumentProcessor:
"location": "Province/State, Country",
"calculated_tax": 0.00,
"is_depreciable": false,
"name_of_asset": null,
"cca_rate": null,
"useful_life": null,
"residual_value": null
@@ -117,6 +118,7 @@ class DocumentProcessor:
- Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings)
- Set is_depreciable to true only for capital assets, false for consumables/services
- If is_depreciable is true, provide:
* name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk")
* cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%)
- Class 10 (Vehicles): 30%
- Class 8 (Furniture, equipment): 20%
@@ -125,7 +127,7 @@ class DocumentProcessor:
- Class 10.1 (Passenger vehicles >$30k): 30%
* useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture)
* residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles)
- If is_depreciable is false, set cca_rate, useful_life, and residual_value to null
- If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null
Return only valid JSON.
"""
@@ -233,6 +235,7 @@ class DocumentProcessor:
"location": "Province/State, Country",
"calculated_tax": 0.00,
"is_depreciable": false,
"name_of_asset": null,
"cca_rate": null,
"useful_life": null,
"residual_value": null
@@ -273,6 +276,7 @@ class DocumentProcessor:
- Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings)
- Set is_depreciable to true only for capital assets, false for consumables/services
- If is_depreciable is true, provide:
* name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk")
* cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%)
- Class 10 (Vehicles): 30%
- Class 8 (Furniture, equipment): 20%
@@ -281,7 +285,7 @@ class DocumentProcessor:
- Class 10.1 (Passenger vehicles >$30k): 30%
* useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture)
* residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles)
- If is_depreciable is false, set cca_rate, useful_life, and residual_value to null
- If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null
Return only valid JSON.
"""
@@ -349,6 +353,9 @@ class DocumentProcessor:
is_depreciable_match = re.search(
r'"is_depreciable"\s*:\s*(true|false)', json_str
)
name_of_asset_match = re.search(
r'"name_of_asset"\s*:\s*"([^"]*)"', json_str
)
cca_rate_match = re.search(
r'"cca_rate"\s*:\s*([0-9.]+|null)', json_str
)
@@ -388,6 +395,9 @@ class DocumentProcessor:
"is_depreciable": is_depreciable_match.group(1) == "true"
if is_depreciable_match
else None,
"name_of_asset": name_of_asset_match.group(1)
if name_of_asset_match
else None,
"cca_rate": float(cca_rate_match.group(1))
if cca_rate_match and cca_rate_match.group(1) != "null"
else None,
@@ -414,6 +424,7 @@ class DocumentProcessor:
"location": data.get("location"),
"calculated_tax": data.get("calculated_tax"),
"is_depreciable": data.get("is_depreciable"),
"name_of_asset": data.get("name_of_asset"),
"cca_rate": data.get("cca_rate"),
"useful_life": data.get("useful_life"),
"residual_value": data.get("residual_value"),
@@ -489,6 +500,7 @@ class DocumentProcessor:
"location": None,
"calculated_tax": None,
"is_depreciable": None,
"name_of_asset": None,
"cca_rate": None,
"useful_life": None,
"residual_value": None,
@@ -508,6 +520,7 @@ class DocumentProcessor:
"location": None,
"calculated_tax": None,
"is_depreciable": None,
"name_of_asset": None,
"cca_rate": None,
"useful_life": None,
"residual_value": None,