From 554f2de23d7af8faf2cd392004296d2722f8d0d7 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 20 Feb 2018 11:18:01 +0530 Subject: [PATCH] Code cleanup online POS (#12985) --- .../doctype/pos_profile/pos_profile.py | 2 +- .../doctype/sales_invoice/sales_invoice.js | 4 ++ .../page/point_of_sale/point_of_sale.js | 69 +++++++++---------- .../page/point_of_sale/point_of_sale.py | 13 ---- 4 files changed, 37 insertions(+), 51 deletions(-) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index 0bce49c016..20a90f4bfe 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -32,7 +32,7 @@ class POSProfile(Document): .format(res[0][0], row.user), raise_exception=1) elif not row.default and not res: msgprint(_("User {0} doesn't have any default POS Profile. Check Default at Row {1} for this User.") - .format(row.user, row.idx), raise_exception=1) + .format(row.user, row.idx)) def validate_all_link_fields(self): accounts = {"Account": [self.income_account, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 754fc6b177..93c22067d8 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -106,6 +106,10 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte on_submit: function(doc, dt, dn) { var me = this; + if (frappe.get_route()[0] != 'Sales Invoice') { + return + } + $.each(doc["items"], function(i, row) { if(row.delivery_note) frappe.model.clear_doc("Delivery Note", row.delivery_note) }) 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 9484dc7029..d1f6b7a7c2 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -256,17 +256,22 @@ erpnext.pos.PointOfSale = class PointOfSale { if (field == 'qty' && value < 0) { frappe.msgprint(__("Quantity must be positive")); value = item.qty; + } else { + item[field] = value; + if (field == "serial_no" && value) { + let serial_nos = value.split("\n"); + item["qty"] = serial_nos.filter(d => { + return d!==""; + }).length; + } } - if (field) { - return frappe.model.set_value(item.doctype, item.name, field, value) - .then(() => this.frm.script_manager.trigger('qty', item.doctype, item.name)) - .then(() => { - if (field === 'qty' && item.qty === 0) { - frappe.model.clear_doc(item.doctype, item.name); - } - }) - } + return this.frm.script_manager.trigger('qty', item.doctype, item.name) + .then(() => { + if (field === 'qty' && item.qty === 0) { + frappe.model.clear_doc(item.doctype, item.name); + } + }) return Promise.resolve(); } @@ -283,20 +288,13 @@ erpnext.pos.PointOfSale = class PointOfSale { } submit_sales_invoice() { - - frappe.confirm(__("Permanently Submit {0}?", [this.frm.doc.name]), () => { - frappe.call({ - method: 'erpnext.selling.page.point_of_sale.point_of_sale.submit_invoice', - freeze: true, - args: { - doc: this.frm.doc - } - }).then(r => { - if(r.message) { - this.frm.doc = r.message; + this.frm.savesubmit() + .then((r) => { + if (r && r.doc) { + this.frm.doc.docstatus = r.doc.docstatus; frappe.show_alert({ indicator: 'green', - message: __(`Sales invoice ${r.message.name} created succesfully`) + message: __(`Sales invoice ${r.doc.name} created succesfully`) }); this.toggle_editing(); @@ -304,21 +302,22 @@ erpnext.pos.PointOfSale = class PointOfSale { this.set_primary_action_in_modal(); } }); - }); } set_primary_action_in_modal() { - this.frm.msgbox = frappe.msgprint( - ` - ${__('Print')} - - ${__('New')}` - ); + if (!this.frm.msgbox) { + this.frm.msgbox = frappe.msgprint( + ` + ${__('Print')} + + ${__('New')}` + ); - $(this.frm.msgbox.body).find('.btn-default').on('click', () => { - this.frm.msgbox.hide(); - this.make_new_invoice(); - }) + $(this.frm.msgbox.body).find('.btn-default').on('click', () => { + this.frm.msgbox.hide(); + this.make_new_invoice(); + }) + } } change_pos_profile() { @@ -487,11 +486,6 @@ erpnext.pos.PointOfSale = class PointOfSale { // // }).addClass('visible-xs'); - this.page.add_menu_item(__("Form View"), function () { - frappe.model.sync(me.frm.doc); - frappe.set_route("Form", me.frm.doc.doctype, me.frm.doc.name); - }); - this.page.add_menu_item(__("POS Profile"), function () { frappe.set_route('List', 'POS Profile'); }); @@ -589,6 +583,7 @@ class POSCart { this.$taxes_and_totals.html(this.get_taxes_and_totals()); this.numpad && this.numpad.reset_value(); this.customer_field.set_value(""); + this.frm.msgbox = ""; this.$discount_amount.find('input:text').val(''); this.wrapper.find('.grand-total-value').text( 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 d98a01706e..8654287208 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -87,19 +87,6 @@ def get_conditions(item_code, serial_no, batch_no, barcode): return '%%%s%%'%(frappe.db.escape(item_code)), condition -@frappe.whitelist() -def submit_invoice(doc): - if isinstance(doc, basestring): - args = json.loads(doc) - - doc = frappe.new_doc('Sales Invoice') - doc.update(args) - doc.run_method("set_missing_values") - doc.run_method("calculate_taxes_and_totals") - doc.submit() - - return doc - def get_item_group_condition(pos_profile): cond = "and 1=1" item_groups = get_item_groups(pos_profile)