[hub] simplify marketplace settings, remove company fields

- Company attributes will be fetched/calculated to send to server
- removed them as fields in settings
- Added description in company, with existing logo field
- TODO: for things like logo and description, ask user to set in master
This commit is contained in:
Prateeksha Singh
2018-09-01 17:20:08 +05:30
parent 255dd0e03d
commit b2b745fc7a
6 changed files with 136 additions and 243 deletions

View File

@@ -17,25 +17,17 @@ current_user = frappe.session.user
@frappe.whitelist() @frappe.whitelist()
def register_marketplace(company, company_description): def register_marketplace(company):
validate_registerer() validate_registerer()
settings = frappe.get_single('Marketplace Settings') settings = frappe.get_single('Marketplace Settings')
country, currency = frappe.db.get_value('Company', company, ['country', 'default_currency']) message = settings.register_seller(company)
settings.company = company
settings.country = country
settings.currency = currency
settings.company_description = company_description
message = settings.register()
if message.get('hub_seller_name'): if message.get('hub_seller_name'):
settings.registered = 1 settings.registered = 1
settings.hub_seller_name = message.get('hub_seller_name') settings.hub_seller_name = message.get('hub_seller_name')
settings.save() settings.save()
settings.add_user(frappe.session.user) settings.add_hub_user(frappe.session.user)
return { 'ok': 1 } return { 'ok': 1 }

View File

@@ -95,7 +95,7 @@
"in_global_search": 0, "in_global_search": 0,
"in_list_view": 0, "in_list_view": 0,
"in_standard_filter": 0, "in_standard_filter": 0,
"label": "Marketplace URL", "label": "Marketplace URL (to hide and update label)",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@@ -240,167 +240,6 @@
"translatable": 0, "translatable": 0,
"unique": 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,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Company Logo",
"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": "site_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Site Name",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"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": "country",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Country",
"length": 0,
"no_copy": 0,
"options": "Country",
"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": "currency",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Currency",
"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_description",
"fieldtype": "Long Text",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Company Description",
"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_bulk_edit": 0,
"allow_in_quick_entry": 0, "allow_in_quick_entry": 0,
@@ -512,8 +351,8 @@
"issingle": 1, "issingle": 1,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-09-01 14:15:40.676256", "modified": "2018-09-01 17:05:59.600583",
"modified_by": "suraj@rawcoderz.com", "modified_by": "cave@aperture.com",
"module": "Hub Node", "module": "Hub Node",
"name": "Marketplace Settings", "name": "Marketplace Settings",
"name_case": "", "name_case": "",

View File

@@ -13,23 +13,33 @@ from six import string_types
class MarketplaceSettings(Document): class MarketplaceSettings(Document):
def validate(self): def register_seller(self, company):
self.site_name = frappe.utils.get_url()
def register(self): country, currency, company_description = frappe.db.get_value('Company', company,
""" Create a User on hubmarket.org and return username/password """ ['country', 'default_currency', 'company_description'])
self.site_name = frappe.utils.get_url()
company_details = {
'company': company,
'country': country,
# 'city': '',
'currency': currency,
'company_description': company_description,
# 'company_logo': company_logo,
'site_name': frappe.utils.get_url(),
}
hub_connection = self.get_connection() hub_connection = self.get_connection()
response = hub_connection.post_request({ response = hub_connection.post_request({
'cmd': 'hub.hub.api.register', 'cmd': 'hub.hub.api.add_hub_seller',
'company_details': self.as_json() 'company_details': json.dumps(company_details)
}) })
return response return response
def add_user(self, user_email):
def add_hub_user(self, user_email):
if not self.registered: if not self.registered:
return return
@@ -53,10 +63,11 @@ class MarketplaceSettings(Document):
self.insert() self.insert()
def get_connection(self): def get_connection(self):
return FrappeClient(self.marketplace_url) return FrappeClient(self.marketplace_url)
def unregister(self): def unregister(self):
""" Disable the User on hub.erpnext.org""" """Disable the User on hubmarket.org"""
pass pass

View File

