mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-01 12:38:27 +00:00
fix: use grand_total_diff instead of rounding_adjustment in taxes_and_totals
(cherry picked from commit fd252da6b1)
This commit is contained in:
@@ -377,9 +377,7 @@ class calculate_taxes_and_totals:
|
|||||||
self._calculate()
|
self._calculate()
|
||||||
|
|
||||||
def calculate_taxes(self):
|
def calculate_taxes(self):
|
||||||
rounding_adjustment_computed = self.doc.get("is_consolidated") and self.doc.get("rounding_adjustment")
|
self.grand_total_diff = 0
|
||||||
if not rounding_adjustment_computed:
|
|
||||||
self.doc.rounding_adjustment = 0
|
|
||||||
|
|
||||||
# maintain actual tax rate based on idx
|
# maintain actual tax rate based on idx
|
||||||
actual_tax_dict = dict(
|
actual_tax_dict = dict(
|
||||||
@@ -446,9 +444,8 @@ class calculate_taxes_and_totals:
|
|||||||
and self.discount_amount_applied
|
and self.discount_amount_applied
|
||||||
and self.doc.discount_amount
|
and self.doc.discount_amount
|
||||||
and self.doc.apply_discount_on == "Grand Total"
|
and self.doc.apply_discount_on == "Grand Total"
|
||||||
and not rounding_adjustment_computed
|
|
||||||
):
|
):
|
||||||
self.doc.rounding_adjustment = flt(
|
self.grand_total_diff = flt(
|
||||||
self.doc.grand_total - flt(self.doc.discount_amount) - tax.total,
|
self.doc.grand_total - flt(self.doc.discount_amount) - tax.total,
|
||||||
self.doc.precision("rounding_adjustment"),
|
self.doc.precision("rounding_adjustment"),
|
||||||
)
|
)
|
||||||
@@ -552,11 +549,11 @@ class calculate_taxes_and_totals:
|
|||||||
return self.adjust_grand_total_for_inclusive_tax()
|
return self.adjust_grand_total_for_inclusive_tax()
|
||||||
|
|
||||||
def adjust_grand_total_for_inclusive_tax(self):
|
def adjust_grand_total_for_inclusive_tax(self):
|
||||||
# if fully inclusive taxes and diff
|
# if any inclusive taxes and diff
|
||||||
if self.doc.get("taxes") and any(cint(t.included_in_print_rate) for t in self.doc.get("taxes")):
|
if self.doc.get("taxes") and any(cint(t.included_in_print_rate) for t in self.doc.get("taxes")):
|
||||||
last_tax = self.doc.get("taxes")[-1]
|
last_tax = self.doc.get("taxes")[-1]
|
||||||
non_inclusive_tax_amount = sum(
|
non_inclusive_tax_amount = sum(
|
||||||
flt(d.tax_amount_after_discount_amount)
|
self.get_tax_amount_if_for_valuation_or_deduction(d.tax_amount_after_discount_amount, d)
|
||||||
for d in self.doc.get("taxes")
|
for d in self.doc.get("taxes")
|
||||||
if not d.included_in_print_rate
|
if not d.included_in_print_rate
|
||||||
)
|
)
|
||||||
@@ -573,27 +570,23 @@ class calculate_taxes_and_totals:
|
|||||||
diff = flt(diff, self.doc.precision("rounding_adjustment"))
|
diff = flt(diff, self.doc.precision("rounding_adjustment"))
|
||||||
|
|
||||||
if diff and abs(diff) <= (5.0 / 10 ** last_tax.precision("tax_amount")):
|
if diff and abs(diff) <= (5.0 / 10 ** last_tax.precision("tax_amount")):
|
||||||
self.doc.grand_total_diff = diff
|
self.grand_total_diff = diff
|
||||||
else:
|
|
||||||
self.doc.grand_total_diff = 0
|
|
||||||
|
|
||||||
def calculate_totals(self):
|
def calculate_totals(self):
|
||||||
if self.doc.get("taxes"):
|
if self.doc.get("taxes"):
|
||||||
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + flt(
|
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + self.grand_total_diff
|
||||||
self.doc.get("grand_total_diff")
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.doc.grand_total = flt(self.doc.net_total)
|
self.doc.grand_total = flt(self.doc.net_total)
|
||||||
|
|
||||||
if self.doc.get("taxes"):
|
if self.doc.get("taxes"):
|
||||||
self.doc.total_taxes_and_charges = flt(
|
self.doc.total_taxes_and_charges = flt(
|
||||||
self.doc.grand_total - self.doc.net_total - flt(self.doc.get("grand_total_diff")),
|
self.doc.grand_total - self.doc.net_total - self.grand_total_diff,
|
||||||
self.doc.precision("total_taxes_and_charges"),
|
self.doc.precision("total_taxes_and_charges"),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.doc.total_taxes_and_charges = 0.0
|
self.doc.total_taxes_and_charges = 0.0
|
||||||
|
|
||||||
self._set_in_company_currency(self.doc, ["total_taxes_and_charges", "rounding_adjustment"])
|
self._set_in_company_currency(self.doc, ["total_taxes_and_charges"])
|
||||||
|
|
||||||
if self.doc.doctype in [
|
if self.doc.doctype in [
|
||||||
"Quotation",
|
"Quotation",
|
||||||
@@ -643,7 +636,9 @@ class calculate_taxes_and_totals:
|
|||||||
|
|
||||||
if self.doc.meta.get_field("rounded_total"):
|
if self.doc.meta.get_field("rounded_total"):
|
||||||
if self.doc.is_rounded_total_disabled():
|
if self.doc.is_rounded_total_disabled():
|
||||||
self.doc.rounded_total = self.doc.base_rounded_total = 0
|
self.doc.rounded_total = 0
|
||||||
|
self.doc.base_rounded_total = 0
|
||||||
|
self.doc.rounding_adjustment = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
self.doc.rounded_total = round_based_on_smallest_currency_fraction(
|
self.doc.rounded_total = round_based_on_smallest_currency_fraction(
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
calculate_taxes() {
|
calculate_taxes() {
|
||||||
var me = this;
|
var me = this;
|
||||||
this.frm.doc.rounding_adjustment = 0;
|
this.grand_total_diff = 0;
|
||||||
var actual_tax_dict = {};
|
var actual_tax_dict = {};
|
||||||
|
|
||||||
// maintain actual tax rate based on idx
|
// maintain actual tax rate based on idx
|
||||||
@@ -417,7 +417,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
// adjust Discount Amount loss in last tax iteration
|
// adjust Discount Amount loss in last tax iteration
|
||||||
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied
|
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied
|
||||||
&& me.frm.doc.apply_discount_on == "Grand Total" && me.frm.doc.discount_amount) {
|
&& me.frm.doc.apply_discount_on == "Grand Total" && me.frm.doc.discount_amount) {
|
||||||
me.frm.doc.rounding_adjustment = flt(me.frm.doc.grand_total -
|
me.grand_total_diff = flt(me.frm.doc.grand_total -
|
||||||
flt(me.frm.doc.discount_amount) - tax.total, precision("rounding_adjustment"));
|
flt(me.frm.doc.discount_amount) - tax.total, precision("rounding_adjustment"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -535,7 +535,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
adjust_grand_total_for_inclusive_tax() {
|
adjust_grand_total_for_inclusive_tax() {
|
||||||
var me = this;
|
var me = this;
|
||||||
// if fully inclusive taxes and diff
|
|
||||||
|
// if any inclusive taxes and diff
|
||||||
if (this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
|
if (this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
|
||||||
var any_inclusive_tax = false;
|
var any_inclusive_tax = false;
|
||||||
$.each(this.frm.doc.taxes || [], function(i, d) {
|
$.each(this.frm.doc.taxes || [], function(i, d) {
|
||||||
@@ -546,7 +547,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
var non_inclusive_tax_amount = frappe.utils.sum($.map(this.frm.doc.taxes || [],
|
var non_inclusive_tax_amount = frappe.utils.sum($.map(this.frm.doc.taxes || [],
|
||||||
function(d) {
|
function(d) {
|
||||||
if(!d.included_in_print_rate) {
|
if(!d.included_in_print_rate) {
|
||||||
return flt(d.tax_amount_after_discount_amount);
|
let tax_amount = d.category === "Valuation" ? 0 : d.tax_amount_after_discount_amount;
|
||||||
|
if (d.add_deduct_tax === "Deduct") tax_amount *= -1;
|
||||||
|
return tax_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@@ -560,9 +563,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
diff = flt(diff, precision("rounding_adjustment"));
|
diff = flt(diff, precision("rounding_adjustment"));
|
||||||
|
|
||||||
if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) {
|
if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) {
|
||||||
me.frm.doc.grand_total_diff = diff;
|
me.grand_total_diff = diff;
|
||||||
} else {
|
|
||||||
me.frm.doc.grand_total_diff = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -573,7 +574,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
var me = this;
|
var me = this;
|
||||||
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
|
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
|
||||||
this.frm.doc.grand_total = flt(tax_count
|
this.frm.doc.grand_total = flt(tax_count
|
||||||
? this.frm.doc["taxes"][tax_count - 1].total + flt(this.frm.doc.grand_total_diff)
|
? this.frm.doc["taxes"][tax_count - 1].total + this.grand_total_diff
|
||||||
: this.frm.doc.net_total);
|
: this.frm.doc.net_total);
|
||||||
|
|
||||||
if(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) {
|
if(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) {
|
||||||
@@ -605,9 +606,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total
|
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total
|
||||||
- flt(this.frm.doc.grand_total_diff), precision("total_taxes_and_charges"));
|
- this.grand_total_diff, precision("total_taxes_and_charges"));
|
||||||
|
|
||||||
this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges", "rounding_adjustment"]);
|
this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
|
||||||
|
|
||||||
// Round grand total as per precision
|
// Round grand total as per precision
|
||||||
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "base_grand_total"]);
|
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "base_grand_total"]);
|
||||||
@@ -627,6 +628,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
if (cint(disable_rounded_total)) {
|
if (cint(disable_rounded_total)) {
|
||||||
this.frm.doc.rounded_total = 0;
|
this.frm.doc.rounded_total = 0;
|
||||||
this.frm.doc.base_rounded_total = 0;
|
this.frm.doc.base_rounded_total = 0;
|
||||||
|
this.frm.doc.rounding_adjustment = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user