[REF] Ref to remove warning about missing user_id in calendar.attendee
bzr revid: jke@openerp.com-20131211130635-hjrb306zrph4dcg5
This commit is contained in:
parent
9c0c62be6d
commit
ce8a4968de
|
@ -115,7 +115,7 @@ class calendar_attendee(osv.osv):
|
|||
return result
|
||||
|
||||
_columns = {
|
||||
'state': fields.selection([('needs-action', 'Needs Action'),('tentative', 'Uncertain'),('declined', 'Declined'),('accepted', 'Accepted')], 'Status', readonly=True, help="Status of the attendee's participation"),
|
||||
'state': fields.selection([('needsAction', 'Needs Action'),('tentative', 'Uncertain'),('declined', 'Declined'),('accepted', 'Accepted')], 'Status', readonly=True, help="Status of the attendee's participation"),
|
||||
'cn': fields.function(_compute_data, string='Common name', type="char", size=124, multi='cn', store=True),
|
||||
'dir': fields.char('URI Reference', size=124, help="Reference to the URI that points to the directory information corresponding to the attendee."),
|
||||
'partner_id': fields.many2one('res.partner', 'Contact',readonly="True"),
|
||||
|
@ -127,7 +127,7 @@ class calendar_attendee(osv.osv):
|
|||
'event_id': fields.many2one('crm.meeting','Meeting linked'),
|
||||
}
|
||||
_defaults = {
|
||||
'state': 'needs-action',
|
||||
'state': 'needsAction',
|
||||
}
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
|
@ -220,7 +220,7 @@ class calendar_attendee(osv.osv):
|
|||
template_pool = self.pool.get('email.template')
|
||||
local_context = context.copy()
|
||||
color = {
|
||||
'needs-action' : 'grey',
|
||||
'needsAction' : 'grey',
|
||||
'accepted' :'green',
|
||||
'tentative' :'#FFFF00',
|
||||
'declined':'red'
|
||||
|
@ -297,8 +297,7 @@ class calendar_attendee(osv.osv):
|
|||
meeting_obj = self.pool.get('crm.meeting')
|
||||
res = self.write(cr, uid, ids, {'state': 'accepted'}, context)
|
||||
for attendee in self.browse(cr, uid, ids, context=context):
|
||||
if attendee.ref:
|
||||
meeting_obj.message_post(cr, uid, attendee.event_id.id, body=_(("%s has accepted invitation") % (attendee.cn)),subtype="base_calendar.subtype_invitation", context=context)
|
||||
meeting_obj.message_post(cr, uid, attendee.event_id.id, body=_(("%s has accepted invitation") % (attendee.cn)),subtype="base_calendar.subtype_invitation", context=context)
|
||||
|
||||
return res
|
||||
|
||||
|
@ -572,7 +571,7 @@ class calendar_alarm_manager(osv.osv):
|
|||
template_pool = self.pool.get('email.template')
|
||||
local_context = context and context.copy() or {}
|
||||
color = {
|
||||
'needs-action' : 'grey',
|
||||
'needsAction' : 'grey',
|
||||
'accepted' :'green',
|
||||
'tentative' :'#FFFF00',
|
||||
'declined':'red'
|
||||
|
@ -849,7 +848,7 @@ class crm_meeting(osv.Model):
|
|||
if field == 'is_attendee':
|
||||
res[meeting_id][field] = True if attendee else False
|
||||
elif field == 'attendee_status':
|
||||
res[meeting_id][field] = attendee.state if attendee else 'needs-action'
|
||||
res[meeting_id][field] = attendee.state if attendee else 'needsAction'
|
||||
elif field == 'display_time':
|
||||
res[meeting_id][field] = self._get_display_time(cr, uid, meeting_id, context=context)
|
||||
return res
|
||||
|
@ -1082,7 +1081,6 @@ class crm_meeting(osv.Model):
|
|||
access_token = self.new_invitation_token(cr, uid, event, partner.id)
|
||||
att_id = self.pool.get('calendar.attendee').create(cr, uid, {
|
||||
'partner_id': partner.id,
|
||||
'user_id': partner.user_ids and partner.user_ids[0].id or False,
|
||||
'event_id': event.id,
|
||||
'access_token': access_token,
|
||||
'email': partner.email,
|
||||
|
|
|
@ -138,9 +138,9 @@
|
|||
<field name="state" />
|
||||
<field name="email" widget="email"/>
|
||||
|
||||
<button name="do_tentative" states="needs-action,declined,accepted" string="Uncertain" type="object" icon="terp-crm" />
|
||||
<button name="do_accept" string="Accept" states="needs-action,tentative,declined" type="object" icon="gtk-apply"/>
|
||||
<button name="do_decline" string="Decline" states="needs-action,tentative,accepted" type="object" icon="gtk-cancel"/>
|
||||
<button name="do_tentative" states="needsAction,declined,accepted" string="Uncertain" type="object" icon="terp-crm" />
|
||||
<button name="do_accept" string="Accept" states="needsAction,tentative,declined" type="object" icon="gtk-apply"/>
|
||||
<button name="do_decline" string="Decline" states="needsAction,tentative,accepted" type="object" icon="gtk-cancel"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
margin-bottom : -4px;
|
||||
display : inline-block;
|
||||
}
|
||||
.openerp .needs-action , .tentative,.text-core .text-tag .custom-edit, .text-core .text-tag .tentative {
|
||||
.openerp .needsAction , .tentative,.text-core .text-tag .custom-edit, .text-core .text-tag .tentative {
|
||||
background : url(/web/static/src/img/icons/gtk-normal.png) no-repeat;
|
||||
background-size : 11px 11px;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<div class="oe_right"><b><t t-esc="invitation['current_attendee'].cn"/> (<t t-esc="invitation['current_attendee'].email"/>)</b></div>
|
||||
<div class="oe_left"><img class="cal_inline cal_image" t-attf-src="data:image/png;base64,#{invitation['logo']}"/><p class="cal_tag cal_inline">Calendar</p></div>
|
||||
<div class="invitation_block">
|
||||
<t t-if="invitation['current_attendee'].state != 'needs-action'">
|
||||
<t t-if="invitation['current_attendee'].state != 'needsAction'">
|
||||
<div class="event_status"><a t-attf-class="attendee_#{invitation['current_attendee'].state}"><b t-if="invitation['current_attendee'].state == 'accepted'">Yes I'm going.</b><b t-if="invitation['current_attendee'].state == 'declined'">No I'm not going.</b></a></div>
|
||||
</t>
|
||||
<div class="cal_meeting"><t t-esc="invitation['meeting'].event"/></div>
|
||||
|
|
|
@ -4,7 +4,6 @@ import openerp
|
|||
import openerp.addons.web.http as http
|
||||
from openerp.addons.web.http import request
|
||||
import openerp.addons.web.controllers.main as webmain
|
||||
import json
|
||||
from openerp.addons.web.http import SessionExpiredException
|
||||
from werkzeug.exceptions import BadRequest
|
||||
import werkzeug.utils
|
||||
|
@ -13,29 +12,41 @@ class google_auth(http.Controller):
|
|||
|
||||
@http.route('/googleauth/oauth2callback', type='http', auth="none")
|
||||
def oauth2callback(self, **kw):
|
||||
""" This route/function is called by Google when user Accept/Refuse the consent of Google """
|
||||
|
||||
state = simplejson.loads(kw['state'])
|
||||
|
||||
dbname = state.get('d')
|
||||
service = state.get('s')
|
||||
url_return = state.get('from')
|
||||
|
||||
registry = openerp.modules.registry.RegistryManager.get(dbname)
|
||||
with registry.cursor() as cr:
|
||||
#TODO CHECK IF REQUEST OK
|
||||
registry.get('google.calendar').set_all_tokens(cr,request.session.uid,kw['code'])
|
||||
#registry.get('google.calendar').set_primary_id(cr,request.session.uid)
|
||||
if kw.get('code'):
|
||||
registry.get('google.%s' % service).set_all_tokens(cr,request.session.uid,kw['code'])
|
||||
return werkzeug.utils.redirect(url_return)
|
||||
|
||||
return werkzeug.utils.redirect(url_return)
|
||||
|
||||
#TODO - Display error at customer if url contains ?Error=
|
||||
elif kw.get('error'):
|
||||
return werkzeug.utils.redirect("%s%s%s" % (url_return ,"?Error=" , kw.get('error')))
|
||||
else:
|
||||
return werkzeug.utils.redirect("%s%s%s" % (url_return ,"?Error=Unknown_error"))
|
||||
|
||||
|
||||
@http.route('/web_calendar_sync/sync_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
|
||||
|
||||
Function return a dictionary with the status : NeedConfigFromAdmin, NeedAuth, NeedRefresh, NoNewEventFromGoogle, SUCCESS if not crm meeting
|
||||
The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example
|
||||
|
||||
"""
|
||||
|
||||
if model == 'crm.meeting':
|
||||
gs_obj = request.registry.get('google.service')
|
||||
gc_obj = request.registry.get('google.calendar')
|
||||
|
||||
#We check that admin has already configure api for google synchronization !
|
||||
# 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('LocalContext'))
|
||||
|
||||
if not client_id or client_id == '':
|
||||
|
@ -44,7 +55,7 @@ class google_auth(http.Controller):
|
|||
"url" : ''
|
||||
}
|
||||
|
||||
#We check that user has already accepted openerp to access his calendar !
|
||||
# Checking that user have already accepted OpenERP to access his calendar !
|
||||
if gc_obj.need_authorize(request.cr, request.uid,context=kw.get('LocalContext')):
|
||||
url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'),context=kw.get('LocalContext'))
|
||||
return {
|
||||
|
@ -52,27 +63,9 @@ class google_auth(http.Controller):
|
|||
"url" : url
|
||||
}
|
||||
|
||||
#We launch the synchronization
|
||||
result = gc_obj.synchronize_events(request.cr, request.uid, [], kw.get('LocalContext'))
|
||||
return result
|
||||
else:
|
||||
calendar_info = {
|
||||
'field_data':{},
|
||||
'date_start':arch['attrs'].get('date_start'),
|
||||
'date_stop':arch['attrs'].get('date_stop'),
|
||||
'calendar_string':arch['attrs'].get('string'),
|
||||
'model':model
|
||||
}
|
||||
for field, data in fields.items():
|
||||
calendar_info['field_data'][field] = {
|
||||
'type': data.get('type'),
|
||||
'string': data.get('string')
|
||||
}
|
||||
|
||||
print "@@@@@@@@@@@@@@@@@ Is still used !!!!"
|
||||
gc_obj.synchronize_calendar(request.cr, request.uid, calendar_info, kw.get('LocalContext'))
|
||||
|
||||
|
||||
# If App authorized, and user access accepted, We launch the synchronization
|
||||
return gc_obj.synchronize_events(request.cr, request.uid, [], kw.get('LocalContext'))
|
||||
|
||||
return { "status" : "SUCCESS" }
|
||||
|
||||
|
||||
|
|
|
@ -65,8 +65,9 @@ class google_service(osv.osv_memory):
|
|||
|
||||
#If no scope is passed, we use service by default to get a default scope
|
||||
|
||||
|
||||
def _get_authorize_uri(self, cr, uid, from_url, service, scope = False, context=None):
|
||||
|
||||
""" This method return the url needed to allow this instance of OpenErp to access to the scope of gmail specified as parameters """
|
||||
state_obj = {}
|
||||
state_obj['d'] = cr.dbname
|
||||
state_obj['s'] = service
|
||||
|
@ -88,7 +89,7 @@ class google_service(osv.osv_memory):
|
|||
uri = self.get_uri_oauth(a='auth') + "?%s" % urllib.urlencode(params)
|
||||
return uri
|
||||
|
||||
def _get_google_token_json(self, cr, uid, authorize_code, service, context=None): #exchange_AUTHORIZATION vs Token (service = calendar)
|
||||
def _get_google_token_json(self, cr, uid, authorize_code, service, context=None):
|
||||
res = False
|
||||
base_url = self.get_base_url(cr, uid, context)
|
||||
client_id = self.get_client_id(cr, uid, service, context)
|
||||
|
@ -107,13 +108,13 @@ class google_service(osv.osv_memory):
|
|||
try:
|
||||
data = urllib.urlencode(params)
|
||||
req = urllib2.Request(self.get_uri_oauth(a='token'), data, headers)
|
||||
|
||||
content = urllib2.urlopen(req).read()
|
||||
res = simplejson.loads(content)
|
||||
|
||||
except urllib2.HTTPError,e:
|
||||
print e
|
||||
raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during your token generation. Maybe your Authorization Code is invalid or already expired"), context=context)
|
||||
|
||||
raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during your token generation. Maybe your Authorization Code is invalid"), context=context)
|
||||
return res
|
||||
|
||||
def _refresh_google_token_json(self, cr, uid, refresh_token, service, context=None): #exchange_AUTHORIZATION vs Token (service = calendar)
|
||||
|
@ -163,11 +164,13 @@ class google_service(osv.osv_memory):
|
|||
else:
|
||||
raise ('Method not supported [%s] not in [GET, POST, PUT or PATCH]!' % (type))
|
||||
req.get_method = lambda: type.upper()
|
||||
req.add_header('Pragma', 'no-cache')
|
||||
|
||||
request = urllib2.urlopen(req)
|
||||
|
||||
if request.getcode() == 204:
|
||||
if request.getcode() == 204: #No content returned, (ex: POST calendar/event/clear)
|
||||
res = True
|
||||
elif request.getcode() == 404: #Page not found
|
||||
res = False
|
||||
else:
|
||||
content=request.read()
|
||||
res = simplejson.loads(content)
|
||||
|
@ -177,7 +180,7 @@ class google_service(osv.osv_memory):
|
|||
print "=========="
|
||||
except urllib2.HTTPError,e:
|
||||
print "ERROR CATCHED : ",e.read()
|
||||
raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during your token generation. Maybe your Authorization Code is invalid or already expired"), context=context)
|
||||
raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong with your request to google"), context=context)
|
||||
|
||||
return res
|
||||
|
||||
|
@ -190,7 +193,7 @@ class google_service(osv.osv_memory):
|
|||
def get_client_secret(self, cr, uid, service, context=None):
|
||||
return self.pool.get('ir.config_parameter').get_param(cr, uid, 'google_%s_client_secret' % (service,),context=context).strip()
|
||||
|
||||
def get_uri_oauth(self,a=''): #a = optionnal action
|
||||
def get_uri_oauth(self,a=''): #a = optional action
|
||||
return "https://accounts.google.com/o/oauth2/%s" % (a,)
|
||||
|
||||
def get_uri_api(self):
|
||||
|
|
Binary file not shown.
|
@ -38,19 +38,6 @@ from openerp.osv import fields, osv
|
|||
from openerp.osv import osv
|
||||
|
||||
|
||||
google_state_mapping = {
|
||||
'needs-action':'needsAction',
|
||||
'declined': 'declined',
|
||||
'tentative':'tentative',
|
||||
'accepted':'accepted',
|
||||
'delegated':'declined',
|
||||
}
|
||||
oe_state_mapping = {
|
||||
'needsAction':'needs-action',
|
||||
'declined': 'declined',
|
||||
'tentative':'tentative',
|
||||
'accepted':'accepted',
|
||||
}
|
||||
|
||||
class google_calendar(osv.osv):
|
||||
_name = 'google.calendar'
|
||||
|
@ -71,14 +58,12 @@ class google_calendar(osv.osv):
|
|||
end_date = fields.datetime.context_timestamp(cr, uid, datetime.strptime(event.date_deadline, tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context).isoformat('T')
|
||||
type = 'dateTime'
|
||||
attendee_list = []
|
||||
|
||||
print "att for event %s : %s" % (event.id,event.attendee_ids)
|
||||
|
||||
for attendee in event.attendee_ids:
|
||||
attendee_list.append({
|
||||
'email':attendee.email or 'NoEmail@mail.com',
|
||||
'displayName':attendee.partner_id.name,
|
||||
'responseStatus':google_state_mapping.get(attendee.state, 'needsAction'),
|
||||
'responseStatus':attendee.state or 'needsAction',
|
||||
})
|
||||
data = {
|
||||
"summary": event.name or '',
|
||||
|
@ -112,10 +97,8 @@ class google_calendar(osv.osv):
|
|||
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
data_json = simplejson.dumps(data)
|
||||
|
||||
response = gs_pool._do_request(cr, uid, url, data_json, headers, type='POST', context=context)
|
||||
#TODO Check response result
|
||||
|
||||
return response
|
||||
return gs_pool._do_request(cr, uid, url, data_json, headers, type='POST', context=context)
|
||||
|
||||
|
||||
def delete_an_event(self, cr, uid,event_id, context=None):
|
||||
gs_pool = self.pool.get('google.service')
|
||||
|
@ -128,7 +111,6 @@ class google_calendar(osv.osv):
|
|||
url = "/calendar/v3/calendars/%s/events/%s" % ('primary',event_id)
|
||||
|
||||
response = gs_pool._do_request(cr, uid, url, params, headers, type='DELETE', context=context)
|
||||
print "@@@RESPONSE",response
|
||||
return response
|
||||
|
||||
def get_event_dict(self,cr,uid,token=False,nextPageToken=False,context=None):
|
||||
|
@ -243,7 +225,7 @@ class google_calendar(osv.osv):
|
|||
if type == "write":
|
||||
for oe_attendee in event['attendee_ids']:
|
||||
if oe_attendee.email == google_attendee['email']:
|
||||
calendar_attendee_obj.write(cr, uid,[oe_attendee.id] ,{'state' : oe_state_mapping[google_attendee['responseStatus']]},context=context)
|
||||
calendar_attendee_obj.write(cr, uid,[oe_attendee.id] ,{'state' : google_attendee['responseStatus']},context=context)
|
||||
google_attendee['found'] = True
|
||||
continue
|
||||
|
||||
|
@ -255,7 +237,7 @@ class google_calendar(osv.osv):
|
|||
attendee = res_partner_obj.read(cr, uid, attendee_id[0], ['email'], context=context)
|
||||
partner_record.append((4, attendee.get('id')))
|
||||
attendee['partner_id'] = attendee.pop('id')
|
||||
attendee['state'] = oe_state_mapping[google_attendee['responseStatus']]
|
||||
attendee['state'] = google_attendee['responseStatus']
|
||||
attendee_record.append((0, 0, attendee))
|
||||
UTC = pytz.timezone('UTC')
|
||||
if single_event_dict.get('start') and single_event_dict.get('end'): # If not cancelled
|
||||
|
|
Binary file not shown.
|
@ -42,8 +42,8 @@ openerp.google_calendar = function(instance) {
|
|||
else if (o.status == "NeedRefresh"){
|
||||
self.$calendar.fullCalendar('refetchEvents');
|
||||
}
|
||||
$('div.oe_cal_sync_button').prop('disabled',false);
|
||||
});
|
||||
|
||||
}).always(function(o) { $('div.oe_cal_sync_button').prop('disabled',false); });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue