[Fix] Discount and serial no search issue (#11040)
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js
index 5eb8226..1b0b9eb 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -763,28 +763,41 @@
// });
this.wrapper.find('.additional_discount_percentage').on('change', (e) => {
+ const discount_percentage = flt(e.target.value,
+ precision("additional_discount_percentage"));
+
frappe.model.set_value(this.frm.doctype, this.frm.docname,
- 'additional_discount_percentage', e.target.value)
+ 'additional_discount_percentage', discount_percentage)
.then(() => {
let discount_wrapper = this.wrapper.find('.discount_amount');
- discount_wrapper.val(this.frm.doc.discount_amount);
+ discount_wrapper.val(flt(this.frm.doc.discount_amount,
+ precision('discount_amount')));
discount_wrapper.trigger('change');
});
});
this.wrapper.find('.discount_amount').on('change', (e) => {
+ const discount_amount = flt(e.target.value, precision('discount_amount'));
frappe.model.set_value(this.frm.doctype, this.frm.docname,
- 'discount_amount', flt(e.target.value));
+ 'discount_amount', discount_amount);
this.frm.trigger('discount_amount')
.then(() => {
- let discount_wrapper = this.wrapper.find('.additional_discount_percentage');
- discount_wrapper.val(this.frm.doc.additional_discount_percentage);
+ this.update_discount_fields();
this.update_taxes_and_totals();
this.update_grand_total();
});
});
}
+ update_discount_fields() {
+ let discount_wrapper = this.wrapper.find('.additional_discount_percentage');
+ let discount_amt_wrapper = this.wrapper.find('.discount_amount');
+ discount_wrapper.val(flt(this.frm.doc.additional_discount_percentage,
+ precision('additional_discount_percentage')));
+ discount_amt_wrapper.val(flt(this.frm.doc.discount_amount,
+ precision('discount_amount')));
+ }
+
set_selected_item($item) {
this.selected_item = $item;
this.$cart_items.find('.list-item').removeClass('current-item qty disc rate');
@@ -848,7 +861,7 @@
this.search_field = frappe.ui.form.make_control({
df: {
fieldtype: 'Data',
- label: 'Search Item (Ctrl + I)',
+ label: 'Search Item ( Ctrl + i )',
placeholder: 'Search by item code, serial number, batch no or barcode'
},
parent: this.wrapper.find('.search-field'),
@@ -945,16 +958,21 @@
if(serial_no) {
this.events.update_cart(items[0].item_code,
'serial_no', serial_no);
- this.search_field.set_value('');
+ this.reset_search_field();
}
if(batch_no) {
this.events.update_cart(items[0].item_code,
'batch_no', batch_no);
- this.search_field.set_value('');
+ this.reset_search_field();
}
});
}
+ reset_search_field() {
+ this.search_field.set_value('');
+ this.search_field.$input.trigger("input");
+ }
+
bind_events() {
var me = this;
this.wrapper.on('click', '.pos-item-wrapper', function() {
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 d74f1f0..5694ad9 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.py
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.py
@@ -24,6 +24,8 @@
if batch_no_data:
batch_no, item_code = batch_no_data
+ item_code, condition = get_conditions(item_code, serial_no, batch_no)
+
lft, rgt = frappe.db.get_value('Item Group', item_group, ['lft', 'rgt'])
# locate function is used to sort by closest match from the beginning of the value
res = frappe.db.sql("""select i.name as item_code, i.item_name, i.image as item_image,
@@ -36,11 +38,11 @@
where
i.disabled = 0 and i.has_variants = 0 and i.is_sales_item = 1
and i.item_group in (select name from `tabItem Group` where lft >= {lft} and rgt <= {rgt})
- and (i.item_code like %(item_code)s
- or i.item_name like %(item_code)s or i.barcode like %(item_code)s)
- limit {start}, {page_length}""".format(start=start, page_length=page_length, lft=lft, rgt=rgt),
+ and {condition}
+ limit {start}, {page_length}""".format(start=start,
+ page_length=page_length, lft=lft, rgt=rgt, condition=condition),
{
- 'item_code': '%%%s%%'%(frappe.db.escape(item_code)),
+ 'item_code': item_code,
'price_list': price_list
} , as_dict=1)
@@ -60,6 +62,15 @@
return res
+def get_conditions(item_code, serial_no, batch_no):
+ if serial_no or batch_no:
+ return frappe.db.escape(item_code), "i.item_code = %(item_code)s"
+
+ condition = """(i.item_code like %(item_code)s
+ or i.item_name like %(item_code)s or i.barcode like %(item_code)s)"""
+
+ return '%%%s%%'%(frappe.db.escape(item_code)), condition
+
@frappe.whitelist()
def submit_invoice(doc):
if isinstance(doc, basestring):