@ -0,0 +1,55 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
Google Contact Connector |
|||
======================== |
|||
Google Contact Connector module helps to Synchronize Google Contacts. |
|||
|
|||
Features |
|||
======== |
|||
* Import Odoo contacts to Google. |
|||
* Delete contact from Odoo and Google. |
|||
* Export Google contacts to Odoo. |
|||
* Filter contact synced with Google. |
|||
|
|||
Configuration |
|||
============= |
|||
* No additional configurations needed |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
------- |
|||
General Public License, Version 3 (AGPL v3). |
|||
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
* Developers: (V16) Gion Dany, |
|||
(V17) Farhana Jahan PT, |
|||
Contact: odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
* Website : https://cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
|
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import controllers |
|||
from . import models |
@ -0,0 +1,43 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
{ |
|||
'name': "Google Contact Connector", |
|||
'version': '17.0.1.0.0', |
|||
'summary': """Synchronize Google Contacts (Import/Export).""", |
|||
'description': 'The Google Contact Connector module helps you import Google' |
|||
' contacts from Odoo and export Google contacts to Odoo.', |
|||
"category": "Extra Tools", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'depends': ['contacts'], |
|||
'website': 'https://www.cybrosys.com', |
|||
'data': [ |
|||
'views/res_company_views.xml', |
|||
'views/res_partner_views.xml' |
|||
], |
|||
'images': ['static/description/banner.jpg'], |
|||
'license': "AGPL-3", |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False |
|||
} |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import google_contact_integration |
@ -0,0 +1,73 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import datetime |
|||
import requests |
|||
from odoo import _ |
|||
from odoo import http |
|||
from odoo.exceptions import UserError |
|||
from odoo.http import request |
|||
|
|||
TIMEOUT = 20 |
|||
|
|||
|
|||
class GoogleContactAuth(http.Controller): |
|||
"""Controller for Google Contact authentication. """ |
|||
@http.route('/google_contact_authentication', type="http", auth="public", |
|||
website=True) |
|||
def get_auth_code(self, **kw): |
|||
"""Connect your Google account with the OAuth Authentication process. |
|||
You will be redirected to the Google login page |
|||
where you will need to accept the permission.""" |
|||
user_id = request.uid |
|||
company_id = http.request.env['res.users'].sudo().search( |
|||
[('id', '=', user_id)], limit=1).company_id |
|||
if kw.get('code'): |
|||
company_id.write( |
|||
{'contact_company_authorization_code': kw.get('code')}) |
|||
data = { |
|||
'code': kw.get('code'), |
|||
'client_id': company_id.contact_client_id, |
|||
'client_secret': company_id.contact_client_secret, |
|||
'redirect_uri': company_id.contact_redirect_uri, |
|||
'grant_type': 'authorization_code' |
|||
} |
|||
response = requests.post( |
|||
'https://accounts.google.com/o/oauth2/token', data=data, |
|||
headers={ |
|||
'content-type': 'application/x-www-form-urlencoded'}, |
|||
timeout=TIMEOUT) |
|||
if response.json() and response.json().get('access_token'): |
|||
company_id.write({ |
|||
'contact_company_access_token': |
|||
response.json().get('access_token'), |
|||
'contact_company_access_token_expiry': |
|||
datetime.datetime.now() + datetime.timedelta( |
|||
seconds=response.json().get('expires_in')), |
|||
'contact_company_refresh_token': |
|||
response.json().get('access_token'), |
|||
}) |
|||
return "Authentication Success. You Can Close this window" |
|||
else: |
|||
raise UserError( |
|||
_('Something went wrong during the token generation.' |
|||
'Maybe your Authorization Code is invalid') |
|||
) |
@ -0,0 +1,5 @@ |
|||
## Module <odoo_google_contact_integration> |
|||
#### 21.03.2024 |
|||
#### Version 17.0.1.0.0 |
|||
#### ADD |
|||
- Initial commit for Google Contact Connector |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import res_partner |
|||
from . import res_company |
@ -0,0 +1,180 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import logging |
|||
import requests |
|||
from odoo import api, fields, models, _ |
|||
from odoo.exceptions import UserError, ValidationError |
|||
from odoo.http import request |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
TIMEOUT = 20 |
|||
|
|||
|
|||
class ResCompany(models.Model): |
|||
"""Inherit res_company for integrating contacts with Google""" |
|||
_inherit = "res.company" |
|||
|
|||
contact_client_id = fields.Char( |
|||
string="Client Id", help='People API Client ID') |
|||
contact_client_secret = fields.Char( |
|||
string="Client Secret", help='People API Client Secret') |
|||
contact_redirect_uri = fields.Char( |
|||
string="Authorized redirect URIs", |
|||
compute="_compute_contact_redirect_uri", |
|||
help='People API Authorized redirect URIs') |
|||
contact_company_access_token = fields.Char( |
|||
string="Access Token", copy=False, readonly=True, |
|||
help='People API Access Token') |
|||
contact_company_access_token_expiry = fields.Datetime( |
|||
string="Token expiry", help='People API Token Expiry', |
|||
readonly=True) |
|||
contact_company_refresh_token = fields.Char( |
|||
string="Refresh Token", copy=False, readonly=True, |
|||
help='People API Refresh Token') |
|||
contact_company_authorization_code = fields.Char( |
|||
string="Authorization Code", readonly=True, |
|||
help='People API Authorization Code') |
|||
|
|||
@api.depends('contact_redirect_uri') |
|||
def _compute_contact_redirect_uri(self): |
|||
"""Compute the redirect URI for onedrive and Google Drive""" |
|||
for rec in self: |
|||
base_url = request.env['ir.config_parameter'].get_param( |
|||
'web.base.url') |
|||
rec.contact_redirect_uri = base_url + '/google_contact_authentication' |
|||
|
|||
def action_google_contact_authenticate(self): |
|||
"""Authenticate the connection to Google.""" |
|||
if not self.contact_client_id: |
|||
raise ValidationError("Please Enter Client ID") |
|||
if not self.contact_redirect_uri: |
|||
raise ValidationError("Please Enter Client Secret") |
|||
people_scope = 'https://www.googleapis.com/auth/contacts' |
|||
url = ( |
|||
"https://accounts.google.com/o/oauth2/v2/auth?response_type=code" |
|||
"&access_type=offline&client_id={}&redirect_uri={}&scope={} " |
|||
).format(self.contact_client_id, |
|||
self.contact_redirect_uri, people_scope) |
|||
return { |
|||
"type": 'ir.actions.act_url', |
|||
"url": url, |
|||
"target": "new" |
|||
} |
|||
|
|||
def action_google_contact_refresh_token(self): |
|||
"""Request a refresh token from Google.""" |
|||
if not self.contact_client_id: |
|||
raise UserError( |
|||
_('Client ID is not yet configured.')) |
|||
if not self.contact_client_secret: |
|||
raise UserError( |
|||
_('Client Secret is not yet configured.')) |
|||
if not self.contact_company_refresh_token: |
|||
raise UserError( |
|||
_('Refresh Token is not yet configured.')) |
|||
data = { |
|||
'client_id': self.contact_client_id, |
|||
'client_secret': self.contact_client_secret, |
|||
'refresh_token': self.contact_company_refresh_token, |
|||
'grant_type': 'refresh_token', |
|||
} |
|||
response = requests.post( |
|||
'https://accounts.google.com/o/oauth2/token', data=data, |
|||
headers={ |
|||
'content-type': 'application/x-www-form-urlencoded'}, |
|||
timeout=TIMEOUT) |
|||
if response.json() and response.json().get('access_token'): |
|||
self.write({ |
|||
'contact_company_access_token': |
|||
response.json().get('access_token'), |
|||
}) |
|||
else: |
|||
raise UserError( |
|||
_('Something went wrong during the token generation.' |
|||
' Please request again an authorization code.') |
|||
) |
|||
|
|||
def action_import_google_contacts(self): |
|||
"""IMPORT Contacts FROM Google TO ODOO""" |
|||
url = ("https://people.googleapis.com/v1/people/me/" |
|||
"connections?personFields=names,addresses," |
|||
"emailAddresses,phoneNumbers&pageSize=1000") |
|||
headers = { |
|||
'Authorization': f'Bearer {self.contact_company_access_token}', |
|||
'Content-Type': 'application/json' |
|||
} |
|||
response = requests.get(url, headers=headers) |
|||
if response.status_code == 200: |
|||
data = response.json().get('connections', []) |
|||
partners = [] |
|||
for connection in data: |
|||
cnt_rsr_name = connection.get('resourceName', '') |
|||
etag = connection.get('etag', '') |
|||
names = connection.get('names', [{}])[0] |
|||
first_name = names.get('givenName', '') |
|||
last_name = names.get('familyName', '') |
|||
name = names.get('displayName', '') |
|||
emailAddresses = connection.get('emailAddresses', [{}])[0] |
|||
email = emailAddresses.get('value', '') |
|||
phoneNumbers = connection.get('phoneNumbers', [{}])[0] |
|||
phone = phoneNumbers.get('value', '') |
|||
addresses = connection.get('addresses', [{}])[0] |
|||
street = addresses.get('streetAddress', '') |
|||
street2 = addresses.get('extendedAddress', '') |
|||
city = addresses.get('city', '') |
|||
pin = addresses.get('postalCode', '') |
|||
state = addresses.get('region', '') |
|||
state = self.env['res.country.state'].search( |
|||
[("name", 'ilike', state)], limit=1) |
|||
state_id = state.id if state else False |
|||
country_code = addresses.get('countryCode', '') |
|||
country = self.env['res.country'].search( |
|||
[('code', 'ilike', country_code)], limit=1) |
|||
country_id = country.id if country else False |
|||
partner_vals = { |
|||
'name': name or '', |
|||
'first_name': first_name or '', |
|||
'last_name': last_name or '', |
|||
'email': email or '', |
|||
'street': street or '', |
|||
'street2': street2 or '', |
|||
'city': city or '', |
|||
'zip': pin or '', |
|||
'state_id': state_id or False, |
|||
'country_id': country_id or False, |
|||
'phone': phone, |
|||
'google_resource': cnt_rsr_name, |
|||
'google_etag': etag, |
|||
} |
|||
existing_partner = self.env['res.partner'].search( |
|||
[('google_resource', '=', cnt_rsr_name)], limit=1) |
|||
if existing_partner: |
|||
existing_partner.write(partner_vals) |
|||
else: |
|||
partners.append(partner_vals) |
|||
if partners: |
|||
self.env['res.partner'].create(partners) |
|||
_logger.info("Contact imported successfully!") |
|||
else: |
|||
error_message = f"Failed to import contact. Error: {response.text}" |
|||
raise ValidationError(error_message) |
@ -0,0 +1,163 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Cybrosys Techno Solutions (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import logging |
|||
import requests |
|||
from odoo import fields, models |
|||
from odoo.exceptions import ValidationError |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
TIMEOUT = 20 |
|||
|
|||
|
|||
class ResPartner(models.Model): |
|||
"""Inherit res_partner for integrating contacts with Google""" |
|||
_inherit = 'res.partner' |
|||
|
|||
google_resource = fields.Char('Google Contact Id', |
|||
help='Contact Unique identifier', |
|||
readonly=True) |
|||
google_etag = fields.Char( |
|||
'Google Etag', help='Contact Version control key', readonly=True) |
|||
first_name = fields.Char( |
|||
'First Name', help='Enter the first name of the person.') |
|||
last_name = fields.Char( |
|||
'Last Name', help='Enter the last name of the person.') |
|||
|
|||
def action_export_google_contacts(self): |
|||
"""Export Contacts FROM Google TO ODOO""" |
|||
current_uid = self._context.get('uid') |
|||
user_id = self.env['res.users'].browse(current_uid) |
|||
company_id = user_id.company_id |
|||
partner_ids = self.env['res.partner'].sudo().browse( |
|||
self.env.context.get('active_ids')) |
|||
for partner in partner_ids: |
|||
header = { |
|||
'Authorization': |
|||
f'Bearer {company_id.contact_company_access_token}', |
|||
'Content-Type': 'application/json' |
|||
} |
|||
contact_payload = { |
|||
'names': [ |
|||
{ |
|||
'givenName': partner.first_name or partner.name, |
|||
'familyName': partner.last_name or '' |
|||
} |
|||
], |
|||
'emailAddresses': [ |
|||
{ |
|||
'value': partner.email or '', |
|||
'type': 'work' |
|||
} |
|||
], |
|||
'phoneNumbers': [ |
|||
{ |
|||
'value': partner.phone or '', |
|||
'type': 'work' |
|||
} |
|||
], |
|||
'addresses': [ |
|||
{ |
|||
'streetAddress': partner.street or '', |
|||
'city': partner.city or '', |
|||
'region': partner.state_id.name or '', |
|||
'postalCode': partner.zip or '', |
|||
'country': partner.country_id.name or '', |
|||
'type': 'work' |
|||
} |
|||
], |
|||
'organizations': [ |
|||
{ |
|||
'name': partner.company_id.name or '', |
|||
'title': partner.title or '', |
|||
'type': 'work' |
|||
} |
|||
] |
|||
} |
|||
if partner.google_etag: |
|||
contact_resource_name = partner.google_resource |
|||
contact_payload['resourceName'] = contact_resource_name |
|||
contact_payload['etag'] = partner.google_etag |
|||
url = ( |
|||
f"https://people.googleapis.com/v1/{contact_resource_name}:updateContact?" |
|||
"updatePersonFields=emailAddresses,names,phoneNumbers," |
|||
"addresses,organizations,userDefined&" |
|||
"prettyPrint=false" |
|||
) |
|||
response = requests.patch(url, headers=header, |
|||
json=contact_payload) |
|||
if response.status_code == 200: |
|||
partner.write({ |
|||
'google_resource': response.json().get('resourceName'), |
|||
'google_etag': response.json().get('etag') |
|||
}) |
|||
_logger.info("Contact updated successfully!") |
|||
else: |
|||
error_message = f"Failed to update contact. Error: {response.text}" |
|||
raise ValidationError(error_message) |
|||
else: |
|||
url = 'https://people.googleapis.com/v1/people:createContact' |
|||
result = requests.post(url, headers=header, |
|||
json=contact_payload) |
|||
if result.status_code == 200: |
|||
partner.write({ |
|||
'google_resource': result.json().get('resourceName'), |
|||
'google_etag': result.json().get('etag') |
|||
}) |
|||
_logger.info("Contact exported successfully!") |
|||
else: |
|||
error_message = f"Failed to export contact. Error: {result.text}" |
|||
raise ValidationError(error_message) |
|||
|
|||
def action_delete_google_contact(self): |
|||
"""Deleting a contact from Google Contacts""" |
|||
current_uid = self._context.get('uid') |
|||
user_id = self.env['res.users'].browse(current_uid) |
|||
company_id = user_id.company_id |
|||
partner_ids = self.env['res.partner'].sudo().browse( |
|||
self.env.context.get('active_ids')) |
|||
for partner in partner_ids: |
|||
contact_resource_name = partner.google_resource |
|||
if not contact_resource_name: |
|||
_logger.warning( |
|||
"Partner %s does not have a Google contact resource name.", |
|||
partner.name) |
|||
continue |
|||
url = f"https://people.googleapis.com/v1/{contact_resource_name}:deleteContact" |
|||
headers = { |
|||
'Authorization': f'Bearer {company_id.contact_company_access_token}', |
|||
'Content-Type': 'application/json' |
|||
} |
|||
response = requests.delete(url, headers=headers) |
|||
if response.status_code == 200: |
|||
_logger.info("Contact deleted successfully!") |
|||
partner.google_resource = '' |
|||
partner.google_etag = '' |
|||
partner.unlink() |
|||
elif response.status_code == 404: |
|||
_logger.warning( |
|||
"Contact not found in Google. Removing local reference.") |
|||
partner.google_resource = '' |
|||
partner.google_etag = '' |
|||
else: |
|||
error_message = f"Failed to delete contact. Error: {response.text}" |
|||
raise ValidationError(error_message) |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 565 B |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 88 KiB |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 107 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 105 KiB |
After Width: | Height: | Size: 130 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 106 KiB |
After Width: | Height: | Size: 633 KiB |
After Width: | Height: | Size: 63 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 121 KiB |
After Width: | Height: | Size: 106 KiB |
After Width: | Height: | Size: 130 KiB |
After Width: | Height: | Size: 111 KiB |
After Width: | Height: | Size: 96 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 364 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 5.2 KiB |
@ -0,0 +1,55 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!--Inherit the Res Company form view --> |
|||
<record id="view_company_form" model="ir.ui.view"> |
|||
<field name="name"> |
|||
res.company.view.form.inherit.odoo.google.contact.integration |
|||
</field> |
|||
<field name="model">res.company</field> |
|||
<field name="inherit_id" ref="base.view_company_form"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//notebook/page[1]" position="after"> |
|||
<page string="Google Contact"> |
|||
<separator name="gci_configuration" |
|||
string="Google Contact Configuration"/> |
|||
<notebook> |
|||
<page name="gci_credentials" string="Credentials"> |
|||
<group> |
|||
<field name="contact_client_id"/> |
|||
<field name="contact_client_secret"/> |
|||
<field name="contact_redirect_uri"/> |
|||
</group> |
|||
<group> |
|||
<button string="Authenticate" type="object" |
|||
name="action_google_contact_authenticate" |
|||
class="oe_highlight" |
|||
/> |
|||
<button string="Refresh Token" type="object" |
|||
name="action_google_contact_refresh_token" |
|||
class="oe_highlight"/> |
|||
</group> |
|||
</page> |
|||
<page name="gci_authentication" string="Authentication"> |
|||
<group> |
|||
<field name="contact_company_access_token"/> |
|||
<field name="contact_company_access_token_expiry"/> |
|||
<field name="contact_company_refresh_token"/> |
|||
<field name="contact_company_authorization_code"/> |
|||
</group> |
|||
</page> |
|||
<page name="gci_export" string="Import"> |
|||
<group> |
|||
<div style="width: 150px; height: 50px; font-size: 16px;"> |
|||
<button string="Import Contacts" |
|||
type="object" |
|||
name="action_import_google_contacts" |
|||
/> |
|||
</div> |
|||
</group> |
|||
</page> |
|||
</notebook> |
|||
</page> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,60 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!--Inherit the Res Partner form view --> |
|||
<record id="view_partner_form" model="ir.ui.view"> |
|||
<field name="name"> |
|||
res.partner.view.form.inherit.odoo.google.contact.integration |
|||
</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_partner_form"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//span[@name='address_name']" position="before"> |
|||
<field name='first_name'/> |
|||
<field name="last_name"/> |
|||
</xpath> |
|||
<xpath expr="//field[@name='industry_id']" position="after"> |
|||
<field name="google_resource"/> |
|||
<field name="google_etag"/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
<!-- Export G-Contact Button in action menu --> |
|||
<record id="action_export_google_contact" model="ir.actions.server"> |
|||
<field name="name">Export to Google</field> |
|||
<field name="model_id" ref="model_res_partner"/> |
|||
<field name="binding_model_id" ref="model_res_partner"/> |
|||
<field name="binding_view_types">list,form</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
if records: |
|||
action = records.action_export_google_contacts() |
|||
</field> |
|||
</record> |
|||
<!--Inherit the Res Partner filter view --> |
|||
<record id="view_res_partner_filter" model="ir.ui.view"> |
|||
<field name="name"> |
|||
res.partner.view.search.inherit.odoo.google.contact.integration |
|||
</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_res_partner_filter"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//filter[@name='type_company']" position="after"> |
|||
<separator/> |
|||
<filter string="G-Contacts" name="g_contacts" |
|||
domain="[('google_resource','!=', False)]"/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
<!-- Delete G-Contact Button in action menu --> |
|||
<record id="action_delete_google_contact" model="ir.actions.server"> |
|||
<field name="name">Delete G-Contact</field> |
|||
<field name="model_id" ref="model_res_partner"/> |
|||
<field name="binding_model_id" ref="model_res_partner"/> |
|||
<field name="binding_view_types">list,form</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
if records: |
|||
action = records.action_delete_google_contact() |
|||
</field> |
|||
</record> |
|||
</odoo> |