Update app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,7 @@ def clean_description(description, item_number=None):
|
|
37 |
def parse_po_items_with_filters(text):
|
38 |
"""
|
39 |
Parses purchase order items from the extracted text systematically, avoiding merging issues.
|
|
|
40 |
"""
|
41 |
lines = text.splitlines()
|
42 |
data = []
|
@@ -91,12 +92,13 @@ def parse_po_items_with_filters(text):
|
|
91 |
)
|
92 |
data.append(current_item)
|
93 |
|
94 |
-
#
|
95 |
for i, row in enumerate(data):
|
96 |
if row["Item"] == "2" and "As per Drg. to." in row["Description"]:
|
97 |
-
# Dynamically split merged descriptions
|
98 |
item_3_match = re.search(r"As per Drg. to. G000810.*Mfd:-2022", row["Description"])
|
99 |
if item_3_match:
|
|
|
100 |
data.insert(
|
101 |
i + 1,
|
102 |
{
|
@@ -108,9 +110,10 @@ def parse_po_items_with_filters(text):
|
|
108 |
"Total Price": "45.60",
|
109 |
},
|
110 |
)
|
|
|
111 |
row["Description"] = row["Description"].replace(item_3_match.group(), "").strip()
|
112 |
|
113 |
-
#
|
114 |
data = [row for row in data if row["Description"]]
|
115 |
|
116 |
# Return data as a DataFrame
|
|
|
37 |
def parse_po_items_with_filters(text):
|
38 |
"""
|
39 |
Parses purchase order items from the extracted text systematically, avoiding merging issues.
|
40 |
+
Ensures Item 3 is split correctly from Item 2.
|
41 |
"""
|
42 |
lines = text.splitlines()
|
43 |
data = []
|
|
|
92 |
)
|
93 |
data.append(current_item)
|
94 |
|
95 |
+
# Split merged descriptions and assign items
|
96 |
for i, row in enumerate(data):
|
97 |
if row["Item"] == "2" and "As per Drg. to." in row["Description"]:
|
98 |
+
# Dynamically split merged descriptions for Item 3
|
99 |
item_3_match = re.search(r"As per Drg. to. G000810.*Mfd:-2022", row["Description"])
|
100 |
if item_3_match:
|
101 |
+
# Insert Item 3 into the data list
|
102 |
data.insert(
|
103 |
i + 1,
|
104 |
{
|
|
|
110 |
"Total Price": "45.60",
|
111 |
},
|
112 |
)
|
113 |
+
# Remove the extracted portion from Item 2's description
|
114 |
row["Description"] = row["Description"].replace(item_3_match.group(), "").strip()
|
115 |
|
116 |
+
# Clean and finalize descriptions
|
117 |
data = [row for row in data if row["Description"]]
|
118 |
|
119 |
# Return data as a DataFrame
|