From c95dff7b7da3a0226f19bd9aa958a0ebd48b956f Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 3 Nov 2020 10:16:58 +0530 Subject: [PATCH 1/2] fix: cannot add items to cart (#23796) * fix: _ is not defined * fix: item image alt gets overflowed due to large text * fix: available item qty in pos search * fix: cash shortcuts overflow --- erpnext/selling/page/point_of_sale/point_of_sale.py | 6 ++---- erpnext/selling/page/point_of_sale/pos_controller.js | 2 +- erpnext/selling/page/point_of_sale/pos_item_selector.js | 2 +- erpnext/selling/page/point_of_sale/pos_payment.js | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index 6b9939e8ef..135e8928c5 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -14,11 +14,9 @@ from six import string_types def get_items(start, page_length, price_list, item_group, pos_profile, search_value=""): data = dict() result = [] - warehouse, hide_unavailable_items = "", False allow_negative_stock = frappe.db.get_single_value('Stock Settings', 'allow_negative_stock') - if not allow_negative_stock: - warehouse, hide_unavailable_items = frappe.db.get_value('POS Profile', pos_profile, ['warehouse', 'hide_unavailable_items']) + warehouse, hide_unavailable_items = frappe.db.get_value('POS Profile', pos_profile, ['warehouse', 'hide_unavailable_items']) if not frappe.db.exists('Item Group', item_group): item_group = get_root_of('Item Group') @@ -97,7 +95,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_va for item in items_data: item_code = item.item_code item_price = item_prices.get(item_code) or {} - if not allow_negative_stock: + if allow_negative_stock: item_stock_qty = frappe.db.sql("""select ifnull(sum(actual_qty), 0) from `tabBin` where item_code = %s""", item_code)[0][0] else: item_stock_qty = get_stock_availability(item_code, warehouse) diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js index 3d0054647b..f7d1fa4ded 100644 --- a/erpnext/selling/page/point_of_sale/pos_controller.js +++ b/erpnext/selling/page/point_of_sale/pos_controller.js @@ -637,7 +637,7 @@ erpnext.PointOfSale.Controller = class { if (!(available_qty > 0)) { frappe.model.clear_doc(item_row.doctype, item_row.name); frappe.throw({ - title: _("Not Available"), + title: __("Not Available"), message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) }) } else if (available_qty < qty_needed) { diff --git a/erpnext/selling/page/point_of_sale/pos_item_selector.js b/erpnext/selling/page/point_of_sale/pos_item_selector.js index 4139e29947..49d42814ab 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_selector.js +++ b/erpnext/selling/page/point_of_sale/pos_item_selector.js @@ -81,7 +81,7 @@ erpnext.PointOfSale.ItemSelector = class { function get_item_image_html() { if (item_image) { return `
- ${item_image} + ${frappe.get_abbr(item.item_name)}
` } else { return `
diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index e89cf01f79..e4d8965ac2 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -409,7 +409,7 @@ erpnext.PointOfSale.Payment = class { ${ shortcuts.map(s => { return `
- ${format_currency(s, currency)} + ${format_currency(s, currency, 0)}
` }).join('') } From da878c43fcf84c6e9f9b9474ca1c268e7c744fa5 Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 3 Nov 2020 10:51:09 +0530 Subject: [PATCH 2/2] fix: cannot save customer email & phone (#23797) --- .../page/point_of_sale/point_of_sale.py | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index 135e8928c5..a690050f79 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -229,13 +229,31 @@ def set_customer_info(fieldname, customer, value=""): frappe.db.set_value('Customer', customer, 'loyalty_program', value) contact = frappe.get_cached_value('Customer', customer, 'customer_primary_contact') + if not contact: + contact = frappe.db.sql(""" + SELECT parent FROM `tabDynamic Link` + WHERE + parenttype = 'Contact' AND + parentfield = 'links' AND + link_doctype = 'Customer' AND + link_name = %s + """, (customer), as_dict=1) + contact = contact[0].get('parent') if contact else None - if contact: - contact_doc = frappe.get_doc('Contact', contact) - if fieldname == 'email_id': - contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}]) - frappe.db.set_value('Customer', customer, 'email_id', 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() \ No newline at end of file + if not contact: + new_contact = frappe.new_doc('Contact') + new_contact.is_primary_contact = 1 + new_contact.first_name = customer + new_contact.set('links', [{'link_doctype': 'Customer', 'link_name': customer}]) + new_contact.save() + contact = new_contact.name + frappe.db.set_value('Customer', customer, 'customer_primary_contact', contact) + + contact_doc = frappe.get_doc('Contact', contact) + if fieldname == 'email_id': + contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}]) + frappe.db.set_value('Customer', customer, 'email_id', 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() \ No newline at end of file