同步企业微信会议
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
'description': 'Experience the Ease of Booking Meeting Rooms with Real-Time Availability Display.',
|
||||
'category': 'Services/Room',
|
||||
'version': '1.0',
|
||||
'depends': ['mail', 'hr', 'documents'],
|
||||
'depends': ['mail', 'hr', 'documents', 'yuthon_wechat'],
|
||||
'data': [
|
||||
'data/message_template_views.xml',
|
||||
'views/room_booking_views.xml',
|
||||
|
||||
@@ -4,7 +4,7 @@ import qrcode
|
||||
import base64
|
||||
from io import BytesIO
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
|
||||
class RoomBooking(models.Model):
|
||||
@@ -34,6 +34,8 @@ class RoomBooking(models.Model):
|
||||
meeting_boss_document_ids = fields.One2many('boss.document', 'room_booking_id', string="董事会议文档")
|
||||
meeting_sing_ids = fields.One2many('room.meeting.sign', 'room_booking_id', string="签到详情")
|
||||
meeting_data = fields.Html(string="会议说明")
|
||||
wechat_meetingid = fields.Char("企业微信会议室ID")
|
||||
|
||||
|
||||
def meet_notice(self):
|
||||
if self.is_notice:
|
||||
@@ -111,13 +113,58 @@ class RoomBooking(models.Model):
|
||||
# Notify frontend views of new bookings
|
||||
for room, bookings in bookings.grouped("room_id").items():
|
||||
room._notify_booking_view("create", bookings)
|
||||
# wechat 创建会议
|
||||
for record in bookings:
|
||||
record.sync_wechat_room()
|
||||
return bookings
|
||||
|
||||
@api.model
|
||||
def sync_wechat_room(self):
|
||||
for record in self:
|
||||
admin_userid = record.organizer_id.oauth_uid
|
||||
title = record.name
|
||||
meeting_start = record.start_datetime.timestamp()
|
||||
meeting_duration = record.stop_datetime.timestamp() - record.start_datetime.timestamp()
|
||||
if not record.wechat_meetingid:
|
||||
create_result, create_data = self.sudo().env["wecom.apps"].sync_meeting_create(
|
||||
admin_userid=admin_userid,
|
||||
title=title,
|
||||
meeting_start=meeting_start,
|
||||
meeting_duration=meeting_duration,
|
||||
kwargs={
|
||||
"location": record.room_id.name,
|
||||
"invitees": {
|
||||
"userid": record.room_users_ids.oauth_uid
|
||||
},
|
||||
}
|
||||
)
|
||||
if create_result:
|
||||
record.wechat_meetingid = create_data.get("meetingid", "")
|
||||
if not create_result:
|
||||
raise UserError("同步企业微信会议失败:{0}".format(str(create_data)))
|
||||
if record.wechat_meetingid:
|
||||
update_result, update_data = self.sudo().env["wecom.apps"].sync_meeting_update(
|
||||
meetingid=record.wechat_meetingid,
|
||||
kwargs={
|
||||
"title": title,
|
||||
"meeting_start": meeting_start,
|
||||
"meeting_duration" :meeting_duration,
|
||||
"location": record.room_id.name,
|
||||
"invitees": {
|
||||
"userid": record.room_users_ids.oauth_uid
|
||||
},
|
||||
}
|
||||
)
|
||||
if not update_result:
|
||||
raise UserError("更新企业微信会议失败:{0}".format(str(update_data)))
|
||||
|
||||
def unlink(self):
|
||||
# Notify frontend of deleted bookings
|
||||
bookings_by_room = self.grouped("room_id")
|
||||
for room, bookings in bookings_by_room.items():
|
||||
room._notify_booking_view("delete", bookings)
|
||||
if self.wechat_meetingid:
|
||||
self.sudo().env["wecom.apps"].sync_meeting_cancel(meetingid=self.wechat_meetingid)
|
||||
return super(RoomBooking, self).unlink()
|
||||
|
||||
def write(self, vals):
|
||||
@@ -132,6 +179,7 @@ class RoomBooking(models.Model):
|
||||
elif {"name", "start_datetime", "stop_datetime"} & vals.keys():
|
||||
for room, bookings in bookings_by_room.items():
|
||||
room._notify_booking_view("update", bookings)
|
||||
self.sync_wechat_room()
|
||||
return res
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user