[IMP]: method do_accept,do_decline and get_day

bzr revid: aja@tinyerp.com-20131010132100-t2e9mwxv1phzk1zw
This commit is contained in:
ajay javiya (OpenERP) 2013-10-10 18:51:00 +05:30
parent 3fae74635b
commit ccfc03ccf5
5 changed files with 41 additions and 45 deletions

View File

@ -462,12 +462,13 @@ property or property parameter."),
if context is None:
context = {}
meeting_obj = self.pool.get('crm.meeting')
for vals in self.browse(cr, uid, ids, context=context):
meeting_id = meeting_obj.search(cr, uid, [('attendee_ids','=',vals.id)],context = context)
if meeting_id and vals.state != 'accepted':
meeting_obj.message_post(cr, uid, meeting_id, body=_(("%s has accepted invitation") % (vals.cn)), context=context)
self.write(cr, uid, vals.id, {'state': 'accepted'}, context)
return True
res = self.write(cr, uid, ids, {'state': 'accepted'}, context)
for attandee in self.browse(cr, uid, ids, context=context):
meeting_ids = meeting_obj.search(cr, uid, [('attendee_ids', '=', attandee.id)], context=context)
print "come herer ",meeting_ids , ids , attandee.id
meeting_obj.message_post(cr, uid, meeting_ids, body=_(("%s has accepted invitation") % (attandee.cn)), context=context)
return res
def do_decline(self, cr, uid, ids, context=None, *args):
"""
@ -482,11 +483,10 @@ property or property parameter."),
if context is None:
context = {}
meeting_obj = self.pool.get('crm.meeting')
for vals in self.browse(cr, uid, ids, context=context):
meeting_id = meeting_obj.search(cr, uid, [('attendee_ids','=',vals.id)], context=context)
if meeting_id and vals.state != 'declined':
meeting_obj.message_post(cr, uid, meeting_id, body=_(("%s has declined invitation") % (vals.cn)), context=context)
self.write(cr, uid, vals.id, {'state': 'declined'}, context)
res = self.write(cr, uid, ids, {'state': 'declined'}, context)
for attandee in self.browse(cr, uid, ids, context=context):
meeting_ids = meeting_obj.search(cr, uid, [('attendee_ids', '=', attandee.id)], context=context)
meeting_obj.message_post(cr, uid, meeting_ids, body=_(("%s has declined invitation") % (attandee.cn)), context=context)
return True
def create(self, cr, uid, vals, context=None):

View File

@ -14,7 +14,7 @@ class meetting_invitation(http.Controller):
registry = openerp.modules.registry.RegistryManager.get(db)
attendee_pool = registry.get('calendar.attendee')
with registry.cursor() as cr:
attendee_id = attendee_pool.search(cr, openerp.SUPERUSER_ID, [('access_token','=',token)])
attendee_id = attendee_pool.search(cr, openerp.SUPERUSER_ID, [('access_token','=',token),('state','!=', 'accepted')])
if attendee_id:
attendee_pool.do_accept(cr, openerp.SUPERUSER_ID, attendee_id)
return self.view(db, token, action, id, view='form')
@ -25,7 +25,7 @@ class meetting_invitation(http.Controller):
registry = openerp.modules.registry.RegistryManager.get(db)
attendee_pool = registry.get('calendar.attendee')
with registry.cursor() as cr:
attendee_id = attendee_pool.search(cr, openerp.SUPERUSER_ID, [('access_token','=',token)])
attendee_id = attendee_pool.search(cr, openerp.SUPERUSER_ID, [('access_token','=',token),('state','!=', 'declined')])
if attendee_id:
attendee_pool.do_decline(cr, openerp.SUPERUSER_ID, attendee_id)
return self.view(db, token, action, id, view='form')

View File

@ -22,7 +22,7 @@
import time
from openerp.osv import fields, osv
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
from openerp.tools.translate import _
from base_calendar import get_real_ids, base_calendar_id2real_id
from datetime import datetime, timedelta, date
@ -49,19 +49,20 @@ class crm_meeting(osv.Model):
_order = "id desc"
_inherit = ["calendar.event", "mail.thread", "ir.needaction_mixin"]
def _find_user_attendee(self, cr, uid, meeting_id, context=None):
def _find_user_attendee(self, cr, uid, meeting_ids, context=None):
attendee_pool = self.pool.get('calendar.attendee')
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
for attendee in self.browse(cr,uid,meeting_id,context).attendee_ids:
if user.partner_id.id == attendee.partner_id.id:
return attendee
for meeting_id in meeting_ids:
for attendee in self.browse(cr,uid,meeting_id,context).attendee_ids:
if user.partner_id.id == attendee.partner_id.id:
return attendee
return False
def _compute(self, cr, uid, ids, fields, arg, context=None):
res = {}
for meeting_id in ids:
res[meeting_id] = {}
attendee = self._find_user_attendee(cr, uid, meeting_id, context)
attendee = self._find_user_attendee(cr, uid, [meeting_id], context)
for field in fields:
if field == 'is_attendee':
res[meeting_id][field] = True if attendee else False
@ -195,22 +196,18 @@ class crm_meeting(osv.Model):
def do_decline(self, cr, uid, ids, context=None):
attendee_pool = self.pool.get('calendar.attendee')
for meeting_id in ids:
attendee = self._find_user_attendee(cr, uid, meeting_id, context)
if attendee:
if attendee.state != 'declined':
self.message_post(cr, uid, meeting_id, body=_(("%s has declined invitation") % (attendee.cn)), context=context)
attendee_pool.write(cr, uid, attendee.id, {'state': 'declined'}, context)
attendee = self._find_user_attendee(cr, uid, ids, context)
if attendee:
if attendee.state != 'declined':
attendee_pool.do_decline(cr, uid, [attendee.id], context=context)
return True
def do_accept(self, cr, uid, ids, context=None):
attendee_pool = self.pool.get('calendar.attendee')
for meeting_id in ids:
attendee = self._find_user_attendee(cr, uid, meeting_id, context)
if attendee:
if attendee.state != 'accepted':
self.message_post(cr, uid, meeting_id, body=_(("%s has accepted invitation") % (attendee.cn)), context=context)
attendee_pool.write(cr, uid, attendee.id, {'state': 'accepted'}, context)
attendee = self._find_user_attendee(cr, uid, ids, context)
if attendee:
if attendee.state != 'accepted':
attendee_pool.do_accept(cr, uid, [attendee.id], context=context)
return True
def get_attendee(self, cr, uid, meeting_id, context=None):
@ -225,16 +222,15 @@ class crm_meeting(osv.Model):
invitation['attendee'] = att
return invitation
def get_day(self, cr, uid, ids, time= None, context=None):
rec = self.browse(cr, uid, ids, context=context)[0]
date = datetime.strptime(rec.date,'%Y-%m-%d %H:%M:%S')
if time == 'day':
def get_day(self, cr, uid, ids, date, interval, context=None):
date = datetime.strptime(date, DEFAULT_SERVER_DATETIME_FORMAT)
if interval == 'day':
res = str(date.day)
elif time == 'month':
elif interval == 'month':
res = date.strftime('%B') + " " + str(date.year)
elif time == 'dayname':
elif interval == 'dayname':
res = date.strftime('%A')
elif time == 'time':
elif interval == 'time':
res = date.strftime('%I:%M %p')
return res

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<openerp>
<data>
<data noupdate="1">
<!-- CASE CATEGORY(categ_id) -->
@ -54,12 +54,12 @@
<table>
<tr>
<td>
<div style="border-top-left-radius:3px;border-top-right-radius:3px;font-size:12px;border-collapse:separate;text-align:center;font-weight:bold;color:#ffffff;width:130px;min-height: 18px;border-color:#ffffff;background:#8a89ba;padding-top: 4px;">${object.get_day('dayname')}</div>
<div style="border-top-left-radius:3px;border-top-right-radius:3px;font-size:12px;border-collapse:separate;text-align:center;font-weight:bold;color:#ffffff;width:130px;min-height: 18px;border-color:#ffffff;background:#8a89ba;padding-top: 4px;">${object.get_day(object.date, 'dayname')}</div>
<div style="font-size:48px;min-height:auto;font-weight:bold;text-align:center;color: #5F5F5F;background-color: #E1E2F8;width: 130px;">
${object.get_day('day')}
${object.get_day(object.date,'day')}
</div>
<div style='font-size:12px;text-align:center;font-weight:bold;color:#ffffff;background-color:#8a89ba'>${object.get_day('month')}</div>
<div style="border-collapse:separate;color:#8a89ba;text-align:center;width: 128px;font-size:12px;border-bottom-right-radius:3px;font-weight:bold;border:1px solid;border-bottom-left-radius:3px;">${object.get_day('time')}</div>
<div style='font-size:12px;text-align:center;font-weight:bold;color:#ffffff;background-color:#8a89ba'>${object.get_day(object.date, 'month')}</div>
<div style="border-collapse:separate;color:#8a89ba;text-align:center;width: 128px;font-size:12px;border-bottom-right-radius:3px;font-weight:bold;border:1px solid;border-bottom-left-radius:3px;">${object.get_day(object.date, 'time')}</div>
</td>
<td>
<table cellspacing="0" cellpadding="0" border="0" style="margin-top: 15px; margin-left: 10px;font-size: 16px;">

View File

@ -62,8 +62,8 @@ class calendar_attendee(osv.osv):
def create(self, cr, uid, vals, context=None):
user_pool = self.pool.get('res.users')
if vals.get('partner_id'):
users = user_pool.search_read(cr, uid, [('partner_id','=', vals.get('partner_id'))],['employee_ids'], context=context)
partner_id = vals.get('partner_id')
users = user_pool.search_read(cr, uid, [('partner_id','=', partner_id)],['employee_ids'], context=context)
for user in users:
if user['employee_ids']:
vals['state'] = 'accepted'