Spaces:
Sleeping
Sleeping
File size: 4,959 Bytes
6eb672d fb1b75a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | from enum import Enum
from typing import Dict, Any
class AccessoryType(Enum):
PENDANT = "pendant"
RINGBAND = "ringband"
EARRING = "earring"
BRACELET = "bracelet"
NECKLACE = "necklace"
class AccessoryProcessor:
def __init__(self, accessory_type: str):
# Convert string to enum
try:
self.accessory_type = AccessoryType(accessory_type.lower())
except ValueError:
raise ValueError(f"Invalid accessory type. Must be one of: {[t.value for t in AccessoryType]}")
def get_column_config(self) -> Dict[str, list]:
base_columns = {
"metal_columns": [
"Customer Ref",
lambda x: next(col for col in x.keys() if "Gold Lock @" in col),
lambda x: next(col for col in x.keys() if "Platinum Lock" in col),
"Wt. in gram 14K",
"Wt. in gram 18K",
"Wt. in gram PLT",
"Gold Value 14K",
"Gold Value 18K",
"Plat Value",
"Gold Lock",
"Platinum Lock"
],
"price_columns": [
"Price of USD 14K", "Price of USD 18K", "Price of USD PT",
"Price of GBP 14K @ 1/0.78", "Price of GBP 18K @ 1/0.78", "Price of GBP PT @ 1/0.78",
"14K Duty @ 2.5% Including", "18K Duty @ 2.5% Including", "PT950 Duty @ 2.5% Including",
"Freight",
"14K Landing Cost (Duty + Freight)", "18K Landing Cost (Duty + Freight)",
"PT950 Landing Cost (Duty + Freight)"
]
}
columns_config = {
AccessoryType.PENDANT: {
**base_columns,
"finding_columns": [
"Finding For Gold 14KT", "Finding For Gold 18KT", "Finding for Plt.",
"Rhodium", "Stamping"
],
"labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
},
AccessoryType.RINGBAND: {
**base_columns,
"finding_columns": [
"CFP for Gold 14KT", "CFP for Gold 18KT", "CFP for Plt.",
"Rhodium", "Stamping"
],
"labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
},
AccessoryType.EARRING: {
**base_columns,
"finding_columns": [
"Finding & CFP For Gold 14KT",
"Finding For Gold 18KT",
"Finding for Plt.",
"Rhodium",
"Stamping"
],
"labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
},
AccessoryType.BRACELET: {
**base_columns,
"finding_columns": [
"CFP For Gold 14KT", "CFP For Gold 18KT", "CFP For Gold PLT",
"Rhodium", "Stamping", "Setting"
],
"labour_columns": []
},
AccessoryType.NECKLACE: {
**base_columns,
"finding_columns": [
"CFP For Gold 14KT", "CFP For Gold 18KT", "CFP For Gold PLT",
"Rhodium", "Stamping", "Setting"
],
"labour_columns": []
}
}
return columns_config[self.accessory_type]
def calculate_labour(self, metal_data: dict) -> dict:
if self.accessory_type in [AccessoryType.BRACELET, AccessoryType.NECKLACE]:
metal_data["Labour 14K"] = 0
metal_data["Labour 18K"] = 0
metal_data["Labour PT"] = 0
elif self.accessory_type == AccessoryType.RINGBAND:
metal_data["Labour 14K"] = float(metal_data.get("Wt. in gram 14K", 0)) * 7
metal_data["Labour 18K"] = float(metal_data.get("Wt. in gram 18K", 0)) * 7
metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11
elif self.accessory_type == AccessoryType.EARRING:
metal_data["Labour 14K"] = 12
metal_data["Labour 18K"] = 12
metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11
else: # Default PENDANT case
metal_data["Labour 14K"] = round(12 if (float(metal_data.get("Wt. in gram 14K", 0)) * 7) < 12
else (float(metal_data.get("Wt. in gram 14K", 0)) * 7), 2)
metal_data["Labour 18K"] = round(12 if (float(metal_data.get("Wt. in gram 18K", 0)) * 7) < 12
else (float(metal_data.get("Wt. in gram 18K", 0)) * 7), 2)
metal_data["Labour PT"] = round(15 if (float(metal_data.get("Wt. in gram PLT", 0)) * 11) < 15
else (float(metal_data.get("Wt. in gram PLT", 0)) * 11), 2)
return metal_data |