From d4359faa3153cf9b0bd8f3e02c73407699976b4b Mon Sep 17 00:00:00 2001 From: Jay Parikh Date: Thu, 1 Feb 2018 04:26:24 -0800 Subject: [PATCH 1/3] Enable/Disable Discount in POS using POS Profile #11748 --- .../doctype/pos_profile/pos_profile.json | 32 ++++++++++++++- .../doctype/sales_invoice/sales_invoice.py | 3 +- .../page/point_of_sale/point_of_sale.js | 40 ++++++++++++++----- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index 2cb8e1024a..ed3de07140 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -254,6 +254,36 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "allow_user_to_edit_discount", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Allow user to edit Discount", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -1476,7 +1506,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-01-03 17:30:45.198147", + "modified": "2018-01-31 19:33:11.765731", "modified_by": "Administrator", "module": "Accounts", "name": "POS Profile", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index f37fe6114c..2af30e1956 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -249,7 +249,8 @@ class SalesInvoice(SellingController): if pos: return { "print_format": pos.get("print_format_for_online"), - "allow_edit_rate": pos.get("allow_user_to_edit_rate") + "allow_edit_rate": pos.get("allow_user_to_edit_rate"), + "allow_edit_discount": pos.get("allow_user_to_edit_discount") } def update_time_sheet(self, sales_invoice): 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 f5bc6c2499..bfbb6ad405 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -464,6 +464,7 @@ erpnext.pos.PointOfSale = class PointOfSale { if (r.message) { this.frm.meta.default_print_format = r.message.print_format || 'POS Invoice'; this.frm.allow_edit_rate = r.message.allow_edit_rate; + this.frm.allow_edit_discount = r.message.allow_edit_discount; } } @@ -553,9 +554,9 @@ class POSCart {
${this.get_taxes_and_totals()}
-
- ${this.get_discount_amount()} -
+
`+ + (!this.frm.allow_edit_discount ? `` : `${this.get_discount_amount()}`)+ + `
${this.get_grand_total()}
@@ -714,6 +715,21 @@ class POSCart { this.customer_field.set_value(this.frm.doc.customer); } + disable_numpad_control() { + if(!this.frm.allow_edit_rate && !this.frm.allow_edit_discount) { + return ['Rate', 'Disc']; + } + if(!this.frm.allow_edit_rate || !this.frm.allow_edit_discount) { + if(!this.frm.allow_edit_rate) { + return ['Rate']; + } else { + return ['Disc']; + } + } else { + return []; + } + } + make_numpad() { this.numpad = new NumberPad({ button_array: [ @@ -728,7 +744,7 @@ class POSCart { disable_highlight: ['Qty', 'Disc', 'Rate', 'Pay'], reset_btns: ['Qty', 'Disc', 'Rate', 'Pay'], del_btn: 'Del', - disable_btns: !this.frm.allow_edit_rate ? ['Rate']: [], + disable_btns: this.disable_numpad_control(), wrapper: this.wrapper.find('.number-pad-container'), onclick: (btn_value) => { // on click @@ -1300,13 +1316,15 @@ class NumberPad { this.set_class(); - this.disable_btns.forEach((btn) => { - const $btn = this.get_btn(btn); - $btn.prop("disabled", true) - $btn.hover(() => { - $btn.css('cursor','not-allowed'); - }) - }) + if(this.disable_btns) { + this.disable_btns.forEach((btn) => { + const $btn = this.get_btn(btn); + $btn.prop("disabled", true) + $btn.hover(() => { + $btn.css('cursor','not-allowed'); + }) + }) + } } set_class() { From 171e5af995a8b2de1db5603d8f56b1b8cb13bf1f Mon Sep 17 00:00:00 2001 From: Jay Parikh Date: Thu, 1 Feb 2018 21:39:20 -0800 Subject: [PATCH 2/3] Fixed indentation issue in pull # 11748 --- .../page/point_of_sale/point_of_sale.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 bfbb6ad405..70e45f9512 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -464,7 +464,7 @@ erpnext.pos.PointOfSale = class PointOfSale { if (r.message) { this.frm.meta.default_print_format = r.message.print_format || 'POS Invoice'; this.frm.allow_edit_rate = r.message.allow_edit_rate; - this.frm.allow_edit_discount = r.message.allow_edit_discount; + this.frm.allow_edit_discount = r.message.allow_edit_discount; } } @@ -715,7 +715,7 @@ class POSCart { this.customer_field.set_value(this.frm.doc.customer); } - disable_numpad_control() { + disable_numpad_control() { if(!this.frm.allow_edit_rate && !this.frm.allow_edit_discount) { return ['Rate', 'Disc']; } @@ -1316,15 +1316,15 @@ class NumberPad { this.set_class(); - if(this.disable_btns) { - this.disable_btns.forEach((btn) => { - const $btn = this.get_btn(btn); - $btn.prop("disabled", true) - $btn.hover(() => { - $btn.css('cursor','not-allowed'); - }) - }) - } + if(this.disable_btns) { + this.disable_btns.forEach((btn) => { + const $btn = this.get_btn(btn); + $btn.prop("disabled", true) + $btn.hover(() => { + $btn.css('cursor','not-allowed'); + }) + }) + } } set_class() { From 2c95ab3897571bdfa63e62d0c7ac73dd91db50c6 Mon Sep 17 00:00:00 2001 From: Jay Parikh Date: Thu, 1 Feb 2018 22:52:58 -0800 Subject: [PATCH 3/3] Code fix for Enable/Disable Discount in POS using POS Profile #11748 --- .../page/point_of_sale/point_of_sale.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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 70e45f9512..bc7ebf3abe 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -464,7 +464,7 @@ erpnext.pos.PointOfSale = class PointOfSale { if (r.message) { this.frm.meta.default_print_format = r.message.print_format || 'POS Invoice'; this.frm.allow_edit_rate = r.message.allow_edit_rate; - this.frm.allow_edit_discount = r.message.allow_edit_discount; + this.frm.allow_edit_discount = r.message.allow_edit_discount; } } @@ -585,6 +585,7 @@ class POSCart { this.numpad && this.numpad.reset_value(); this.customer_field.set_value(""); + this.$discount_amount.find('input:text').val(''); this.wrapper.find('.grand-total-value').text( format_currency(this.frm.doc.grand_total, this.frm.currency)); this.wrapper.find('.rounded-total-value').text( @@ -715,19 +716,15 @@ class POSCart { this.customer_field.set_value(this.frm.doc.customer); } - disable_numpad_control() { - if(!this.frm.allow_edit_rate && !this.frm.allow_edit_discount) { - return ['Rate', 'Disc']; + disable_numpad_control() { + let disabled_btns = []; + if(!this.frm.allow_edit_rate) { + disabled_btns.push('Rate'); } - if(!this.frm.allow_edit_rate || !this.frm.allow_edit_discount) { - if(!this.frm.allow_edit_rate) { - return ['Rate']; - } else { - return ['Disc']; - } - } else { - return []; + if(!this.frm.allow_edit_discount) { + disabled_btns.push('Disc'); } + return disabled_btns; } make_numpad() {