|
@@ -579,6 +579,7 @@ class CrmLead(models.Model):
|
|
|
|
|
|
|
|
validation = drive_service.validate_folder_id(folder_id)
|
|
validation = drive_service.validate_folder_id(folder_id)
|
|
|
if not validation.get('valid'):
|
|
if not validation.get('valid'):
|
|
|
|
|
+ _logger.warning(f"Folder {folder_id} is not valid or accessible")
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
current_name = validation.get('name', '')
|
|
current_name = validation.get('name', '')
|
|
@@ -592,6 +593,11 @@ class CrmLead(models.Model):
|
|
|
|
|
|
|
|
hierarchy = drive_service.navigate_folder_hierarchy(folder_id, max_levels=5)
|
|
hierarchy = drive_service.navigate_folder_hierarchy(folder_id, max_levels=5)
|
|
|
|
|
|
|
|
|
|
+ # If hierarchy is empty, return basic structure with just the opportunity folder
|
|
|
|
|
+ if not hierarchy:
|
|
|
|
|
+ _logger.warning(f"Could not navigate hierarchy for folder {folder_id}")
|
|
|
|
|
+ return complete_structure
|
|
|
|
|
+
|
|
|
for folder_info in hierarchy:
|
|
for folder_info in hierarchy:
|
|
|
folder_name = folder_info.get('name', '')
|
|
folder_name = folder_info.get('name', '')
|
|
|
level = folder_info.get('level', 0)
|
|
level = folder_info.get('level', 0)
|
|
@@ -764,7 +770,33 @@ class CrmLead(models.Model):
|
|
|
current_structure = self._analyze_crm_folder_structure(self.google_drive_folder_id)
|
|
current_structure = self._analyze_crm_folder_structure(self.google_drive_folder_id)
|
|
|
|
|
|
|
|
if not current_structure:
|
|
if not current_structure:
|
|
|
- raise UserError(_('Could not analyze current folder structure'))
|
|
|
|
|
|
|
+ # Provide a more helpful error message
|
|
|
|
|
+ error_msg = f"<strong>❌ Cannot Analyze Folder Structure</strong><br/><br/>"
|
|
|
|
|
+ error_msg += f"<strong>Folder ID:</strong> {self.google_drive_folder_id}<br/>"
|
|
|
|
|
+ error_msg += f"<strong>Possible Issues:</strong><br/>"
|
|
|
|
|
+ error_msg += f"• Folder may not exist or be accessible<br/>"
|
|
|
|
|
+ error_msg += f"• Insufficient permissions to access the folder<br/>"
|
|
|
|
|
+ error_msg += f"• Folder may be in a Shared Drive without proper access<br/>"
|
|
|
|
|
+ error_msg += f"• Network connectivity issues<br/><br/>"
|
|
|
|
|
+ error_msg += f"<strong>Expected Structure:</strong><br/>"
|
|
|
|
|
+ error_msg += f"📁 [Root Folder] (MC Team)<br/>"
|
|
|
|
|
+ error_msg += f"└── 📁 {expected_components['primary_name']} (Company/Contact)<br/>"
|
|
|
|
|
+ error_msg += f" └── 📁 {expected_components['year']} (Year)<br/>"
|
|
|
|
|
+ error_msg += f" └── 📁 {expected_components['opportunity_name']} (Opportunity)<br/>"
|
|
|
|
|
+ error_msg += f" ├── 📁 Meets<br/>"
|
|
|
|
|
+ error_msg += f" └── 📁 Archivos cliente<br/><br/>"
|
|
|
|
|
+ error_msg += f"<strong>Recommendation:</strong> Try using the 'Rename Folder Structure' button to recreate the structure."
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ 'type': 'ir.actions.client',
|
|
|
|
|
+ 'tag': 'display_notification',
|
|
|
|
|
+ 'params': {
|
|
|
|
|
+ 'title': _('Folder Structure Analysis'),
|
|
|
|
|
+ 'message': error_msg,
|
|
|
|
|
+ 'type': 'warning',
|
|
|
|
|
+ 'sticky': True,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
analysis = self._compare_folder_structures(expected_components, current_structure)
|
|
analysis = self._compare_folder_structures(expected_components, current_structure)
|
|
|
|
|
|
|
@@ -779,6 +811,7 @@ class CrmLead(models.Model):
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
|
+ _logger.error(f"Error in action_analyze_folder_structure: {str(e)}")
|
|
|
raise UserError(_('Failed to analyze folder structure: %s') % str(e))
|
|
raise UserError(_('Failed to analyze folder structure: %s') % str(e))
|
|
|
|
|
|
|
|
def _compare_folder_structures(self, expected_components, current_structure):
|
|
def _compare_folder_structures(self, expected_components, current_structure):
|