Merge branch 'fix_asset_sold_status' of https://github.com/AnandBaburajan/erpnext into fix_asset_sold_status
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 4f8b5c7..8eae0a0 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -212,21 +212,15 @@
meta = frappe.get_meta(doctype, cached=True)
searchfields = meta.get_search_fields()
- # these are handled separately
- ignored_search_fields = ("item_name", "description")
- for ignored_field in ignored_search_fields:
- if ignored_field in searchfields:
- searchfields.remove(ignored_field)
-
columns = ""
- extra_searchfields = [
- field
- for field in searchfields
- if not field in ["name", "item_group", "description", "item_name"]
- ]
+ extra_searchfields = [field for field in searchfields if not field in ["name", "description"]]
if extra_searchfields:
- columns = ", " + ", ".join(extra_searchfields)
+ columns += ", " + ", ".join(extra_searchfields)
+
+ if "description" in searchfields:
+ columns += """, if(length(tabItem.description) > 40, \
+ concat(substr(tabItem.description, 1, 40), "..."), description) as description"""
searchfields = searchfields + [
field
@@ -266,12 +260,10 @@
if frappe.db.count(doctype, cache=True) < 50000:
# scan description only if items are less than 50000
description_cond = "or tabItem.description LIKE %(txt)s"
+
return frappe.db.sql(
"""select
- tabItem.name, tabItem.item_name, tabItem.item_group,
- if(length(tabItem.description) > 40, \
- concat(substr(tabItem.description, 1, 40), "..."), description) as description
- {columns}
+ tabItem.name {columns}
from tabItem
where tabItem.docstatus < 2
and tabItem.disabled=0
diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py
index 1cee553..e35c8bf 100644
--- a/erpnext/stock/doctype/item/test_item.py
+++ b/erpnext/stock/doctype/item/test_item.py
@@ -5,6 +5,7 @@
import json
import frappe
+from frappe.custom.doctype.property_setter.property_setter import make_property_setter
from frappe.test_runner import make_test_objects
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, today
@@ -816,6 +817,30 @@
item.reload()
self.assertEqual(item.is_stock_item, 1)
+ def test_serach_fields_for_item(self):
+ from erpnext.controllers.queries import item_query
+
+ make_property_setter("Item", None, "search_fields", "item_name", "Data", for_doctype="Doctype")
+
+ item = make_item(properties={"item_name": "Test Item", "description": "Test Description"})
+ data = item_query(
+ "Item", "Test Item", "", 0, 20, filters={"item_name": "Test Item"}, as_dict=True
+ )
+ self.assertEqual(data[0].name, item.name)
+ self.assertEqual(data[0].item_name, item.item_name)
+ self.assertTrue("description" not in data[0])
+
+ make_property_setter(
+ "Item", None, "search_fields", "item_name, description", "Data", for_doctype="Doctype"
+ )
+ data = item_query(
+ "Item", "Test Item", "", 0, 20, filters={"item_name": "Test Item"}, as_dict=True
+ )
+ self.assertEqual(data[0].name, item.name)
+ self.assertEqual(data[0].item_name, item.item_name)
+ self.assertEqual(data[0].description, item.description)
+ self.assertTrue("description" in data[0])
+
def set_item_variant_settings(fields):
doc = frappe.get_doc("Item Variant Settings")
diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html
index a10870d..ec1d497 100644
--- a/erpnext/templates/pages/order.html
+++ b/erpnext/templates/pages/order.html
@@ -18,7 +18,7 @@
<b class="caret"></b>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
- {% if doc.doctype == 'Purchase Order' %}
+ {% if doc.doctype == 'Purchase Order' and show_make_pi_button %}
<a class="dropdown-item" href="/api/method/erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice_from_portal?purchase_order_name={{ doc.name }}" data-action="make_purchase_invoice">{{ _("Make Purchase Invoice") }}</a>
{% endif %}
<a class="dropdown-item" href='/printview?doctype={{ doc.doctype}}&name={{ doc.name }}&format={{ print_format }}'
diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py
index 3e6d57a..e1e12bd 100644
--- a/erpnext/templates/pages/order.py
+++ b/erpnext/templates/pages/order.py
@@ -52,6 +52,9 @@
)
context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
+ # show Make Purchase Invoice button based on permission
+ context.show_make_pi_button = frappe.has_permission("Purchase Invoice", "create")
+
def get_attachments(dt, dn):
return frappe.get_all(