Update app.py
Browse files
app.py
CHANGED
|
@@ -80,12 +80,25 @@ def parse_po_items_with_filters(text):
|
|
| 80 |
current_item["Qty"] = qty_match.group("Qty")
|
| 81 |
current_item["Unit"] = qty_match.group(2)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
if
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
# Save the last item
|
| 89 |
if current_item:
|
| 90 |
current_item["Description"] = clean_description(
|
| 91 |
" ".join(description_accumulator).strip(),
|
|
@@ -93,30 +106,6 @@ def parse_po_items_with_filters(text):
|
|
| 93 |
)
|
| 94 |
data.append(current_item)
|
| 95 |
|
| 96 |
-
# Split merged descriptions and assign items
|
| 97 |
-
for i, row in enumerate(data):
|
| 98 |
-
if row["Item"] == "2" and "As per Drg. to." in row["Description"]:
|
| 99 |
-
# Dynamically identify and split Item 3's description
|
| 100 |
-
item_3_match = re.search(
|
| 101 |
-
r"(Stainless Steel RATING AND DIAGRAM PLATE.*?With Serial No:NT00I53 38 to 50 Mfd:-2022)",
|
| 102 |
-
row["Description"]
|
| 103 |
-
)
|
| 104 |
-
if item_3_match:
|
| 105 |
-
# Insert Item 3 into the data list
|
| 106 |
-
data.insert(
|
| 107 |
-
i + 1,
|
| 108 |
-
{
|
| 109 |
-
"Item": "3",
|
| 110 |
-
"Description": item_3_match.group().strip(),
|
| 111 |
-
"Qty": "12",
|
| 112 |
-
"Unit": "Nos.",
|
| 113 |
-
"Unit Price": "3.80",
|
| 114 |
-
"Total Price": "45.60",
|
| 115 |
-
},
|
| 116 |
-
)
|
| 117 |
-
# Remove extracted Item 3 description from Item 2's description
|
| 118 |
-
row["Description"] = row["Description"].replace(item_3_match.group(), "").strip()
|
| 119 |
-
|
| 120 |
# Remove invalid rows
|
| 121 |
data = [row for row in data if row["Description"]]
|
| 122 |
|
|
|
|
| 80 |
current_item["Qty"] = qty_match.group("Qty")
|
| 81 |
current_item["Unit"] = qty_match.group(2)
|
| 82 |
|
| 83 |
+
# Skip extracting unit price and total price for specific items
|
| 84 |
+
if not re.search(r"(Mfd:-2022|\(NT00192\)|SIZE)", line):
|
| 85 |
+
price_match = re.search(r"(?P<UnitPrice>[\d.]+)\s+(?P<TotalPrice>[\d.]+)$", line)
|
| 86 |
+
if price_match:
|
| 87 |
+
current_item["Unit Price"] = price_match.group("UnitPrice")
|
| 88 |
+
current_item["Total Price"] = price_match.group("TotalPrice")
|
| 89 |
+
|
| 90 |
+
# End of Description: Start new item when description ends with specific pattern
|
| 91 |
+
if re.search(r"(Mfd:-2022|\(NT00192\)|SIZE)", line):
|
| 92 |
+
if current_item:
|
| 93 |
+
current_item["Description"] = clean_description(
|
| 94 |
+
" ".join(description_accumulator).strip(),
|
| 95 |
+
item_number=int(current_item["Item"]),
|
| 96 |
+
)
|
| 97 |
+
data.append(current_item)
|
| 98 |
+
description_accumulator = []
|
| 99 |
+
current_item = None # Reset for the next item
|
| 100 |
|
| 101 |
+
# Save the last item if not already added
|
| 102 |
if current_item:
|
| 103 |
current_item["Description"] = clean_description(
|
| 104 |
" ".join(description_accumulator).strip(),
|
|
|
|
| 106 |
)
|
| 107 |
data.append(current_item)
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# Remove invalid rows
|
| 110 |
data = [row for row in data if row["Description"]]
|
| 111 |
|