mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
base init v17, 很多只改了版号,没验证
This commit is contained in:
@@ -6,6 +6,7 @@ from odoo.http import request
|
||||
import requests
|
||||
import base64
|
||||
from io import BytesIO
|
||||
import uuid
|
||||
|
||||
from datetime import date, datetime, time
|
||||
import pytz
|
||||
@@ -104,9 +105,35 @@ class Base(models.AbstractModel):
|
||||
# 返回这个图片的base64编码
|
||||
return get_image_from_url(url)
|
||||
|
||||
@api.model
|
||||
def get_image_url2attachment(self, url, mimetype_list=None):
|
||||
# Todo: mimetype filter
|
||||
image, file_name = get_image_url2attachment(url)
|
||||
if image and file_name:
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
'datas': image,
|
||||
'name': file_name,
|
||||
})
|
||||
return attachment
|
||||
else:
|
||||
return False
|
||||
|
||||
@api.model
|
||||
def get_image_base642attachment(self, data):
|
||||
image, file_name = get_image_base642attachment(data)
|
||||
if image and file_name:
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
'datas': image,
|
||||
'name': file_name,
|
||||
})
|
||||
return attachment
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_ua_type(self):
|
||||
return get_ua_type()
|
||||
|
||||
|
||||
def get_image_from_url(url):
|
||||
if not url:
|
||||
return None
|
||||
@@ -116,7 +143,34 @@ def get_image_from_url(url):
|
||||
return None
|
||||
# 返回这个图片的base64编码
|
||||
return base64.b64encode(BytesIO(response.content).read())
|
||||
|
||||
|
||||
|
||||
def get_image_url2attachment(url):
|
||||
if not url:
|
||||
return None
|
||||
try:
|
||||
if url.startswith('//'):
|
||||
url = 'https:%s' % url
|
||||
response = requests.get(url, timeout=30)
|
||||
except Exception as e:
|
||||
return None, None
|
||||
# 返回这个图片的base64编码
|
||||
image = base64.b64encode(BytesIO(response.content).read())
|
||||
file_name = url.split('/')[-1]
|
||||
return image, file_name
|
||||
|
||||
|
||||
def get_image_base642attachment(data):
|
||||
if not data:
|
||||
return None
|
||||
try:
|
||||
image_data = data.split(',')[1]
|
||||
file_name = str(uuid.uuid4()) + '.png'
|
||||
return image_data, file_name
|
||||
except Exception as e:
|
||||
return None, None
|
||||
|
||||
|
||||
def get_ua_type():
|
||||
ua = request.httprequest.headers.get('User-Agent')
|
||||
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来
|
||||
|
||||
@@ -18,11 +18,12 @@ class IrMailServer(models.Model):
|
||||
email_to = message['To']
|
||||
|
||||
# 忽略掉无效email,避免被ban
|
||||
if email_to.find('no-reply@odooai.cn') != -1 or email_to.find('postmaster-odoo@odooai.cn') != -1:
|
||||
pass
|
||||
elif email_to.find('example.com') != -1 or email_to.find('@sunpop.cn') != -1 or email_to.find('@odooapp.cn') != -1:
|
||||
_logger.error(_("=================Email to ignore: %s") % email_to)
|
||||
raise AssertionError(_("Email to ignore: %s") % email_to)
|
||||
if email_to:
|
||||
if email_to.find('no-reply@odooai.cn') != -1 or email_to.find('postmaster-odoo@odooai.cn') != -1:
|
||||
pass
|
||||
elif email_to.find('example.com') != -1 or email_to.find('@sunpop.cn') != -1 or email_to.find('@odooapp.cn') != -1:
|
||||
_logger.error(_("=================Email to ignore: %s") % email_to)
|
||||
raise AssertionError(_("Email to ignore: %s") % email_to)
|
||||
|
||||
return super(IrMailServer, self).send_email(message, mail_server_id, smtp_server, smtp_port,
|
||||
smtp_user, smtp_password, smtp_encryption, smtp_debug,
|
||||
|
||||
@@ -23,7 +23,7 @@ def app_relaxng(view_type):
|
||||
relaxng_doc = etree.parse(frng)
|
||||
_relaxng_cache[view_type] = etree.RelaxNG(relaxng_doc)
|
||||
except Exception:
|
||||
_logger.error('Failed to load RelaxNG XML schema for views validation')
|
||||
_logger.error('You can Ignore this. Failed to load RelaxNG XML schema for views validation')
|
||||
_relaxng_cache[view_type] = None
|
||||
return _relaxng_cache[view_type]
|
||||
|
||||
|
||||
@@ -11,6 +11,14 @@ class MailMail(models.Model):
|
||||
# 猴子补丁模式,改默认发邮件逻辑
|
||||
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
|
||||
for m in self:
|
||||
if m.email_to and (m.email_to.find('example.com') != -1 or m.email_to.find('@odooai.cn') != -1 or m.email_to.find('@odooapp.cn') != -1):
|
||||
self = self - m
|
||||
email_to = m.email_to
|
||||
# 忽略掉无效email,避免被ban
|
||||
if email_to:
|
||||
if email_to.find('no-reply@odooai.cn') != -1 or email_to.find('postmaster-odoo@odooai.cn') != -1:
|
||||
pass
|
||||
elif email_to.find('example.com') != -1 or email_to.find('@sunpop.cn') != -1 or email_to.find('@odooapp.cn') != -1:
|
||||
_logger.error(_("=================Email to ignore: %s") % email_to)
|
||||
self = self - m
|
||||
if not self:
|
||||
return True
|
||||
return super(MailMail, self)._send(auto_commit, raise_exception, smtp_session)
|
||||
|
||||
@@ -10,4 +10,7 @@ class ResPartner(models.Model):
|
||||
def get_related_user_id(self):
|
||||
self.ensure_one()
|
||||
user = self.env['res.users'].sudo().with_context(active_test=False).search([('partner_id', '=', self.id)], limit=1)
|
||||
if not user and self.commercial_partner_id:
|
||||
user = self.env['res.users'].sudo().with_context(active_test=False).search([('partner_id', '=', self.commercial_partner_id.id)],
|
||||
limit=1)
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user