feat: Add new registration flow
diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py
index af34844..12a564a3 100644
--- a/erpnext/hub_node/api.py
+++ b/erpnext/hub_node/api.py
@@ -17,31 +17,27 @@
@frappe.whitelist()
-def register_marketplace(**kwargs):
- settings = frappe.get_single('Marketplace Settings')
- settings.update(kwargs)
- settings.users = []
-
+def register_marketplace(company, company_description):
validate_registerer()
+
+ settings = frappe.get_single('Marketplace Settings')
+ country, currency = frappe.db.get_value('Company', company, ['country', 'default_currency'])
+
+ settings.company = company
+ settings.country = country
+ settings.currency = currency
+ settings.company_description = company_description
+
message = settings.register()
- if message.get('email'):
+ if message.get('hub_seller_name'):
settings.registered = 1
+ settings.hub_seller_name = message.get('hub_seller_name')
+ settings.save()
- settings.append('users', {
- 'user': current_user,
- 'name': current_user,
- 'username': kwargs.get('username'),
- 'password': message.get('password')
- })
+ settings.add_user(frappe.session.user)
- user_emails = kwargs.get('users').strip()[:-1].split(', ')
- for email in user_emails:
- settings.append('users', {'user': email, 'name': email})
-
- settings.insert()
-
- return message
+ return { 'ok': 1 }
@frappe.whitelist()
@@ -53,8 +49,11 @@
if current_user == 'Administrator':
frappe.throw(_('Please login as another user to register on Marketplace'))
- if 'System Manager' not in frappe.get_roles():
- frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError)
+ valid_roles = ['System Manager', 'Item Manager']
+
+ if not frappe.utils.is_subset(valid_roles, frappe.get_roles()):
+ frappe.throw(_('Only users with {0} role can register on Marketplace').format(', '.join(valid_roles)),
+ frappe.PermissionError)
@frappe.whitelist()
diff --git a/erpnext/hub_node/doctype/hub_user/hub_user.json b/erpnext/hub_node/doctype/hub_user/hub_user.json
index 08a59c6..a660022 100644
--- a/erpnext/hub_node/doctype/hub_user/hub_user.json
+++ b/erpnext/hub_node/doctype/hub_user/hub_user.json
@@ -3,7 +3,7 @@
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
- "autoname": "field:user",
+ "autoname": "",
"beta": 0,
"creation": "2018-08-31 12:36:45.627531",
"custom": 0,
@@ -53,7 +53,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "username",
+ "fieldname": "hub_user_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
@@ -62,7 +62,7 @@
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
- "label": "Hub Username",
+ "label": "Hub User",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@@ -121,8 +121,8 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2018-09-01 09:46:54.327880",
- "modified_by": "cave@aperture.com",
+ "modified": "2018-09-01 13:56:07.816894",
+ "modified_by": "netchamp@rawcoderz.com",
"module": "Hub Node",
"name": "Hub User",
"name_case": "",
diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json
index 066202a..f2d8b05 100644
--- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json
+++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json
@@ -215,6 +215,38 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "hub_seller_name",
+ "fieldtype": "Data",
+ "hidden": 1,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Hub Seller Name",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_in_quick_entry": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "company_logo",
"fieldtype": "Attach Image",
"hidden": 0,
@@ -480,8 +512,8 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-08-31 22:14:59.497780",
- "modified_by": "cave@aperture.com",
+ "modified": "2018-09-01 14:15:40.676256",
+ "modified_by": "suraj@rawcoderz.com",
"module": "Hub Node",
"name": "Marketplace Settings",
"name_case": "",
diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py
index f0046d0..cfb9ace 100644
--- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py
+++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py
@@ -7,6 +7,7 @@
from frappe.model.document import Document
from frappe.utils import add_years, now, get_datetime, get_datetime_str
from frappe import _
+from frappe.frappeclient import FrappeClient
from erpnext.utilities.product import get_price, get_qty_in_stock
from six import string_types
@@ -15,27 +16,45 @@
def validate(self):
self.site_name = frappe.utils.get_url()
-
- def get_marketplace_url(self):
- return self.marketplace_url
-
-
def register(self):
- """ Create a User on hub.erpnext.org and return username/password """
+ """ Create a User on hubmarket.org and return username/password """
self.site_name = frappe.utils.get_url()
- register_url = self.get_marketplace_url() + '/api/method/hub.hub.api.register'
- data = {'profile': self.as_json(), 'email': frappe.session.user}
- headers = {'accept': 'application/json'}
+ hub_connection = self.get_connection()
- response = requests.post(register_url, data = data, headers = headers)
- response.raise_for_status()
- if response.ok:
- message = response.json().get('message')
- else:
- frappe.throw(json.loads(response.text))
+ response = hub_connection.post_request({
+ 'cmd': 'hub.hub.api.register',
+ 'company_details': self.as_json()
+ })
- return message or None
+ return response
+
+ def add_user(self, user_email):
+ if not self.registered:
+ return
+
+ hub_connection = self.get_connection()
+
+ first_name, last_name = frappe.db.get_value('User', user_email, ['first_name', 'last_name'])
+
+ hub_user = hub_connection.post_request({
+ 'cmd': 'hub.hub.api.add_hub_user',
+ 'user_email': user_email,
+ 'first_name': first_name,
+ 'last_name': last_name,
+ 'hub_seller': self.hub_seller_name
+ })
+
+ self.append('users', {
+ 'user': hub_user.get('user_email'),
+ 'hub_user_name': hub_user.get('hub_user_name'),
+ 'password': hub_user.get('password')
+ })
+
+ self.insert()
+
+ def get_connection(self):
+ return FrappeClient(self.marketplace_url)
def unregister(self):
diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js
index 03e7f48..240df82 100644
--- a/erpnext/public/js/hub/components/profile_dialog.js
+++ b/erpnext/public/js/hub/components/profile_dialog.js
@@ -1,12 +1,6 @@
const ProfileDialog = (title = __('Edit Profile'), action={}) => {
const fields = [
{
- // TODO: add hub check for taken
- fieldname: 'username',
- label: __('Username'),
- fieldtype: 'Data'
- },
- {
fieldtype: 'Link',
fieldname: 'company',
label: __('Company'),
@@ -31,21 +25,6 @@
fieldtype: 'Read Only'
},
{
- fieldname: 'users',
- label: __('Users'),
- fieldtype: 'MultiSelect'
- },
- {
- fieldname: 'country',
- label: __('Country'),
- fieldtype: 'Read Only'
- },
- {
- fieldname: 'currency',
- label: __('Currency'),
- fieldtype: 'Read Only'
- },
- {
fieldtype: 'Text',
label: __('About your Company'),
fieldname: 'company_description'
@@ -72,14 +51,6 @@
action.on_submit(form_values);
}
});
-
- frappe.db.get_list('User')
- .then(result => {
- const users = result.map(result => result.name)
- .filter(user => !['Guest', 'Administrator', frappe.session.user].includes(user));
- dialog.fields_dict.users.set_data(users);
- });
-
// Post create
const default_company = frappe.defaults.get_default('company');
dialog.set_value('company', default_company);
diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js
index bea30bd..2bd5552 100644
--- a/erpnext/public/js/hub/marketplace.js
+++ b/erpnext/public/js/hub/marketplace.js
@@ -99,15 +99,20 @@
this.register_dialog.show();
}
- register_marketplace(form_values) {
+ register_marketplace({company, company_email, company_description}) {
frappe.call({
method: 'erpnext.hub_node.api.register_marketplace',
- args: form_values
- }).then(() => {
- this.register_dialog.hide();
- frappe.set_route('marketplace', 'publish');
-
- erpnext.hub.trigger('seller-registered');
+ args: {
+ company,
+ company_email,
+ company_description
+ }
+ }).then((r) => {
+ if (r.message && r.message.ok) {
+ this.register_dialog.hide();
+ frappe.set_route('marketplace', 'publish');
+ erpnext.hub.trigger('seller-registered');
+ }
});
}