mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
fix: publish items
- Pass image data as a json - ignore duplicates while creating Hub Tracked Item
This commit is contained in:
@@ -56,7 +56,7 @@ def publish_selected_items(items_to_publish):
|
|||||||
'item_code': item_code,
|
'item_code': item_code,
|
||||||
'hub_category': item.get('hub_category'),
|
'hub_category': item.get('hub_category'),
|
||||||
'image_list': item.get('image_list')
|
'image_list': item.get('image_list')
|
||||||
}).insert()
|
}).insert(ignore_if_duplicate=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hub_settings = frappe.get_doc('Hub Settings')
|
hub_settings = frappe.get_doc('Hub Settings')
|
||||||
|
|||||||
@@ -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):
|
def pre_process(doc):
|
||||||
|
|
||||||
# file_path = doc.image
|
file_path = doc.image
|
||||||
# file_name = os.path.basename(file_path)
|
file_name = os.path.basename(file_path)
|
||||||
|
|
||||||
# if file_path.startswith('http'):
|
if file_path.startswith('http'):
|
||||||
# url = file_path
|
url = file_path
|
||||||
# file_path = os.path.join('/tmp', file_name)
|
file_path = os.path.join('/tmp', file_name)
|
||||||
# urllib.urlretrieve(url, file_path)
|
urllib.urlretrieve(url, file_path)
|
||||||
|
else:
|
||||||
|
file_path = os.path.abspath(get_file_path(file_path))
|
||||||
|
|
||||||
# with io.open(file_path, 'rb') as f:
|
try:
|
||||||
# doc.image = base64.b64encode(f.read())
|
with io.open(file_path, 'rb') as f:
|
||||||
|
doc.image = json.dumps({
|
||||||
# doc.image_file_name = file_name
|
'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)
|
cached_details = frappe.get_doc('Hub Tracked Item', doc.item_code)
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class HubSettings(Document):
|
|||||||
def create_hub_connector(self, message):
|
def create_hub_connector(self, message):
|
||||||
if frappe.db.exists('Data Migration Connector', 'Hub Connector'):
|
if frappe.db.exists('Data Migration Connector', 'Hub Connector'):
|
||||||
hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector')
|
hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector')
|
||||||
|
hub_connector.hostname = self.get_hub_url()
|
||||||
hub_connector.username = message['email']
|
hub_connector.username = message['email']
|
||||||
hub_connector.password = message['password']
|
hub_connector.password = message['password']
|
||||||
hub_connector.save()
|
hub_connector.save()
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
// rename this file from _test_[name] to test_[name] to activate
|
|
||||||
// and remove above this line
|
|
||||||
|
|
||||||
QUnit.test("test: Hub Tracked Item", function (assert) {
|
|
||||||
let done = assert.async();
|
|
||||||
|
|
||||||
// number of asserts
|
|
||||||
assert.expect(1);
|
|
||||||
|
|
||||||
frappe.run_serially([
|
|
||||||
// insert a new Hub Tracked Item
|
|
||||||
() => frappe.tests.make('Hub Tracked Item', [
|
|
||||||
// values to be set
|
|
||||||
{key: 'value'}
|
|
||||||
]),
|
|
||||||
() => {
|
|
||||||
assert.equal(cur_frm.doc.key, 'value');
|
|
||||||
},
|
|
||||||
() => done()
|
|
||||||
]);
|
|
||||||
|
|
||||||
});
|
|
||||||
@@ -187,7 +187,7 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
show_publish_progress() {
|
show_publish_progress() {
|
||||||
const items_to_publish = this.items_data_to_publish.length
|
const items_to_publish = this.items_data_to_publish.length
|
||||||
? this.items_data_to_publish
|
? this.items_data_to_publish
|
||||||
: JSON.parse(hub.settings.custom_data);
|
: JSON.parse(hub.settings.custom_data || '[]');
|
||||||
|
|
||||||
const $publish_progress = $(`<div class="sync-progress">
|
const $publish_progress = $(`<div class="sync-progress">
|
||||||
<p><b>${__(`Syncing ${items_to_publish.length} Products`)}</b></p>
|
<p><b>${__(`Syncing ${items_to_publish.length} Products`)}</b></p>
|
||||||
|
|||||||
Reference in New Issue
Block a user