From f7a83cb4f5227d6c04717766a7f496b457592929 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 5 Apr 2019 00:42:48 +0530 Subject: [PATCH] fix: incorrect POS profile selected --- erpnext/stock/get_item_details.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 7f0e670f65..8b81972b4d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -606,28 +606,39 @@ def get_pos_profile_item_details(company, args, pos_profile=None, update_data=Fa @frappe.whitelist() def get_pos_profile(company, pos_profile=None, user=None): - if pos_profile: - return frappe.get_cached_doc('POS Profile', pos_profile) + if pos_profile: return frappe.get_cached_doc('POS Profile', pos_profile) if not user: user = frappe.session['user'] + condition = "pfu.user = %(user)s AND pfu.default=1" + if user and company: + condition = "pfu.user = %(user)s AND pf.company = %(company)s AND pfu.default=1" + pos_profile = frappe.db.sql("""SELECT pf.* FROM `tabPOS Profile` pf LEFT JOIN `tabPOS Profile User` pfu ON pf.name = pfu.parent WHERE - ( - (pfu.user = %(user)s AND pf.company = %(company)s AND pfu.default=1) - OR (pfu.user = %(user)s AND pfu.default=1) - OR (ifnull(pfu.user, '') = '' AND pf.company = %(company)s) - ) AND pf.disabled = 0 - """, { + {cond} AND pf.disabled = 0 + """.format(cond = condition), { 'user': user, 'company': company }, as_dict=1) + if not pos_profile and company: + pos_profile = frappe.db.sql("""SELECT pf.* + FROM + `tabPOS Profile` pf LEFT JOIN `tabPOS Profile User` pfu + ON + pf.name = pfu.parent + WHERE + pf.company = %(company)s AND pf.disabled = 0 + """, { + 'company': company + }, as_dict=1) + return pos_profile and pos_profile[0] or None def get_serial_nos_by_fifo(args, sales_order=None):