mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
add base64 img to attachment
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': "odooAi Common Util and Tools",
|
'name': "odooAi Common Util and Tools",
|
||||||
'version': '16.23.10.27',
|
'version': '16.23.10.30',
|
||||||
'author': 'odooai.cn',
|
'author': 'odooai.cn',
|
||||||
'category': 'Base',
|
'category': 'Base',
|
||||||
'website': 'https://www.odooai.cn',
|
'website': 'https://www.odooai.cn',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from odoo.http import request
|
|||||||
import requests
|
import requests
|
||||||
import base64
|
import base64
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime, time
|
from datetime import date, datetime, time
|
||||||
import pytz
|
import pytz
|
||||||
@@ -117,6 +118,18 @@ class Base(models.AbstractModel):
|
|||||||
else:
|
else:
|
||||||
return False
|
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):
|
def get_ua_type(self):
|
||||||
return get_ua_type()
|
return get_ua_type()
|
||||||
|
|
||||||
@@ -144,7 +157,18 @@ def get_image_url2attachment(url):
|
|||||||
file_name = url.split('/')[-1]
|
file_name = url.split('/')[-1]
|
||||||
return image, file_name
|
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():
|
def get_ua_type():
|
||||||
ua = request.httprequest.headers.get('User-Agent')
|
ua = request.httprequest.headers.get('User-Agent')
|
||||||
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来
|
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来
|
||||||
|
|||||||
Reference in New Issue
Block a user