@ -0,0 +1,56 @@ |
|||||
|
.. 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, |
||||
|
(V18) Mruthul Raj, |
||||
|
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: Mruthul Raj(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: Mruthul Raj(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': '18.0.1.0.0', |
||||
|
"category": "Extra Tools", |
||||
|
'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.', |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': 'https://www.cybrosys.com', |
||||
|
'depends': ['contacts'], |
||||
|
'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: Mruthul Raj(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: Mruthul Raj(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> |
||||
|
#### 14.11.2024 |
||||
|
#### Version 18.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_company |
||||
|
from . import res_partner |
@ -0,0 +1,190 @@ |
|||||
|
# -*- 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!") |
||||
|
return { |
||||
|
'type': 'ir.actions.client', |
||||
|
'tag': 'display_notification', |
||||
|
'params': { |
||||
|
'type': 'danger', |
||||
|
'sticky': False, |
||||
|
'message': _("Contact imported successfully!"), |
||||
|
'next': {'type': 'ir.actions.act_window_close'}, |
||||
|
} |
||||
|
} |
||||
|
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: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 767 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 697 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 776 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 |