Ver Fonte

fix: Add post-install hook to preserve dynamic indicators after module reinstall

- Add _post_init_hook method to regenerate dynamic fields after installation
- Ensure all active indicators have manual fields created
- Update views with dynamic fields automatically
- Fix issue where custom indicators disappear after module reinstall
root há 5 meses atrás
pai
commit
a8eb0544a2

+ 2 - 5
hr_efficiency/data/hr_efficiency_post_init.xml

@@ -1,10 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <odoo>
     <data noupdate="1">
-        <!-- Post-installation: Ensure dynamic fields are created and views are updated -->
-        <function model="hr.efficiency" name="_init_dynamic_system"/>
-        <!-- Update views with dynamic fields -->
-        <!-- Temporarily disabled to debug badge widget issue -->
-        <!-- <function model="hr.efficiency" name="_update_views_with_dynamic_fields"/> -->
+        <!-- Post-install hook to ensure dynamic fields are created -->
+        <function model="hr.efficiency" name="_post_init_hook"/>
     </data>
 </odoo>

+ 25 - 0
hr_efficiency/models/hr_efficiency.py

@@ -631,6 +631,31 @@ class HrEfficiency(models.Model):
             _logger.error(f"Error during dynamic system initialization: {str(e)}")
             raise
     
+    @api.model
+    def _post_init_hook(self):
+        """
+        Post-install hook to ensure dynamic fields are created for existing indicators
+        """
+        import logging
+        _logger = logging.getLogger(__name__)
+        
+        try:
+            _logger.info("Running post-install hook for hr_efficiency module")
+            
+            # Ensure all active indicators have manual fields
+            active_indicators = self.env['hr.efficiency.indicator'].search([('active', '=', True)])
+            for indicator in active_indicators:
+                self.env['hr.efficiency.indicator']._create_dynamic_field(indicator)
+            
+            # Update views with dynamic fields
+            self._update_views_with_dynamic_fields()
+            
+            _logger.info(f"Post-install hook completed. Processed {len(active_indicators)} indicators")
+            
+        except Exception as e:
+            _logger.error(f"Error in post-install hook: {str(e)}")
+            raise
+
     @api.model
     def _update_views_with_dynamic_fields(self):
         """