fix: publish items

- Pass image data as a json
- ignore duplicates while creating Hub Tracked Item
This commit is contained in:
Faris Ansari
2018-08-21 19:14:44 +05:30
parent d29a3b3567
commit ff189b6853
5 changed files with 21 additions and 36 deletions

View File

@@ -1,19 +1,26 @@
import frappe, io, base64, urllib, os
import frappe, io, base64, urllib, os, json
from frappe.utils.file_manager import get_file_path
def pre_process(doc):
# file_path = doc.image
# file_name = os.path.basename(file_path)
file_path = doc.image
file_name = os.path.basename(file_path)
# if file_path.startswith('http'):
# url = file_path
# file_path = os.path.join('/tmp', file_name)
# urllib.urlretrieve(url, file_path)
if file_path.startswith('http'):
url = file_path
file_path = os.path.join('/tmp', file_name)
urllib.urlretrieve(url, file_path)
else:
file_path = os.path.abspath(get_file_path(file_path))
# with io.open(file_path, 'rb') as f:
# doc.image = base64.b64encode(f.read())
# doc.image_file_name = file_name
try:
with io.open(file_path, 'rb') as f:
doc.image = json.dumps({
'file_name': file_name,
'base64': base64.b64encode(f.read())
})
except Exception as e:
frappe.log_error(title='Hub Sync Error')
cached_details = frappe.get_doc('Hub Tracked Item', doc.item_code)