@@ -4,30 +4,12 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => {
fieldtype: 'Link', fieldtype: 'Link',
fieldname: 'company', fieldname: 'company',
label: __('Company'), label: __('Company'),
options: 'Company', options: 'Company'
onchange: () => {
const value = dialog.get_value('company');
if (value) {
frappe.db.get_doc('Company', value)
.then(company => {
dialog.set_values({
country: company.country,
currency: company.default_currency
});
});
}
}
}, },
{ {
fieldname: 'company_email', fieldname: 'company_email',
label: __('Email'), label: __('Email'),
fieldtype: 'Read Only' fieldtype: 'Read Only'
},
{
fieldtype: 'Text',
label: __('About your Company'),
fieldname: 'company_description'
} }
]; ];
@@ -38,7 +20,11 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => {
primary_action: () => { primary_action: () => {
const form_values = dialog.get_values(); const form_values = dialog.get_values();
let values_filled = true; let values_filled = true;
const mandatory_fields = ['company', 'company_email', 'company_description'];
// TODO: Say "we notice that the company description and logo isn't set. Please set them in master."
// Only then allow to register
const mandatory_fields = ['company'];
mandatory_fields.forEach(field => { mandatory_fields.forEach(field => {
const value = form_values[field]; const value = form_values[field];
if (!value) { if (!value) {
@@ -51,6 +37,7 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => {
action.on_submit(form_values); action.on_submit(form_values);
} }
}); });
// Post create // Post create
const default_company = frappe.defaults.get_default('company'); const default_company = frappe.defaults.get_default('company');
dialog.set_value('company', default_company); dialog.set_value('company', default_company);

View File

@@ -99,13 +99,12 @@ erpnext.hub.Marketplace = class Marketplace {
this.register_dialog.show(); this.register_dialog.show();
} }
register_marketplace({company, company_email, company_description}) { register_marketplace({company, company_email}) {
frappe.call({ frappe.call({
method: 'erpnext.hub_node.api.register_marketplace', method: 'erpnext.hub_node.api.register_marketplace',
args: { args: {
company, company,
company_email, company_email,
company_description
} }
}).then((r) => { }).then((r) => {
if (r.message && r.message.ok) { if (r.message && r.message.ok) {

View File

@@ -305,6 +305,102 @@
"translatable": 0, "translatable": 0,
"unique": 0 "unique": 0
}, },
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "sb_about",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "About the Company",
"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,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Company Logo",
"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_description",
"fieldtype": "Text Editor",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Company Description",
"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_bulk_edit": 0,
"allow_in_quick_entry": 0, "allow_in_quick_entry": 0,
@@ -741,7 +837,7 @@
"label": "Create Chart Of Accounts Based On", "label": "Create Chart Of Accounts Based On",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"options": "\nStandard Template\nExisting Company", "options": "\nStandard Template\nExisting Company\n\n\n",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
@@ -775,7 +871,7 @@
"label": "Chart Of Accounts Template", "label": "Chart Of Accounts Template",
"length": 0, "length": 0,
"no_copy": 1, "no_copy": 1,
"options": "", "options": "\n\n\n",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
@@ -2630,38 +2726,6 @@
"translatable": 0, "translatable": 0,
"unique": 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,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Company Logo",
"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_bulk_edit": 0,
"allow_in_quick_entry": 0, "allow_in_quick_entry": 0,
@@ -2772,8 +2836,8 @@
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"menu_index": 0, "menu_index": 0,
"modified": "2018-08-28 15:47:50.757131", "modified": "2018-09-01 16:03:30.716918",
"modified_by": "Administrator", "modified_by": "cave@aperture.com",
"module": "Setup", "module": "Setup",
"name": "Company", "name": "Company",
"owner": "Administrator", "owner": "Administrator",
@@ -2918,5 +2982,6 @@
"show_name_in_global_search": 1, "show_name_in_global_search": 1,
"sort_order": "ASC", "sort_order": "ASC",
"track_changes": 1, "track_changes": 1,
"track_seen": 0 "track_seen": 0,
"track_views": 0
} }