Inclusive tax for deduction and manipulation of tax amount to fix rounding issue
This commit is contained in:
parent
9726447169
commit
a6ee8290ce
File diff suppressed because it is too large
Load Diff
@ -159,6 +159,9 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
this.calculate_taxes_and_totals();
|
||||
}
|
||||
},
|
||||
add_deduct_tax: function(doc, cdt, cdn) {
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
calculate_outstanding_amount: function() {
|
||||
if(this.frm.doc.doctype == "Purchase Invoice" && this.frm.doc.docstatus < 2) {
|
||||
|
@ -116,21 +116,8 @@ class calculate_taxes_and_totals(object):
|
||||
item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
|
||||
item.discount_percentage = flt(item.discount_percentage, item.precision("discount_percentage"))
|
||||
|
||||
|
||||
self._set_in_company_currency(item, ["net_rate", "net_amount"])
|
||||
|
||||
# below part need to be fixed???
|
||||
|
||||
# if item.discount_percentage == 100:
|
||||
# item.price_list_rate = item.net_rate
|
||||
# item.base_price_list_rate = flt(item.price_list_rate*self.doc.conversion_rate,
|
||||
# self.doc.precision("base_price_list_rate", item))
|
||||
# item.rate = item.base_rate = item.net_rate = item.base_net_rate = 0.0
|
||||
# else:
|
||||
# item.base_price_list_rate = flt(item.net_rate / (1 - (item.discount_percentage / 100.0)),
|
||||
# self.doc.precision("price_list_rate", item))
|
||||
|
||||
|
||||
def _load_item_tax_rate(self, item_tax_rate):
|
||||
return json.loads(item_tax_rate) if item_tax_rate else {}
|
||||
|
||||
@ -155,6 +142,8 @@ class calculate_taxes_and_totals(object):
|
||||
current_tax_fraction = (tax_rate / 100.0) * \
|
||||
self.doc.get("taxes")[cint(tax.row_id) - 1].grand_total_fraction_for_current_item
|
||||
|
||||
if getattr(tax, "add_deduct_tax", None):
|
||||
current_tax_fraction *= -1.0 if (tax.add_deduct_tax == "Deduct") else 1.0
|
||||
return current_tax_fraction
|
||||
|
||||
def _get_tax_rate(self, tax, item_tax_map):
|
||||
@ -286,17 +275,13 @@ class calculate_taxes_and_totals(object):
|
||||
def manipulate_grand_total_for_inclusive_tax(self):
|
||||
# if fully inclusive taxes and diff
|
||||
if self.doc.get("taxes") and all(cint(t.included_in_print_rate) for t in self.doc.get("taxes")):
|
||||
|
||||
last_tax = self.doc.get("taxes")[-1]
|
||||
|
||||
diff = self.doc.net_total - flt(last_tax.total / self.doc.conversion_rate,
|
||||
self.doc.precision("grand_total"))
|
||||
diff = self.doc.total - flt(last_tax.total, self.doc.precision("grand_total"))
|
||||
|
||||
if diff and abs(diff) <= (2.0 / 10**last_tax.precision("tax_amount")):
|
||||
adjustment_amount = flt(diff * self.doc.conversion_rate, last_tax.precision("tax_amount"))
|
||||
last_tax.tax_amount += adjustment_amount
|
||||
last_tax.tax_amount_after_discount_amount += adjustment_amount
|
||||
last_tax.total += adjustment_amount
|
||||
last_tax.tax_amount += diff
|
||||
last_tax.tax_amount_after_discount_amount += diff
|
||||
last_tax.total += diff
|
||||
|
||||
def calculate_totals(self):
|
||||
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total
|
||||
|
@ -135,14 +135,6 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
|
||||
|
||||
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
||||
|
||||
// if(item.discount_percentage == 100) {
|
||||
// item.base_price_list_rate = item.base_rate;
|
||||
// item.base_rate = 0.0;
|
||||
// } else {
|
||||
// item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
|
||||
// precision("base_price_list_rate", item));
|
||||
// }
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -168,6 +160,9 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
}
|
||||
}
|
||||
|
||||
if(tax.add_deduct_tax) {
|
||||
current_tax_fraction *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0;
|
||||
}
|
||||
return current_tax_fraction;
|
||||
},
|
||||
|
||||
@ -332,15 +327,12 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
if (all_inclusive) {
|
||||
var last_tax = me.frm.doc["taxes"].slice(-1)[0];
|
||||
|
||||
var diff = me.frm.doc.net_total
|
||||
- flt(last_tax.total / me.frm.doc.conversion_rate, precision("grand_total"));
|
||||
var diff = me.frm.doc.total - flt(last_tax.total, precision("grand_total"));
|
||||
|
||||
if ( diff && Math.abs(diff) <= (2.0 / Math.pow(10, precision("tax_amount", last_tax))) ) {
|
||||
var adjustment_amount = flt(diff * me.frm.doc.conversion_rate,
|
||||
precision("tax_amount", last_tax));
|
||||
last_tax.tax_amount += adjustment_amount;
|
||||
last_tax.tax_amount_after_discount += adjustment_amount;
|
||||
last_tax.total += adjustment_amount;
|
||||
last_tax.tax_amount += diff;
|
||||
last_tax.tax_amount_after_discount += diff;
|
||||
last_tax.total += diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user