Przeglądaj źródła

feat: Include dynamic indicators in new record creation criteria

- Added comparison of dynamic indicator values when determining if new record should be created
- Now creates new record when indicator values change, even if basic fields remain the same
- Handles cases where indicator formulas, thresholds, or weights are modified
- Ensures historical tracking of indicator changes for better analysis
- Uses same tolerance (0.01) for indicator value comparison
root 5 miesięcy temu
rodzic
commit
dbc6e56152
1 zmienionych plików z 24 dodań i 0 usunięć
  1. 24 0
      hr_efficiency/models/hr_efficiency.py

+ 24 - 0
hr_efficiency/models/hr_efficiency.py

@@ -502,10 +502,34 @@ class HrEfficiency(models.Model):
                         'actual_non_billable_hours'
                     ]
                     
+                    # Check basic fields
                     for field in fields_to_compare:
                         if abs(efficiency_data[field] - latest_record[field]) > 0.01:  # Tolerance for floating point
                             has_changes = True
                             break
+                    
+                    # If no changes in basic fields, check dynamic indicators
+                    if not has_changes:
+                        # Get all active indicators
+                        active_indicators = self.env['hr.efficiency.indicator'].search([('active', '=', True)])
+                        
+                        for indicator in active_indicators:
+                            field_name = self._get_indicator_field_name(indicator.name)
+                            
+                            # Calculate current indicator value
+                            current_value = indicator.evaluate_formula(efficiency_data)
+                            
+                            # Get previous indicator value from record
+                            previous_value = getattr(latest_record, field_name, None)
+                            
+                            # Compare values with tolerance
+                            if (current_value is not None and previous_value is not None and 
+                                abs(current_value - previous_value) > 0.01):
+                                has_changes = True
+                                break
+                            elif current_value != previous_value:  # Handle None vs value cases
+                                has_changes = True
+                                break
                 else:
                     # No previous record exists, so this is a change
                     has_changes = True