feat: enable custom field search on POS (#25421)

* feat: multi lingual item search in POS

* fix: limit the options for selection and broken down funtion for geting condition
This commit is contained in:
Afshan
2021-04-26 22:48:13 +05:30
committed by GitHub
parent 7f1b2de74d
commit df06e49e0c
6 changed files with 117 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_va
if search_value:
data = search_serial_or_batch_or_barcode_number(search_value)
item_code = data.get("item_code") if data.get("item_code") else search_value
serial_no = data.get("serial_no") if data.get("serial_no") else ""
batch_no = data.get("batch_no") if data.get("batch_no") else ""
@@ -31,7 +31,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_va
if data:
item_info = frappe.db.get_value(
"Item", data.get("item_code"),
"Item", data.get("item_code"),
["name as item_code", "item_name", "description", "stock_uom", "image as item_image", "is_stock_item"]
, as_dict=1)
item_info.setdefault('serial_no', serial_no)
@@ -139,8 +139,24 @@ def get_conditions(item_code, serial_no, batch_no, barcode):
if serial_no or batch_no or barcode:
return "item.name = {0}".format(frappe.db.escape(item_code))
return """(item.name like {item_code}
or item.item_name like {item_code})""".format(item_code = frappe.db.escape('%' + item_code + '%'))
return make_condition(item_code)
def make_condition(item_code):
condition = "("
condition += """item.name like {item_code}
or item.item_name like {item_code}""".format(item_code = frappe.db.escape('%' + item_code + '%'))
condition += add_search_fields_condition(item_code)
condition += ")"
return condition
def add_search_fields_condition(item_code):
condition = ''
search_fields = frappe.get_all('POS Search Fields', fields = ['fieldname'])
if search_fields:
for field in search_fields:
condition += " or item.{0} like {1}".format(field['fieldname'], frappe.db.escape('%' + item_code + '%'))
return condition
def get_item_group_condition(pos_profile):
cond = "and 1=1"
@@ -257,4 +273,4 @@ def set_customer_info(fieldname, customer, value=""):
elif fieldname == 'mobile_no':
contact_doc.set('phone_nos', [{ 'phone': value, 'is_primary_mobile_no': 1}])
frappe.db.set_value('Customer', customer, 'mobile_no', value)
contact_doc.save()
contact_doc.save()