[MIG] google_calendar: migrate to new api
No behaviour changes, only migrate code and add some docstring.
This commit is contained in:
committed by
Jérome Maes
parent
996d6de620
commit
9b39275d85
@@ -1,2 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import controllers
|
||||
import models
|
||||
import models
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import main
|
||||
|
||||
@@ -1,59 +1,58 @@
|
||||
import openerp.http as http
|
||||
from openerp.http import request
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class google_calendar_controller(http.Controller):
|
||||
class GoogleCalendarController(http.Controller):
|
||||
|
||||
@http.route('/google_calendar/sync_data', type='json', auth='user')
|
||||
def sync_data(self, arch, fields, model, **kw):
|
||||
"""
|
||||
This route/function is called when we want to synchronize openERP calendar with Google Calendar
|
||||
""" This route/function is called when we want to synchronize openERP calendar with Google Calendar
|
||||
Function return a dictionary with the status : need_config_from_admin, need_auth, need_refresh, success if not calendar_event
|
||||
The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example
|
||||
"""
|
||||
|
||||
if model == 'calendar.event':
|
||||
gs_obj = request.registry['google.service']
|
||||
gc_obj = request.registry['google.calendar']
|
||||
GoogleService = request.env['google.service']
|
||||
GoogleCal = request.env['google.calendar']
|
||||
|
||||
# Checking that admin have already configured Google API for google synchronization !
|
||||
client_id = gs_obj.get_client_id(request.cr, request.uid, 'calendar', context=kw.get('local_context'))
|
||||
context = kw.get('local_context', {})
|
||||
client_id = GoogleService.with_context(context).get_client_id('calendar')
|
||||
|
||||
if not client_id or client_id == '':
|
||||
action = ''
|
||||
if gc_obj.can_authorize_google(request.cr, request.uid):
|
||||
dummy, action = request.registry.get('ir.model.data').get_object_reference(request.cr, request.uid,
|
||||
'google_calendar', 'action_config_settings_google_calendar')
|
||||
|
||||
action_id = ''
|
||||
if GoogleCal.can_authorize_google():
|
||||
action_id = request.env.ref('google_calendar.action_config_settings_google_calendar').id
|
||||
return {
|
||||
"status": "need_config_from_admin",
|
||||
"url": '',
|
||||
"action": action
|
||||
"action": action_id
|
||||
}
|
||||
|
||||
# Checking that user have already accepted OpenERP to access his calendar !
|
||||
if gc_obj.need_authorize(request.cr, request.uid, context=kw.get('local_context')):
|
||||
url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'), context=kw.get('local_context'))
|
||||
if GoogleCal.need_authorize():
|
||||
url = GoogleCal.with_context(context).authorize_google_uri(from_url=kw.get('fromurl'))
|
||||
return {
|
||||
"status": "need_auth",
|
||||
"url": url
|
||||
}
|
||||
|
||||
# If App authorized, and user access accepted, We launch the synchronization
|
||||
return gc_obj.synchronize_events(request.cr, request.uid, [], context=kw.get('local_context'))
|
||||
return GoogleCal.with_context(context).synchronize_events()
|
||||
|
||||
return {"status": "success"}
|
||||
|
||||
@http.route('/google_calendar/remove_references', type='json', auth='user')
|
||||
def remove_references(self, model, **kw):
|
||||
"""
|
||||
This route/function is called when we want to remove all the references between one calendar OpenERP and one Google Calendar
|
||||
"""
|
||||
""" This route/function is called when we want to remove all the references between one calendar OpenERP and one Google Calendar """
|
||||
status = "NOP"
|
||||
if model == 'calendar.event':
|
||||
gc_obj = request.registry['google.calendar']
|
||||
GoogleCal = request.env['google.calendar']
|
||||
# Checking that user have already accepted OpenERP to access his calendar !
|
||||
if gc_obj.remove_references(request.cr, request.uid, context=kw.get('local_context')):
|
||||
context = kw.get('local_context', {})
|
||||
if GoogleCal.with_context(context).remove_references():
|
||||
status = "OK"
|
||||
else:
|
||||
status = "KO"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<openerp>
|
||||
|
||||
<odoo>
|
||||
<data>
|
||||
<record forcecreate="True" id="ir_cron_sync_all_cals" model="ir.cron">
|
||||
<field name="name">Calendar synchronization</field>
|
||||
@@ -14,6 +12,5 @@
|
||||
<field eval="'google.calendar'" name="model" />
|
||||
<field eval="'synchronize_events_cron'" name="function" />
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
@@ -1,67 +1,63 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datatime import datetime
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class calendar_event(osv.Model):
|
||||
class Meeting(models.Model):
|
||||
|
||||
_inherit = "calendar.event"
|
||||
|
||||
def get_fields_need_update_google(self, cr, uid, context=None):
|
||||
recurrent_fields = self._get_recurrent_fields(cr, uid, context=context)
|
||||
oe_update_date = fields.Datetime('Odoo Update Date')
|
||||
|
||||
@api.model
|
||||
def get_fields_need_update_google(self):
|
||||
recurrent_fields = self._get_recurrent_fields()
|
||||
return recurrent_fields + ['name', 'description', 'allday', 'start', 'date_end', 'stop',
|
||||
'attendee_ids', 'alarm_ids', 'location', 'class', 'active',
|
||||
'attendee_ids', 'alarm_ids', 'location', 'privacy', 'active',
|
||||
'start_date', 'start_datetime', 'stop_date', 'stop_datetime']
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
sync_fields = set(self.get_fields_need_update_google(cr, uid, context))
|
||||
if (set(vals.keys()) & sync_fields) and 'oe_update_date' not in vals.keys() and 'NewMeeting' not in context:
|
||||
vals['oe_update_date'] = datetime.now()
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
sync_fields = set(self.get_fields_need_update_google())
|
||||
if (set(values.keys()) and sync_fields) and 'oe_update_date' not in values.keys() and 'NewMeeting' not in self._context:
|
||||
values['oe_update_date'] = fields.Datetime.now()
|
||||
return super(Meeting, self).write(values)
|
||||
|
||||
return super(calendar_event, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
@api.multi
|
||||
def copy(self, default=None):
|
||||
default = default or {}
|
||||
if default.get('write_type', False):
|
||||
del default['write_type']
|
||||
elif default.get('recurrent_id', False):
|
||||
default['oe_update_date'] = datetime.now()
|
||||
default['oe_update_date'] = fields.Datetime.now()
|
||||
else:
|
||||
default['oe_update_date'] = False
|
||||
return super(calendar_event, self).copy(cr, uid, id, default, context)
|
||||
return super(Meeting, self).copy(default)
|
||||
|
||||
def unlink(self, cr, uid, ids, can_be_deleted=False, context=None):
|
||||
return super(calendar_event, self).unlink(cr, uid, ids, can_be_deleted=can_be_deleted, context=context)
|
||||
|
||||
_columns = {
|
||||
'oe_update_date': fields.datetime('Odoo Update Date'),
|
||||
}
|
||||
@api.multi
|
||||
def unlink(self, can_be_deleted=False):
|
||||
return super(Meeting, self).unlink(can_be_deleted=can_be_deleted)
|
||||
|
||||
|
||||
class calendar_attendee(osv.Model):
|
||||
class Attendee(models.Model):
|
||||
|
||||
_inherit = 'calendar.attendee'
|
||||
|
||||
_columns = {
|
||||
'google_internal_event_id': fields.char('Google Calendar Event Id'),
|
||||
'oe_synchro_date': fields.datetime('Odoo Synchro Date'),
|
||||
}
|
||||
_sql_constraints = [('google_id_uniq', 'unique(google_internal_event_id,partner_id,event_id)', 'Google ID should be unique!')]
|
||||
google_internal_event_id = fields.Char('Google Calendar Event Id')
|
||||
oe_synchro_date = fields.Datetime('Odoo Synchro Date')
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
_sql_constraints = [
|
||||
('google_id_uniq', 'unique(google_internal_event_id,partner_id,event_id)', 'Google ID should be unique!')
|
||||
]
|
||||
|
||||
for id in ids:
|
||||
ref = vals.get('event_id', self.browse(cr, uid, id, context=context).event_id.id)
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
for attendee in self:
|
||||
meeting_id_to_update = values.get('event_id', attendee.event_id.id)
|
||||
|
||||
# If attendees are updated, we need to specify that next synchro need an action
|
||||
# Except if it come from an update_from_google
|
||||
if not context.get('curr_attendee', False) and not context.get('NewMeeting', False):
|
||||
self.pool['calendar.event'].write(cr, uid, ref, {'oe_update_date': datetime.now()}, context)
|
||||
return super(calendar_attendee, self).write(cr, uid, ids, vals, context=context)
|
||||
if not self._context.get('curr_attendee', False) and not self._context.get('NewMeeting', False):
|
||||
self.env['calendar.event'].browse(meeting_id_to_update).write({'oe_update_date': fields.Datetime.now()})
|
||||
return super(Attendee, self).write(values)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,29 +1,24 @@
|
||||
from openerp.osv import fields, osv
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class CalendarSettings(models.TransientModel):
|
||||
|
||||
class calendar_config_settings(osv.TransientModel):
|
||||
_inherit = 'base.config.settings'
|
||||
|
||||
_columns = {
|
||||
'google_cal_sync': fields.boolean("Show Tutorial"),
|
||||
'cal_client_id': fields.char("Client_id"),
|
||||
'cal_client_secret': fields.char("Client_key"),
|
||||
'server_uri': fields.char('URI for tuto')
|
||||
}
|
||||
|
||||
def set_calset(self, cr, uid, ids, context=None) :
|
||||
params = self.pool['ir.config_parameter']
|
||||
myself = self.browse(cr, uid, ids[0], context=context)
|
||||
params.set_param(cr, uid, 'google_calendar_client_id', (myself.cal_client_id or '').strip(), groups=['base.group_system'], context=None)
|
||||
params.set_param(cr, uid, 'google_calendar_client_secret', (myself.cal_client_secret or '').strip(), groups=['base.group_system'], context=None)
|
||||
|
||||
|
||||
def get_default_all(self, cr, uid, fields, context=None):
|
||||
params = self.pool.get('ir.config_parameter')
|
||||
cal_client_id = params.get_param(cr, uid, 'google_calendar_client_id',default='',context=context)
|
||||
cal_client_secret = params.get_param(cr, uid, 'google_calendar_client_secret',default='',context=context)
|
||||
server_uri= "%s/google_account/authentication" % params.get_param(cr, uid, 'web.base.url',default="http://yourcompany.odoo.com",context=context)
|
||||
return dict(cal_client_id=cal_client_id,cal_client_secret=cal_client_secret,server_uri=server_uri)
|
||||
|
||||
|
||||
|
||||
|
||||
google_cal_sync = fields.Boolean("Show Tutorial")
|
||||
cal_client_id = fields.Char("Client_id")
|
||||
cal_client_secret = fields.Char("Client_key")
|
||||
server_uri = fields.Char('URI for tuto')
|
||||
|
||||
def set_calset(self):
|
||||
self.env['ir.config_parameter'].set_param('google_calendar_client_id', (self.cal_client_id or '').strip(), groups=['base.group_system'])
|
||||
self.env['ir.config_parameter'].set_param('google_calendar_client_secret', (self.cal_client_secret or '').strip(), groups=['base.group_system'])
|
||||
|
||||
def get_default_all(self, fields):
|
||||
cal_client_id = self.env['ir.config_parameter'].get_param('google_calendar_client_id', default='')
|
||||
cal_client_secret = self.env['ir.config_parameter'].get_param('google_calendar_client_secret', default='')
|
||||
server_uri = "%s/google_account/authentication" % self.env['ir.config_parameter'].get_param('web.base.url', default="http://yourcompany.odoo.com")
|
||||
return dict(cal_client_id=cal_client_id, cal_client_secret=cal_client_secret, server_uri=server_uri)
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class res_users(osv.Model):
|
||||
class User(models.Model):
|
||||
|
||||
_inherit = 'res.users'
|
||||
|
||||
_columns = {
|
||||
'google_calendar_rtoken': fields.char('Refresh Token', copy=False),
|
||||
'google_calendar_token': fields.char('User token', copy=False),
|
||||
'google_calendar_token_validity': fields.datetime('Token Validity', copy=False),
|
||||
'google_calendar_last_sync_date': fields.datetime('Last synchro date', copy=False),
|
||||
'google_calendar_cal_id': fields.char('Calendar ID', help='Last Calendar ID who has been synchronized. If it is changed, we remove \
|
||||
all links between GoogleID and Odoo Google Internal ID', copy=False)
|
||||
}
|
||||
google_calendar_rtoken = fields.Char('Refresh Token', copy=False)
|
||||
google_calendar_token = fields.Char('User token', copy=False)
|
||||
google_calendar_token_validity = fields.Datetime('Token Validity', copy=False)
|
||||
google_calendar_last_sync_date = fields.Datetime('Last synchro date', copy=False)
|
||||
google_calendar_cal_id = fields.Char('Calendar ID', copy=False, help='Last Calendar ID who has been synchronized. If it is changed, we remove all links between GoogleID and Odoo Google Internal ID')
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_calendar_config_settings" model="ir.ui.view">
|
||||
<odoo>
|
||||
<record id="view_calendar_config_settings" model="ir.ui.view">
|
||||
<field name="name">Calendar_settings_grgrgrgt</field>
|
||||
<field name="model">base.config.settings</field>
|
||||
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
|
||||
@@ -12,9 +11,9 @@
|
||||
<field name="google_cal_sync"/>
|
||||
<div attrs="{'invisible':[('google_cal_sync','=',False)]}">
|
||||
<br/><h2>To setup the signin process with Google, first you have to perform the following steps</h2>
|
||||
<ul>
|
||||
<ul>
|
||||
<li> Connect on your google account and go to <a href='https://console.developers.google.com/' target='_blank'>https://console.developers.google.com/</a> </li>
|
||||
<li>
|
||||
<li>
|
||||
Click on <b>'Create a project...'</b> and enter a project name and change your id if you want. Don't forget to accept the Terms of Services
|
||||
<br/><br/><img src='/google_calendar/static/src/img/setup_01.png' class='calendar_img_tuto'/>
|
||||
</li>
|
||||
@@ -24,8 +23,8 @@
|
||||
<br/><br/> <img src='/google_calendar/static/src/img/setup_03.png' class='calendar_img_tuto'/>
|
||||
<br/> <img src='/google_calendar/static/src/img/setup_04.png' class='calendar_img_tuto'/>
|
||||
<br/> <img src='/google_calendar/static/src/img/setup_05.png' class='calendar_img_tuto'/>
|
||||
</li>
|
||||
<li>
|
||||
</li>
|
||||
<li>
|
||||
In the menu on left side, select the sub menu <b>'Credentials'</b> (from menu APIs and auth) and click on button <b>'Create new Client ID'</b>
|
||||
<br/><br/> <img src='/google_calendar/static/src/img/setup_06.png' class='calendar_img_tuto'/>
|
||||
</li>
|
||||
@@ -42,13 +41,13 @@
|
||||
<li>Once done, you will have the both informations (<b>Client ID</b> and <b>Client Secret</b>) that you need to insert in the 2 fields below!
|
||||
<br/><br/> <img src='/google_calendar/static/src/img/setup_08.png' class='calendar_img_tuto'/>
|
||||
</li>
|
||||
<a href="#" class="oe_link">Return at Top</a>
|
||||
<a href="#" class="oe_link">Return at Top</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="cal_client_id" string="Google Client ID"/>
|
||||
<field name="cal_client_id" nolabel="1" class="oe_inline"/>
|
||||
<field name="cal_client_id" nolabel="1" class="oe_inline"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="cal_client_secret" string="Google Client Secret"/>
|
||||
@@ -67,6 +66,10 @@
|
||||
<field name="target">inline</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_calendar_google_tech_config" name="API Credentials" parent="calendar.menu_calendar_configuration" groups="base.group_no_one" action="action_config_settings_google_calendar"/>
|
||||
</data>
|
||||
</openerp>
|
||||
<menuitem id="menu_calendar_google_tech_config"
|
||||
name="API Credentials"
|
||||
parent="calendar.menu_calendar_configuration"
|
||||
groups="base.group_no_one"
|
||||
action="action_config_settings_google_calendar"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record id="view_users_form" model="ir.ui.view">
|
||||
<field name="name">res.users.form</field>
|
||||
<field name="model">res.users</field>
|
||||
@@ -19,6 +19,6 @@
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
</odoo>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user