diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index f740befd5d3..a4323b87cfb 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -55,6 +55,16 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex }); erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype); + + if (this.frm.doc.pos_profile) { + frappe.db + .get_value("POS Profile", this.frm.doc.pos_profile, "set_grand_total_to_default_mop") + .then((r) => { + if (!r.exc) { + this.frm.set_default_payment = r.message.set_grand_total_to_default_mop; + } + }); + } } onload_post_render(frm) { @@ -120,6 +130,7 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex this.frm.meta.default_print_format = r.message.print_format || ""; this.frm.doc.campaign = r.message.campaign; this.frm.allow_print_before_pay = r.message.allow_print_before_pay; + this.frm.set_default_payment = r.message.set_default_payment; } this.frm.script_manager.trigger("update_stock"); this.calculate_taxes_and_totals(); diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index aac18100263..e23f3e2c7b9 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -732,6 +732,7 @@ class POSInvoice(SalesInvoice): "utm_campaign": profile.get("utm_campaign"), "utm_medium": profile.get("utm_medium"), "allow_print_before_pay": profile.get("allow_print_before_pay"), + "set_default_payment": profile.get("set_grand_total_to_default_mop"), } @frappe.whitelist() diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 98ba684eebb..b55e94a1dce 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -58,6 +58,13 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends ( me.frm.script_manager.trigger("is_pos"); me.frm.refresh_fields(); + frappe.db + .get_value("POS Profile", this.frm.doc.pos_profile, "set_grand_total_to_default_mop") + .then((r) => { + if (!r.exc) { + me.frm.set_default_payment = r.message.set_grand_total_to_default_mop; + } + }); } erpnext.queries.setup_warehouse_query(this.frm); } @@ -512,8 +519,9 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends ( }, callback: function (r) { if (!r.exc) { - if (r.message && r.message.print_format) { + if (r.message) { me.frm.pos_print_format = r.message.print_format; + me.frm.set_default_payment = r.message.set_default_payment; } me.frm.trigger("update_stock"); if (me.frm.doc.taxes_and_charges) { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index b2c87545800..929db4895ad 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -764,6 +764,7 @@ class SalesInvoice(SellingController): "utm_campaign": pos.get("utm_campaign"), "utm_medium": pos.get("utm_medium"), "allow_print_before_pay": pos.get("allow_print_before_pay"), + "set_default_payment": pos.get("set_grand_total_to_default_mop", 1), } @frappe.whitelist() diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 125f2ca8b65..c157753efb7 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -946,8 +946,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { set_default_payment(total_amount_to_pay, update_paid_amount) { var me = this; var payment_status = true; - if(this.frm.doc.is_pos && (update_paid_amount===undefined || update_paid_amount)) { - + const set_payment = flt(this.frm.doc.paid_amount) || cint(this.frm.set_default_payment); + if(this.frm.doc.is_pos && set_payment && (update_paid_amount===undefined || update_paid_amount)) { $.each(this.frm.doc['payments'] || [], function(index, data) { if(data.default && payment_status && total_amount_to_pay > 0) { let base_amount, amount; diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index 5c4efff1dc5..964886506f0 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -450,7 +450,6 @@ erpnext.PointOfSale.Payment = class { } render_payment_section() { - this.grand_total_to_default_mop(); this.render_payment_mode_dom(); this.make_invoice_field_dialog(); this.update_totals_section(); @@ -498,17 +497,6 @@ erpnext.PointOfSale.Payment = class { } } - grand_total_to_default_mop() { - if (this.set_gt_to_default_mop) return; - const doc = this.events.get_frm().doc; - const payments = doc.payments; - payments.forEach((p) => { - if (p.default) { - frappe.model.set_value(p.doctype, p.name, "amount", 0); - } - }); - } - render_payment_mode_dom() { const doc = this.events.get_frm().doc; const payments = doc.payments;