mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-09 00:01:18 +00:00
Hub Market (#13325)
* [hub] enable hub with OAuth token from user's client ID * [hub] settings schema for adding users * [hub] image view style listing * [hub] broken image link fallback * [wip] * [hub] bootstrap timeline * [hub] setup quick view * [hub] reformat ratings, add companies autocomplete filter * [hub] common listing frames * [hub] setup sort selector * [hub] timeline * [hub] customize list header * [hub] genuine form fieldtypes * [hub] review products * [hub] suggest missing categories remotely * [hub] Wishlist; header and title templates * [hub] link wishlist, remove company migration * [hub] calculate ratings
This commit is contained in:
committed by
Rushabh Mehta
parent
c5effbf009
commit
b60a52b194
@@ -22,13 +22,64 @@ def get_list(doctype, start=0, limit=20, fields=["*"], filters="{}", order_by=No
|
||||
response = connection.get_list(doctype,
|
||||
limit_start=start, limit_page_length=limit,
|
||||
filters=filters, fields=fields)
|
||||
return response
|
||||
|
||||
# Bad, need child tables in response
|
||||
listing = []
|
||||
for obj in response:
|
||||
doc = connection.get_doc(doctype, obj['name'])
|
||||
listing.append(doc)
|
||||
|
||||
return listing
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_item_favourites(start=0, limit=20, fields=["*"], order_by=None):
|
||||
doctype = 'Hub Item'
|
||||
hub_settings = frappe.get_doc('Hub Settings')
|
||||
item_names_str = hub_settings.get('custom_data') or '[]'
|
||||
item_names = json.loads(item_names_str)
|
||||
filters = json.dumps({
|
||||
'hub_item_code': ['in', item_names]
|
||||
})
|
||||
return get_list(doctype, start, limit, fields, filters, order_by)
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_wishlist_item(item_name, remove=0):
|
||||
remove = int(remove)
|
||||
hub_settings = frappe.get_doc('Hub Settings')
|
||||
data = hub_settings.get('custom_data')
|
||||
if not data or not json.loads(data):
|
||||
data = '[]'
|
||||
hub_settings.custom_data = data
|
||||
hub_settings.save()
|
||||
|
||||
item_names_str = data
|
||||
item_names = json.loads(item_names_str)
|
||||
if not remove and item_name not in item_names:
|
||||
item_names.append(item_name)
|
||||
if remove and item_name in item_names:
|
||||
item_names.remove(item_name)
|
||||
|
||||
item_names_str = json.dumps(item_names)
|
||||
|
||||
hub_settings.custom_data = item_names_str
|
||||
hub_settings.save()
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_meta(doctype):
|
||||
connection = get_client_connection()
|
||||
meta = connection.get_doc('DocType', doctype)
|
||||
return meta
|
||||
categories = connection.get_list('Hub Category',
|
||||
limit_start=0, limit_page_length=300,
|
||||
filters={}, fields=['name'])
|
||||
|
||||
categories = [d.get('name') for d in categories]
|
||||
return {
|
||||
'meta': meta,
|
||||
'companies': connection.get_list('Hub Company',
|
||||
limit_start=0, limit_page_length=300,
|
||||
filters={}, fields=['name']),
|
||||
'categories': categories
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_categories(parent='All Categories'):
|
||||
@@ -40,12 +91,42 @@ def get_categories(parent='All Categories'):
|
||||
return response
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_category(item_name, category):
|
||||
def update_category(hub_item_code, category):
|
||||
connection = get_hub_connection()
|
||||
response = connection.update('Hub Item', dict(
|
||||
|
||||
# args = frappe._dict(dict(
|
||||
# doctype='Hub Category',
|
||||
# hub_category_name=category
|
||||
# ))
|
||||
# response = connection.insert('Hub Category', args)
|
||||
|
||||
response = connection.update('Hub Item', frappe._dict(dict(
|
||||
doctype='Hub Item',
|
||||
hub_category = category
|
||||
), item_name)
|
||||
return response.ok
|
||||
)), hub_item_code)
|
||||
|
||||
return response
|
||||
|
||||
@frappe.whitelist()
|
||||
def send_review(hub_item_code, review):
|
||||
review = json.loads(review)
|
||||
hub_connection = get_hub_connection()
|
||||
|
||||
item_doc = hub_connection.connection.get_doc('Hub Item', hub_item_code)
|
||||
existing_reviews = item_doc.get('reviews')
|
||||
|
||||
reviews = [review]
|
||||
review.setdefault('idx', 0)
|
||||
for r in existing_reviews:
|
||||
if r.get('user') != review.get('user'):
|
||||
reviews.append(r)
|
||||
|
||||
response = hub_connection.update('Hub Item', dict(
|
||||
doctype='Hub Item',
|
||||
reviews = reviews
|
||||
), hub_item_code)
|
||||
|
||||
return response
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_details(hub_sync_id=None, doctype='Hub Item'):
|
||||
@@ -53,6 +134,11 @@ def get_details(hub_sync_id=None, doctype='Hub Item'):
|
||||
return
|
||||
connection = get_client_connection()
|
||||
details = connection.get_doc(doctype, hub_sync_id)
|
||||
reviews = details.get('reviews')
|
||||
if len(reviews):
|
||||
for r in reviews:
|
||||
r.setdefault('pretty_date', frappe.utils.pretty_date(r.get('modified')))
|
||||
details.setdefault('reviews', reviews)
|
||||
return details
|
||||
|
||||
def get_client_connection():
|
||||
|
||||
Reference in New Issue
Block a user