Skip to content

Commit

Permalink
完成 撤回消息和重新发送消息功能
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbow-studio-solution committed Feb 2, 2022
1 parent d072f24 commit fcc6017
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 31 deletions.
35 changes: 20 additions & 15 deletions wecom_message/i18n/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-01 09:33+0000\n"
"PO-Revision-Date: 2022-02-01 17:46+0800\n"
"POT-Creation-Date: 2022-02-02 06:57+0000\n"
"PO-Revision-Date: 2022-02-02 14:59+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_CN\n"
Expand Down Expand Up @@ -141,11 +141,6 @@ msgstr "绑定应用"
msgid "Cancel"
msgstr "取消"

#. module: wecom_message
#: model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_tree
msgid "Recall message"
msgstr "撤回消息"

#. module: wecom_message
#: code:addons/wecom/wecom_message/models/res_users.py:0 code:addons/wecom_message/models/res_users.py:0
#, python-format
Expand Down Expand Up @@ -225,11 +220,6 @@ msgstr "显示名称"
msgid "Dynamic Placeholder Generator"
msgstr "动态定位符生成器"

#. module: wecom_message
#: model:ir.ui.menu,name:wecom_message.menu_wecom_email_message
msgid "EMail Message"
msgstr "EMail消息"

#. module: wecom_message
#: model:ir.actions.act_window,name:wecom_message.action_view_wecom_mail
msgid "EMail Messages"
Expand Down Expand Up @@ -396,8 +386,8 @@ msgid "Media file id"
msgstr "媒体文件Id"

#. module: wecom_message
#: model:ir.model,name:wecom_message.model_mail_message model:ir.ui.menu,name:wecom_message.menu_wecom_message_root model:wecom.app.subtype,name:wecom_message.wecom_app_subtype_message
#: model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_search
#: model:ir.model,name:wecom_message.model_mail_message model:ir.ui.menu,name:wecom_message.menu_wecom_message_message model:ir.ui.menu,name:wecom_message.menu_wecom_message_root
#: model:wecom.app.subtype,name:wecom_message.wecom_app_subtype_message model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_search
msgid "Message"
msgstr "消息"

Expand Down Expand Up @@ -534,6 +524,16 @@ msgstr "预览"
msgid "QWeb template %s not found when sending template %s. Sending without layouting."
msgstr "发送模板 %s 时找不到QWeb模板 %s。未进行布局发送。"

#. module: wecom_message
#: model:ir.model.fields.selection,name:wecom_message.selection__mail_mail__state__wecom_recall
msgid "Recall"
msgstr "撤回"

#. module: wecom_message
#: model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_tree
msgid "Recall Message"
msgstr "撤回消息"

#. module: wecom_message
#: model:ir.model.fields,field_description:wecom_message.field_res_config_settings__message_app_callback_service_ids
msgid "Receive event service"
Expand All @@ -551,7 +551,12 @@ msgid "Received"
msgstr "已接收"

#. module: wecom_message
#: model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_form model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_tree
#: model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_tree
msgid "Resend Message"
msgstr "重发消息"

#. module: wecom_message
#: model_terms:ir.ui.view,arch_db:wecom_message.view_wecom_mail_form
msgid "Retry"
msgstr "重试"

Expand Down
92 changes: 79 additions & 13 deletions wecom_message/models/mail_mail.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# -*- coding: utf-8 -*-

