diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.js b/erpnext/accounts/doctype/pos_profile/pos_profile.js index cb52627cf0..25aff13693 100755 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.js +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.js @@ -24,11 +24,11 @@ frappe.ui.form.on("POS Profile", "onload", function(frm) { frappe.ui.form.on('POS Profile', { setup: function(frm) { - frm.set_query("online_print_format", function() { + frm.set_query("print_format_for_online", function() { return { filters: [ ['Print Format', 'doc_type', '=', 'Sales Invoice'], - ['Print Format', 'print_format_type', '!=', 'Js'], + ['Print Format', 'print_format_type', '=', 'Server'], ] }; }); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index db9969d133..83d5103020 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -247,7 +247,7 @@ class SalesInvoice(SellingController): super(SalesInvoice, self).set_missing_values(for_validate) if pos: - return {"print_format": pos.get("print_format") } + return {"print_format": pos.get("print_format_for_online") } def update_time_sheet(self, sales_invoice): for d in self.timesheets: 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 b167bcda6c..0a70bb905a 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -53,8 +53,6 @@ erpnext.pos.PointOfSale = class PointOfSale { () => this.setup_pos_profile(), () => this.make_new_invoice(), () => { - frappe.timeout(1); - this.make_items(); this.bind_events(); frappe.dom.unfreeze(); }, @@ -323,16 +321,20 @@ erpnext.pos.PointOfSale = class PointOfSale { make_new_invoice() { return frappe.run_serially([ - () => this.make_sales_invoice_frm(), () => { - if (this.cart) { - this.cart.frm = this.frm; - this.cart.reset(); - } else { - this.make_cart(); - } - this.toggle_editing(true); - } + this.make_sales_invoice_frm() + .then(() => this.set_pos_profile_data()) + .then(() => { + if (this.cart) { + this.cart.frm = this.frm; + this.cart.reset(); + } else { + this.make_items(); + this.make_cart(); + } + this.toggle_editing(true); + }) + }, ]); } @@ -359,12 +361,29 @@ erpnext.pos.PointOfSale = class PointOfSale { if(!frm.doc.company) { frm.set_value('company', pos_profile.company); } - frm.set_value('is_pos', 1); - frm.meta.default_print_format = 'POS Invoice'; + frm.doc.is_pos = 1; return frm; } } + set_pos_profile_data() { + return new Promise(resolve => { + return this.frm.call({ + doc: this.frm.doc, + method: "set_missing_values", + }).then((r) => { + if(!r.exc) { + this.frm.script_manager.trigger("update_stock"); + frappe.model.set_default_values(this.frm.doc); + this.frm.cscript.calculate_taxes_and_totals(); + this.frm.meta.default_print_format = r.message.print_format || 'POS Invoice'; + } + + resolve(); + }) + }) + } + prepare_menu() { var me = this; this.page.clear_menu(); @@ -392,9 +411,6 @@ erpnext.pos.PointOfSale = class PointOfSale { if(this.frm.doc.docstatus !== 1) return; this.page.set_secondary_action(__("Print"), () => { - if (this.pos_profile && this.pos_profile.print_format_for_online) { - this.frm.meta.default_print_format = this.pos_profile.print_format_for_online; - } this.frm.print_preview.printit(true); }); @@ -1264,6 +1280,16 @@ class Payment { $(this.dialog.body).find('.input-with-feedback').focusin(function() { me.numpad.reset_value(); me.fieldname = $(this).prop('dataset').fieldname; + if (me.frm.doc.outstanding_amount > 0 && + !in_list(['write_off_amount', 'change_amount'], me.fieldname)) { + me.frm.doc.payments.forEach((data) => { + if (data.mode_of_payment == me.fieldname && !data.amount) { + me.dialog.set_value(me.fieldname, + me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate); + return; + } + }) + } }); } @@ -1403,4 +1429,4 @@ class Payment { this.dialog.set_value("paid_amount", this.frm.doc.paid_amount); this.dialog.set_value("outstanding_amount", this.frm.doc.outstanding_amount); } -} +} \ No newline at end of file