utkarsh134 commited on
Commit
6eb672d
·
verified ·
1 Parent(s): 775ba9c

Update acc_processor.py

Browse files
Files changed (1) hide show
  1. 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
- 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
 
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