diff --git a/onedrive_integration_odoo/__manifest__.py b/onedrive_integration_odoo/__manifest__.py index bfbc765c2..4cb872f0a 100644 --- a/onedrive_integration_odoo/__manifest__.py +++ b/onedrive_integration_odoo/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################### { 'name': "Onedrive Integration", - 'version': "16.0.1.0.0'", + 'version': "16.0.1.0.2'", 'category': "Document Management", 'summary': """Upload and download files in Onedrive using odoo """, 'description': """This module was developed to upload files to Onedrive as diff --git a/onedrive_integration_odoo/doc/RELEASE_NOTES.md b/onedrive_integration_odoo/doc/RELEASE_NOTES.md index 5c96ccdd6..5615488a2 100644 --- a/onedrive_integration_odoo/doc/RELEASE_NOTES.md +++ b/onedrive_integration_odoo/doc/RELEASE_NOTES.md @@ -8,3 +8,8 @@ #### Version 16.0.1.0.1 #### UPDT - Added modules field and changed view + +#### 12.09.2025 +#### Version 16.0.1.0.2 +##### BUG FIX +- Updated the module workflow to remove the dependency on manually fetching the folder ID. Instead, a new Folder Name field was introduced in the Odoo settings, and the system now automatically retrieves the corresponding Folder ID from the Microsoft Graph API and stores it internally. diff --git a/onedrive_integration_odoo/hooks.py b/onedrive_integration_odoo/hooks.py index c91b3963d..4d4ad7fdb 100644 --- a/onedrive_integration_odoo/hooks.py +++ b/onedrive_integration_odoo/hooks.py @@ -35,3 +35,5 @@ def uninstall_hook(cr, registry): [('key', '=', 'onedrive_integration_odoo.folder_id')]).unlink() env['ir.config_parameter'].sudo().search( [('key', '=', 'onedrive_integration_odoo.onedrive_button')]).unlink() + env['ir.config_parameter'].sudo().search( + [('key', '=', 'onedrive_integration_odoo.folder_id')]).unlink() diff --git a/onedrive_integration_odoo/models/onedrive_dashboard.py b/onedrive_integration_odoo/models/onedrive_dashboard.py index 6172cbe13..e8d9b46db 100644 --- a/onedrive_integration_odoo/models/onedrive_dashboard.py +++ b/onedrive_integration_odoo/models/onedrive_dashboard.py @@ -53,9 +53,7 @@ class OneDriveDashboard(models.Model): help="Binary field to store the uploaded file.") def get_tokens(self, authorize_code): - """ - Generate onedrive tokens from authorization code - """ + """ Generate onedrive tokens from authorization code """ data = { 'code': authorize_code, 'client_id': self.env['ir.config_parameter'].get_param( @@ -76,12 +74,26 @@ class OneDriveDashboard(models.Model): response = res.content and res.json() or {} if response: expires_in = response.get('expires_in') - self.env['onedrive.dashboard'].create({ + record = self.env['onedrive.dashboard'].create({ 'onedrive_access_token': response.get('access_token'), 'onedrive_refresh_token': response.get('refresh_token'), 'token_expiry_date': fields.Datetime.now() + timedelta( seconds=expires_in) if expires_in else False, }) + + folder_name = self.env['ir.config_parameter'].get_param( + 'onedrive_integration_odoo.folder_name', '') + if folder_name: + url = f"https://graph.microsoft.com/v1.0/me/drive/root:/{folder_name}" + res_folder = requests.get(url, headers={ + 'Authorization': f'Bearer {response.get("access_token")}' + }).json() + + if "id" in res_folder: + self.env['ir.config_parameter'].set_param( + 'onedrive_integration_odoo.folder_id', + res_folder["id"] + ) except requests.HTTPError as error: _logger.exception("Bad microsoft onedrive request : %s !", error.response.content) @@ -131,20 +143,35 @@ class OneDriveDashboard(models.Model): return False if record.token_expiry_date <= str(fields.Datetime.now()): record.generate_onedrive_refresh_token() + folder = self.env['ir.config_parameter'].get_param( - 'onedrive_integration_odoo.folder_id', '') - if not folder: return False - url = "https://graph.microsoft.com/v1.0/me/drive/items/%s/children" \ - "?Content-Type=application/json" % folder - response = requests.request("GET", url, headers={ - 'Authorization': 'Bearer "' + record.onedrive_access_token + '"'}, - data={}) + 'onedrive_integration_odoo.folder_id', '' + ) + if not folder: + url = f"https://graph.microsoft.com/v1.0/me/drive/root:/{folder_name}" + response = requests.get(url, headers={ + 'Authorization': f'Bearer {record.onedrive_access_token}' + }) + folder_data = response.json() + if "id" in folder_data: + folder = folder_data["id"] + self.env['ir.config_parameter'].set_param( + 'onedrive_integration_odoo.folder_id', folder + ) + else: + return ['error', 'itemNotFound', 'Folder not found in OneDrive'] + + url = f"https://graph.microsoft.com/v1.0/me/drive/items/{folder}/children" + response = requests.get(url, headers={ + 'Authorization': f'Bearer {record.onedrive_access_token}' + }) message = json.loads(response.content) if 'error' in message: return ['error', message['error']['code'], message['error']['message']] files = {} - for file in response.json().get('value'): - if list(file.keys())[0] == '@microsoft.graph.downloadUrl': + for file in response.json().get('value', []): + if '@microsoft.graph.downloadUrl' in file: files[file['name']] = file['@microsoft.graph.downloadUrl'] return files + diff --git a/onedrive_integration_odoo/models/res_config_settings.py b/onedrive_integration_odoo/models/res_config_settings.py index 55eb19b72..8c1fbebbc 100644 --- a/onedrive_integration_odoo/models/res_config_settings.py +++ b/onedrive_integration_odoo/models/res_config_settings.py @@ -31,12 +31,6 @@ _logger = logging.getLogger(__name__) class ResConfigSettings(models.TransientModel): - """ - This model represents the configuration settings for the OneDrive - integration in Odoo.It allows users to configure various parameters for - OneDrive integration, including client ID, client secret, access token, - and folder ID. - """ _inherit = 'res.config.settings' onedrive_client = fields.Char( @@ -53,22 +47,29 @@ class ResConfigSettings(models.TransientModel): onedrive_tenant_id = fields.Char( string="Onedrive Tenant Id", config_parameter='onedrive_integration_odoo.tenant_id', - help="Director (tenant) id for accessing OneDrive API") + help="Directory (tenant) id for accessing OneDrive API") onedrive_refresh_token = fields.Char( string='Onedrive Refresh Token', help="Refresh Token for refreshing the access token") - onedrive_folder = fields.Char( - string='Folder ID', help="ID of the folder in OneDrive", - config_parameter='onedrive_integration_odoo.folder_id') + + onedrive_folder_name = fields.Char( + string='Folder Name', + help="Name of the folder in OneDrive (ex: ODOO16_onedrive_integration_odoo)", + config_parameter='onedrive_integration_odoo.folder_name' + ) + onedrive_folder_id = fields.Char( + string='Folder ID', + help="Fetched Folder ID from OneDrive API", + config_parameter='onedrive_integration_odoo.folder_id' + ) + is_onedrive_enabled = fields.Boolean( - string="Synchronize Onedrive with odoo", + string="Synchronize Onedrive with Odoo", config_parameter='onedrive_integration_odoo.onedrive_button', help="Enable/Disable OneDrive integration") def action_get_onedrive_auth_code(self): - """ - Generate onedrive authorization code - """ + """ Generate onedrive authorization code """ data = { 'client_id': self.env['ir.config_parameter'].get_param( 'onedrive_integration_odoo.client_id', ''), @@ -117,3 +118,4 @@ class ResConfigSettings(models.TransientModel): 'target': 'self', 'url': "%s?%s" % (authority, encoded_params), } + diff --git a/onedrive_integration_odoo/static/description/assets/screenshots/06.png b/onedrive_integration_odoo/static/description/assets/screenshots/06.png index 5d60ab497..6d3914f4e 100644 Binary files a/onedrive_integration_odoo/static/description/assets/screenshots/06.png and b/onedrive_integration_odoo/static/description/assets/screenshots/06.png differ diff --git a/onedrive_integration_odoo/static/description/assets/screenshots/5.png b/onedrive_integration_odoo/static/description/assets/screenshots/5.png index 40906e5bf..9328212c2 100644 Binary files a/onedrive_integration_odoo/static/description/assets/screenshots/5.png and b/onedrive_integration_odoo/static/description/assets/screenshots/5.png differ diff --git a/onedrive_integration_odoo/static/description/index.html b/onedrive_integration_odoo/static/description/index.html index 85933823b..e7a661a43 100644 --- a/onedrive_integration_odoo/static/description/index.html +++ b/onedrive_integration_odoo/static/description/index.html @@ -191,10 +191,10 @@
- The Onedrive folder id is presented on url of that folder itself.
+ Use the Onedrive folder name for odoo setup.- Token setup is available in configuration settings. Setup Tokens button will redirect to an authorization page. + Token setup is available in configuration settings.After token setup system now automatically retrieves the corresponding Folder ID using Folder Name and stores it internally. Setup Tokens button will redirect to an authorization page. Goto --> Settngs-->Integrations