Repository: frappe/erpnext
Pull request: fix: reset homepage to home after unchecking products page
resets homepage back to home when "home page is products" is unchecked

fixes: #22733 

Problem statement:
Turning on, then off "Homepage is Products" on the Products settings page does not revert back to Home Page
By default, ERPNext provides a landing page for the main index of the site.  If you activate "Home Page is Products" under the Products Settings section, save it, then deactivate the "Home Page is Products" value, the site still acts as-if the feature is enabled.  The expected behavior of this is to revert back to the landing page style for the index page.

Hints from issue discussion:
I've made a fix for this. Please try and let me know if it works fine.

Commit message: chore: fix get single value call

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>

Patch to review:
diff --git a/erpnext/portal/doctype/products_settings/products_settings.py b/erpnext/portal/doctype/products_settings/products_settings.py
index 82afebf2f1e5..cb0746277470 100644
--- a/erpnext/portal/doctype/products_settings/products_settings.py
+++ b/erpnext/portal/doctype/products_settings/products_settings.py
@@ -11,9 +11,9 @@
 class ProductsSettings(Document):
 	def validate(self):
 		if self.home_page_is_products:
-			website_settings = frappe.get_doc('Website Settings')
-			website_settings.home_page = 'products'
-			website_settings.save()
+			frappe.db.set_value("Website Settings", "home_page", "products")
+		elif frappe.db.get_single_value("Website Settings", "home_page") == 'products':
+			frappe.db.set_value("Website Settings", "home_page", "home")
 
 		self.validate_field_filters()
 		self.validate_attribute_filters()
@@ -40,4 +40,5 @@ def home_page_is_products(doc, method):
 	home_page_is_products = cint(frappe.db.get_single_value('Products Settings', 'home_page_is_products'))
 	if home_page_is_products:
 		doc.home_page = 'products'
-
+	elif doc.home_page == "products":
+		doc.home_page = 'home'


Code review comments:
diff_hunk: @@ -40,4 +40,5 @@ def home_page_is_products(doc, method):
 	home_page_is_products = cint(frappe.db.get_single_value('Products Settings', 'home_page_is_products'))
 	if home_page_is_products:
 		doc.home_page = 'products'
-
+	elif doc.home_page == "products":
path: erpnext/portal/doctype/products_settings/products_settings.py
text: @user1:
I am not sure if this block should be added. What if someone is unaware of Product Settings and is trying to set the homepage as "products" from Website Settings itself it will keep on changing the homepage to home and the user will get confused from where this is coming. Also currently it throws the following error if you try to set the homepage as "products" for this PR

![image](https://user-images.githubusercontent.com/42651287/88165514-6f3eb380-cc33-11ea-9a94-f7956e429cbc.png)


@author:
So according to this logic, whenever homepage is set to products and then later "Home Page is Products" is unchecked, it should reset back to home. It won't get triggered any other time. I do not see what the problem is with the logic?

For the error, as you see, I haven't changed anything other than adding a condition that checks whether the current homepage is set to products in this pull request.

@author:
there is a problem with the logic, apologies. ill fix it.