diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index ab40e8c496..91997d9121 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -297,6 +297,36 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "allow_print_before_pay", + "fieldtype": "Check", + "hidden": 1, + "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 Print Before Pay ", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 1, + "print_hide_if_no_value": 0, + "read_only": 1, + "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, @@ -4563,7 +4593,7 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2018-01-11 14:02:48.829906", + "modified": "2018-01-09 09:48:00.152026", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index f6d43c7f70..bf6ad49d0e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -304,6 +304,8 @@ class SalesInvoice(SellingController): self.account_for_change_amount = frappe.db.get_value('Company', self.company, 'default_cash_account') if pos: + self.allow_print_before_pay = pos.allow_print_before_pay + if not for_validate and not self.customer: self.customer = pos.customer 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 0876228d42..29238ea805 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -50,7 +50,6 @@ erpnext.pos.PointOfSale = class PointOfSale { this.set_online_status(); }, () => this.setup_company(), - () => this.make_new_invoice(), () => { frappe.dom.unfreeze(); @@ -111,6 +110,7 @@ erpnext.pos.PointOfSale = class PointOfSale { }, on_select_change: () => { this.cart.numpad.set_inactive(); + this.set_form_action(); }, get_item_details: (item_code) => { return this.items.get(item_code); @@ -180,6 +180,7 @@ erpnext.pos.PointOfSale = class PointOfSale { .then(() => { // update cart this.update_cart_data(item); + this.set_form_action(); }); } return; @@ -278,13 +279,17 @@ erpnext.pos.PointOfSale = class PointOfSale { } submit_sales_invoice() { - + var is_saved = 0; + if(!this.frm.doc.__islocal){ + is_saved = 1; + } 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 + doc: this.frm.doc, + is_saved: is_saved } }).then(r => { if(r.message) { @@ -499,19 +504,26 @@ erpnext.pos.PointOfSale = class PointOfSale { } set_form_action() { - if(this.frm.doc.docstatus !== 1) return; + if(this.frm.doc.docstatus == 1 || (this.frm.doc.allow_print_before_pay == 1&&this.frm.doc.items.length>0)){ + this.page.set_secondary_action(__("Print"), async() => { + if(this.frm.doc.docstatus != 1 ){ + await this.frm.save(); + } + this.frm.print_preview.printit(true); + }); + } + if(this.frm.doc.items.length == 0){ + this.page.clear_secondary_action(); + } - this.page.set_secondary_action(__("Print"), () => { - this.frm.print_preview.printit(true); - }); - - this.page.set_primary_action(__("New"), () => { - this.make_new_invoice(); - }); - - this.page.add_menu_item(__("Email"), () => { - this.frm.email_doc(); - }); + if (this.frm.doc.docstatus == 1) { + this.page.set_primary_action(__("New"), () => { + this.make_new_invoice(); + }); + this.page.add_menu_item(__("Email"), () => { + this.frm.email_doc(); + }); + } } }; 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..4f0d250236 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe, json from frappe.utils.nestedset import get_root_of +from frappe.utils import cint from erpnext.accounts.doctype.pos_profile.pos_profile import get_item_groups @frappe.whitelist() @@ -88,11 +89,15 @@ def get_conditions(item_code, serial_no, batch_no, barcode): return '%%%s%%'%(frappe.db.escape(item_code)), condition @frappe.whitelist() -def submit_invoice(doc): +def submit_invoice(doc,is_saved): if isinstance(doc, basestring): args = json.loads(doc) - doc = frappe.new_doc('Sales Invoice') + if(cint(is_saved) == 1): + doc = frappe.get_doc('Sales Invoice',args["name"]) + else: + doc = frappe.new_doc('Sales Invoice') + doc.update(args) doc.run_method("set_missing_values") doc.run_method("calculate_taxes_and_totals") @@ -123,4 +128,4 @@ def item_group_query(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql(""" select distinct name from `tabItem Group` where {condition} and (name like %(txt)s) limit {start}, {page_len}""" .format(condition = cond, start=start, page_len= page_len), - {'txt': '%%%s%%' % txt}) + {'txt': '%%%s%%' % txt}) \ No newline at end of file