Spaces:
Sleeping
Sleeping
Update acc_processor.py
Browse files- acc_processor.py +111 -91
acc_processor.py
CHANGED
|
@@ -1,92 +1,112 @@
|
|
| 1 |
-
from enum import Enum
|
| 2 |
-
from typing import Dict, Any
|
| 3 |
-
|
| 4 |
-
class AccessoryType(Enum):
|
| 5 |
-
PENDANT = "pendant"
|
| 6 |
-
RINGBAND = "ringband"
|
| 7 |
-
EARRING = "earring"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
"Wt. in gram
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
"
|
| 29 |
-
"Gold
|
| 30 |
-
"
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"
|
| 36 |
-
"
|
| 37 |
-
"14K
|
| 38 |
-
"
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
"Finding
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
return metal_data
|
|
|
|
| 1 |
+
from enum import Enum
|
| 2 |
+
from typing import Dict, Any
|
| 3 |
+
|
| 4 |
+
class AccessoryType(Enum):
|
| 5 |
+
PENDANT = "pendant"
|
| 6 |
+
RINGBAND = "ringband"
|
| 7 |
+
EARRING = "earring"
|
| 8 |
+
BRACELET = "bracelet"
|
| 9 |
+
NECKLACE = "necklace"
|
| 10 |
+
|
| 11 |
+
class AccessoryProcessor:
|
| 12 |
+
def __init__(self, accessory_type: str):
|
| 13 |
+
# Convert string to enum
|
| 14 |
+
try:
|
| 15 |
+
self.accessory_type = AccessoryType(accessory_type.lower())
|
| 16 |
+
except ValueError:
|
| 17 |
+
raise ValueError(f"Invalid accessory type. Must be one of: {[t.value for t in AccessoryType]}")
|
| 18 |
+
|
| 19 |
+
def get_column_config(self) -> Dict[str, list]:
|
| 20 |
+
base_columns = {
|
| 21 |
+
"metal_columns": [
|
| 22 |
+
"Customer Ref",
|
| 23 |
+
lambda x: next(col for col in x.keys() if "Gold Lock @" in col),
|
| 24 |
+
lambda x: next(col for col in x.keys() if "Platinum Lock" in col),
|
| 25 |
+
"Wt. in gram 14K",
|
| 26 |
+
"Wt. in gram 18K",
|
| 27 |
+
"Wt. in gram PLT",
|
| 28 |
+
"Gold Value 14K",
|
| 29 |
+
"Gold Value 18K",
|
| 30 |
+
"Plat Value",
|
| 31 |
+
"Gold Lock",
|
| 32 |
+
"Platinum Lock"
|
| 33 |
+
],
|
| 34 |
+
"price_columns": [
|
| 35 |
+
"Price of USD 14K", "Price of USD 18K", "Price of USD PT",
|
| 36 |
+
"Price of GBP 14K @ 1/0.78", "Price of GBP 18K @ 1/0.78", "Price of GBP PT @ 1/0.78",
|
| 37 |
+
"14K Duty @ 2.5% Including", "18K Duty @ 2.5% Including", "PT950 Duty @ 2.5% Including",
|
| 38 |
+
"Freight",
|
| 39 |
+
"14K Landing Cost (Duty + Freight)", "18K Landing Cost (Duty + Freight)",
|
| 40 |
+
"PT950 Landing Cost (Duty + Freight)"
|
| 41 |
+
]
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
columns_config = {
|
| 45 |
+
AccessoryType.PENDANT: {
|
| 46 |
+
**base_columns,
|
| 47 |
+
"finding_columns": [
|
| 48 |
+
"Finding For Gold 14KT", "Finding For Gold 18KT", "Finding for Plt.",
|
| 49 |
+
"Rhodium", "Stamping"
|
| 50 |
+
],
|
| 51 |
+
"labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
|
| 52 |
+
},
|
| 53 |
+
AccessoryType.RINGBAND: {
|
| 54 |
+
**base_columns,
|
| 55 |
+
"finding_columns": [
|
| 56 |
+
"CFP for Gold 14KT", "CFP for Gold 18KT", "CFP for Plt.",
|
| 57 |
+
"Rhodium", "Stamping"
|
| 58 |
+
],
|
| 59 |
+
"labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
|
| 60 |
+
},
|
| 61 |
+
AccessoryType.EARRING: {
|
| 62 |
+
**base_columns,
|
| 63 |
+
"finding_columns": [
|
| 64 |
+
"Finding & CFP For Gold 14KT",
|
| 65 |
+
"Finding For Gold 18KT",
|
| 66 |
+
"Finding for Plt.",
|
| 67 |
+
"Rhodium",
|
| 68 |
+
"Stamping"
|
| 69 |
+
],
|
| 70 |
+
"labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
|
| 71 |
+
},
|
| 72 |
+
AccessoryType.BRACELET: {
|
| 73 |
+
**base_columns,
|
| 74 |
+
"finding_columns": [
|
| 75 |
+
"CFP For Gold 14KT", "CFP For Gold 18KT", "CFP For Gold PLT",
|
| 76 |
+
"Rhodium", "Stamping", "Setting"
|
| 77 |
+
],
|
| 78 |
+
"labour_columns": []
|
| 79 |
+
},
|
| 80 |
+
AccessoryType.NECKLACE: {
|
| 81 |
+
**base_columns,
|
| 82 |
+
"finding_columns": [
|
| 83 |
+
"CFP For Gold 14KT", "CFP For Gold 18KT", "CFP For Gold PLT",
|
| 84 |
+
"Rhodium", "Stamping", "Setting"
|
| 85 |
+
],
|
| 86 |
+
"labour_columns": []
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return columns_config[self.accessory_type]
|
| 91 |
+
|
| 92 |
+
def calculate_labour(self, metal_data: dict) -> dict:
|
| 93 |
+
if self.accessory_type in [AccessoryType.BRACELET, AccessoryType.NECKLACE]:
|
| 94 |
+
metal_data["Labour 14K"] = 0
|
| 95 |
+
metal_data["Labour 18K"] = 0
|
| 96 |
+
metal_data["Labour PT"] = 0
|
| 97 |
+
elif self.accessory_type == AccessoryType.RINGBAND:
|
| 98 |
+
metal_data["Labour 14K"] = float(metal_data.get("Wt. in gram 14K", 0)) * 7
|
| 99 |
+
metal_data["Labour 18K"] = float(metal_data.get("Wt. in gram 18K", 0)) * 7
|
| 100 |
+
metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11
|
| 101 |
+
elif self.accessory_type == AccessoryType.EARRING:
|
| 102 |
+
metal_data["Labour 14K"] = 12
|
| 103 |
+
metal_data["Labour 18K"] = 12
|
| 104 |
+
metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11
|
| 105 |
+
else: # Default PENDANT case
|
| 106 |
+
metal_data["Labour 14K"] = round(12 if (float(metal_data.get("Wt. in gram 14K", 0)) * 7) < 12
|
| 107 |
+
else (float(metal_data.get("Wt. in gram 14K", 0)) * 7), 2)
|
| 108 |
+
metal_data["Labour 18K"] = round(12 if (float(metal_data.get("Wt. in gram 18K", 0)) * 7) < 12
|
| 109 |
+
else (float(metal_data.get("Wt. in gram 18K", 0)) * 7), 2)
|
| 110 |
+
metal_data["Labour PT"] = round(15 if (float(metal_data.get("Wt. in gram PLT", 0)) * 11) < 15
|
| 111 |
+
else (float(metal_data.get("Wt. in gram PLT", 0)) * 11), 2)
|
| 112 |
return metal_data
|