import logging
import ast
import base64
import datetime
import logging
import psycopg2
import smtplib
import re
from odoo import _, api, fields, models
from odoo import tools
from odoo.addons.base.models.ir_mail_server import MailDeliveryException
Expand Down Expand Up @@ -40,7 +34,7 @@ class MailMail(models.Model):
)
message_to_tag = fields.Char(string="To Tags", help="Message recipients (tags)",)
use_templates = fields.Boolean("Is template message", default=False)
templates_id = fields.Many2one("wecom.message.template", string="Message template")
templates_id = fields.Many2one("mail.template", string="Message template")
msgtype = fields.Selection(
[
("text", "Text message"),
Expand Down Expand Up @@ -98,7 +92,12 @@ class MailMail(models.Model):
# copy=False,
# )

state = fields.Selection(selection_add=[("wecom_exception", "Send exception")])
state = fields.Selection(
selection_add=[
("wecom_exception", "Send exception"),
("wecom_recall", "Recall"),
]
)

# ------------------------------------------------------
# mail_mail formatting, tools and send mechanism
Expand All @@ -109,12 +108,79 @@ def recall_message(self):
"""
撤回应用消息
"""
# 获取公司
company = self.env[self.model].browse(self.res_id).company_id
if not company:
company = self.env.company
if self.is_wecom_message:
# 获取公司
company = self.env[self.model].browse(self.res_id).company_id
if not company:
company = self.env.company

try:
wecomapi = self.env["wecom.service_api"].InitServiceApi(
company.corpid, company.message_app_id.secret
)
res = wecomapi.httpCall(
self.env["wecom.service_api_list"].get_server_api_call(
"MESSAGE_RECALL"
),
{"msgid": self.message_id},
)
print(res)

print(company)
except ApiException as e:
return self.env["wecomapi.tools.action"].ApiExceptionDialog(
e, raise_exception=True
)
else:
if res["errcode"] == 0:
return self.write({"state": "wecom_recall", "message_id": None})

def resend_message(self):
"""
重新发送应用消息
"""
if self.is_wecom_message:
# 获取公司
company = self.env[self.model].browse(self.res_id).company_id
if not company:
company = self.env.company

try:
wecomapi = self.env["wecom.service_api"].InitServiceApi(
company.corpid, company.message_app_id.secret
)
msg = self.env["wecom.message.api"].build_message(
msgtype=self.msgtype,
touser=self.message_to_user,
toparty=self.message_to_party,
totag=self.message_to_tag,
subject=self.subject,
media_id=self.media_id,
description=self.description,
author_id=self.author_id,
body_html=self.body_html,
body_json=self.body_json,
body_markdown=self.body_markdown,
safe=self.safe,
enable_id_trans=self.enable_id_trans,
enable_duplicate_check=self.enable_duplicate_check,
duplicate_check_interval=self.duplicate_check_interval,
company=company,
)
del msg["company"]
res = wecomapi.httpCall(
self.env["wecom.service_api_list"].get_server_api_call(
"MESSAGE_SEND"
),
msg,
)

except ApiException as e:
return self.env["wecomapi.tools.action"].ApiExceptionDialog(
e, raise_exception=True
)
else:
if res["errcode"] == 0:
return self.write({"state": "sent", "message_id": res["msgid"]})

def _send_prepare_body(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion wecom_message/views/mail_mail_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@

<button name="send_wecom_message" string="Send Now" type="object" icon="fa-paper-plane" states='outgoing'/>

<button name="mark_outgoing" string="Retry" type="object" icon="fa-repeat" states='wecom_exception,cancel'/>
<button name="recall_message" string="Recall Message" type="object" icon="fa-times-circle" states='sent'/>

<button name="resend_message" string="Resend Message" type="object" icon="fa-repeat" states='wecom_exception,wecom_recall'/>
</tree>
</field>
</record>
Expand Down
4 changes: 2 additions & 2 deletions wecom_message/views/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<menuitem id="menu_wecom_message_records" name="Send Records" parent="menu_wecom_message_root" sequence="1"/>

<!-- 1.消息 -->
<!-- <menuitem id="menu_wecom_message_message" name="Message" parent="menu_wecom_message_records" action="action_view_wecom_message_message" groups="base.group_erp_manager" sequence="1"/> -->
<menuitem id="menu_wecom_message_message" name="Message" parent="menu_wecom_message_records" action="action_view_wecom_mail" groups="base.group_erp_manager" sequence="1"/>
<!-- 2.跟踪值 -->
<!-- <menuitem name="Tracking Values" id="menu_wecom_discuss_tracking_value" parent="menu_wecom_discuss" action="mail.action_view_mail_tracking_value" sequence="2"/> -->
<!-- 3.活动 -->
Expand All @@ -27,7 +27,7 @@
<menuitem id="menu_wecom_message_settings" name="Settings" parent="menu_wecom_message_root" sequence="2"/>

<!-- 1.邮件 -->
<menuitem id="menu_wecom_email_message" name="EMail Message" parent="menu_wecom_message_settings" action="action_view_wecom_mail" groups="base.group_erp_manager" sequence="1"/>
<!-- <menuitem id="menu_wecom_email_message" name="EMail Message" parent="menu_wecom_message_settings" action="action_view_wecom_mail" groups="base.group_erp_manager" sequence="1"/> -->

<!-- 2.模板 -->
<menuitem id="menu_wecom_message_template" name="Template" parent="menu_wecom_message_settings" groups="base.group_erp_manager" action="action_wecom_message_template_tree_all" sequence="2"/>
Expand Down

0 comments on commit fcc6017

Please sign in to comment.