utkarsh134 commited on
Commit
fb1b75a
·
verified ·
1 Parent(s): e529d7d

Upload acc_processor.py

Browse files
Files changed (1) hide show
  1. acc_processor.py +92 -0
acc_processor.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ class AccessoryProcessor:
10
+ def __init__(self, accessory_type: str):
11
+ # Convert string to enum
12
+ try:
13
+ self.accessory_type = AccessoryType(accessory_type.lower())
14
+ except ValueError:
15
+ raise ValueError(f"Invalid accessory type. Must be one of: {[t.value for t in AccessoryType]}")
16
+
17
+ def get_column_config(self) -> Dict[str, list]:
18
+ base_columns = {
19
+ "metal_columns": [
20
+ "Customer Ref",
21
+ lambda x: next(col for col in x.keys() if "Gold Lock @" in col),
22
+ lambda x: next(col for col in x.keys() if "Platinum Lock" in col),
23
+ "Wt. in gram 14K",
24
+ "Wt. in gram 18K",
25
+ "Wt. in gram PLT",
26
+ "Gold Value 14K",
27
+ "Gold Value 18K",
28
+ "Plat Value",
29
+ "Gold Lock",
30
+ "Platinum Lock"
31
+ ],
32
+ "price_columns": [
33
+ "Price of USD 14K", "Price of USD 18K", "Price of USD PT",
34
+ "Price of GBP 14K @ 1/0.78", "Price of GBP 18K @ 1/0.78", "Price of GBP PT @ 1/0.78",
35
+ "14K Duty @ 2.5% Including", "18K Duty @ 2.5% Including", "PT950 Duty @ 2.5% Including",
36
+ "Freight",
37
+ "14K Landing Cost (Duty + Freight)", "18K Landing Cost (Duty + Freight)",
38
+ "PT950 Landing Cost (Duty + Freight)"
39
+ ]
40
+ }
41
+
42
+ columns_config = {
43
+ AccessoryType.PENDANT: {
44
+ **base_columns,
45
+ "finding_columns": [
46
+ "Finding For Gold 14KT", "Finding For Gold 18KT", "Finding for Plt.",
47
+ "Rhodium", "Stamping", "Setting"
48
+ ],
49
+ "labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
50
+ },
51
+ AccessoryType.RINGBAND: {
52
+ **base_columns,
53
+ "finding_columns": [
54
+ "CFP for Gold 14KT", "CFP for Gold 18KT", "CFP for Plt.",
55
+ "Rhodium", "Stamping", "Setting"
56
+ ],
57
+ "labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
58
+ },
59
+ AccessoryType.EARRING: {
60
+ **base_columns,
61
+ "finding_columns": [
62
+ "Finding & CFP For Gold 14KT",
63
+ "Finding For Gold 18KT",
64
+ "Finding for Plt.",
65
+ "Rhodium",
66
+ "Stamping",
67
+ "Setting"
68
+ ],
69
+ "labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"]
70
+ }
71
+ }
72
+
73
+ return columns_config[self.accessory_type]
74
+
75
+ def calculate_labour(self, metal_data: dict) -> dict:
76
+ if self.accessory_type == AccessoryType.RINGBAND:
77
+ metal_data["Labour 14K"] = float(metal_data.get("Wt. in gram 14K", 0)) * 7
78
+ metal_data["Labour 18K"] = float(metal_data.get("Wt. in gram 18K", 0)) * 7
79
+ metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11
80
+ elif self.accessory_type == AccessoryType.EARRING:
81
+ metal_data["Labour 14K"] = 12
82
+ metal_data["Labour 18K"] = 12
83
+ metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11
84
+ else: # Default PENDANT case
85
+ # Use existing pendant labour calculation
86
+ metal_data["Labour 14K"] = round(12 if (float(metal_data.get("Wt. in gram 14K", 0)) * 7) < 12
87
+ else (float(metal_data.get("Wt. in gram 14K", 0)) * 7), 2)
88
+ metal_data["Labour 18K"] = round(12 if (float(metal_data.get("Wt. in gram 18K", 0)) * 7) < 12
89
+ else (float(metal_data.get("Wt. in gram 18K", 0)) * 7), 2)
90
+ metal_data["Labour PT"] = round(15 if (float(metal_data.get("Wt. in gram PLT", 0)) * 11) < 15
91
+ else (float(metal_data.get("Wt. in gram PLT", 0)) * 11), 2)
92
+ return metal_data