Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update grand total based on disable rounded total checkbox #44282

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4194,6 +4194,13 @@ def test_gl_voucher_subtype(self):

self.assertTrue(all([x == "Credit Note" for x in gl_entries]))

def test_outstanding_with_rounded_total_as_zero(self):
si = create_sales_invoice(qty=1, rate=0.05, do_not_submit=True)
si.save()
self.assertEqual(si.outstanding_amount, 0)
si.submit()
self.assertEqual(si.status, "Paid")


def set_advance_flag(company, flag, default_account):
frappe.db.set_value(
Expand Down
16 changes: 11 additions & 5 deletions erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def calculate_total_advance(self):

self.doc.total_advance = flt(total_allocated_amount, self.doc.precision("total_advance"))

grand_total = self.doc.rounded_total or self.doc.grand_total
grand_total = self.doc.grand_total if self.doc.disable_rounded_total else self.doc.rounded_total

if self.doc.party_account_currency == self.doc.currency:
invoice_total = flt(
Expand Down Expand Up @@ -843,8 +843,11 @@ def calculate_outstanding_amount(self):
self._set_in_company_currency(self.doc, ["write_off_amount"])

if self.doc.doctype in ["Sales Invoice", "Purchase Invoice"]:
grand_total = self.doc.rounded_total or self.doc.grand_total
base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total
grand_total = self.doc.rounded_total
base_grand_total = self.doc.base_rounded_total
if self.doc.disable_rounded_total:
grand_total = self.doc.grand_total
base_grand_total = self.doc.base_grand_total

if self.doc.party_account_currency == self.doc.currency:
total_amount_to_pay = flt(
Expand Down Expand Up @@ -924,8 +927,11 @@ def calculate_paid_amount(self):
def calculate_change_amount(self):
self.doc.change_amount = 0.0
self.doc.base_change_amount = 0.0
grand_total = self.doc.rounded_total or self.doc.grand_total
base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total
grand_total = self.doc.rounded_total
base_grand_total = self.doc.base_rounded_total
if self.doc.disable_rounded_total:
grand_total = self.doc.grand_total
base_grand_total = self.doc.base_grand_total

if (
self.doc.doctype == "Sales Invoice"
Expand Down
26 changes: 18 additions & 8 deletions erpnext/public/js/controllers/taxes_and_totals.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount"]);

if(["Sales Invoice", "POS Invoice", "Purchase Invoice"].includes(this.frm.doc.doctype)) {
let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
let grand_total = this.frm.doc.rounded_total
let base_grand_total = this.frm.doc.base_rounded_total
if (this.frm.doc.disable_rounded_total) {
grand_total = this.frm.doc.grand_total
base_grand_total = this.frm.doc.base_grand_total
}

if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
var total_amount_to_pay = flt((grand_total - this.frm.doc.total_advance
Expand Down Expand Up @@ -832,9 +836,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
}

set_total_amount_to_default_mop() {
let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;

let grand_total = this.frm.doc.rounded_total
let base_grand_total = this.frm.doc.base_rounded_total
if (this.frm.doc.disable_rounded_total) {
grand_total = this.frm.doc.grand_total
base_grand_total = this.frm.doc.base_grand_total
}
if (this.frm.doc.party_account_currency == this.frm.doc.currency) {
var total_amount_to_pay = flt(
grand_total - this.frm.doc.total_advance - this.frm.doc.write_off_amount,
Expand Down Expand Up @@ -924,9 +931,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {

var payment_types = $.map(this.frm.doc.payments, function(d) { return d.type; });
if (in_list(payment_types, 'Cash')) {
var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
var base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;

let grand_total = this.frm.doc.rounded_total
let base_grand_total = this.frm.doc.base_rounded_total
if (this.frm.doc.disable_rounded_total) {
grand_total = this.frm.doc.grand_total
base_grand_total = this.frm.doc.base_grand_total
}
this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total,
precision("change_amount"));

Expand Down
3 changes: 3 additions & 0 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
frm.cscript.calculate_taxes_and_totals();
});

frappe.ui.form.on(this.frm.doctype, "disable_rounded_total", function(frm) {
cur_frm.cscript.calculate_taxes_and_totals();
});
frappe.ui.form.on(this.frm.doctype + " Item", {
items_add: function(frm, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
Expand Down
Loading