Inclusive tax for deduction and manipulation of tax amount to fix rounding issue

This commit is contained in:
Nabin Hait
2015-05-15 12:02:01 +05:30
parent 9726447169
commit a6ee8290ce
5 changed files with 1608 additions and 1626 deletions

View File

@@ -415,7 +415,8 @@
"options": "currency", "options": "currency",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 1 "print_hide": 1,
"read_only": 1
}, },
{ {
"fieldname": "section_break_44", "fieldname": "section_break_44",
@@ -938,7 +939,7 @@
"icon": "icon-file-text", "icon": "icon-file-text",
"idx": 1, "idx": 1,
"is_submittable": 1, "is_submittable": 1,
"modified": "2015-04-30 03:05:13.790267", "modified": "2015-05-15 14:20:47.718194",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Purchase Invoice", "name": "Purchase Invoice",

View File

@@ -159,6 +159,9 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
this.calculate_taxes_and_totals(); this.calculate_taxes_and_totals();
} }
}, },
add_deduct_tax: function(doc, cdt, cdn) {
this.calculate_taxes_and_totals();
},
calculate_outstanding_amount: function() { calculate_outstanding_amount: function() {
if(this.frm.doc.doctype == "Purchase Invoice" && this.frm.doc.docstatus < 2) { if(this.frm.doc.doctype == "Purchase Invoice" && this.frm.doc.docstatus < 2) {

View File

@@ -116,21 +116,8 @@ class calculate_taxes_and_totals(object):
item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate")) item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
item.discount_percentage = flt(item.discount_percentage, item.precision("discount_percentage")) item.discount_percentage = flt(item.discount_percentage, item.precision("discount_percentage"))
self._set_in_company_currency(item, ["net_rate", "net_amount"]) 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): def _load_item_tax_rate(self, item_tax_rate):
return json.loads(item_tax_rate) if item_tax_rate else {} 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) * \ current_tax_fraction = (tax_rate / 100.0) * \
self.doc.get("taxes")[cint(tax.row_id) - 1].grand_total_fraction_for_current_item 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 return current_tax_fraction
def _get_tax_rate(self, tax, item_tax_map): 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): def manipulate_grand_total_for_inclusive_tax(self):
# if fully inclusive taxes and diff # 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")): 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] last_tax = self.doc.get("taxes")[-1]
diff = self.doc.total - flt(last_tax.total, self.doc.precision("grand_total"))
diff = self.doc.net_total - flt(last_tax.total / self.doc.conversion_rate,
self.doc.precision("grand_total"))
if diff and abs(diff) <= (2.0 / 10**last_tax.precision("tax_amount")): 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 += diff
last_tax.tax_amount += adjustment_amount last_tax.tax_amount_after_discount_amount += diff
last_tax.tax_amount_after_discount_amount += adjustment_amount last_tax.total += diff
last_tax.total += adjustment_amount
def calculate_totals(self): def calculate_totals(self):
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total self.doc.grand_total = flt(self.doc.get("taxes")[-1].total

View File

@@ -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)); item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
me.set_in_company_currency(item, ["net_rate", "net_amount"]); 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; return current_tax_fraction;
}, },
@@ -332,15 +327,12 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
if (all_inclusive) { if (all_inclusive) {
var last_tax = me.frm.doc["taxes"].slice(-1)[0]; var last_tax = me.frm.doc["taxes"].slice(-1)[0];
var diff = me.frm.doc.net_total var diff = me.frm.doc.total - flt(last_tax.total, precision("grand_total"));
- flt(last_tax.total / me.frm.doc.conversion_rate, precision("grand_total"));
if ( diff && Math.abs(diff) <= (2.0 / Math.pow(10, precision("tax_amount", last_tax))) ) { 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, last_tax.tax_amount += diff;
precision("tax_amount", last_tax)); last_tax.tax_amount_after_discount += diff;
last_tax.tax_amount += adjustment_amount; last_tax.total += diff;
last_tax.tax_amount_after_discount += adjustment_amount;
last_tax.total += adjustment_amount;
} }
} }
} }

View File

@@ -405,7 +405,8 @@
"options": "currency", "options": "currency",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 1 "print_hide": 1,
"read_only": 1
}, },
{ {
"fieldname": "section_break_42", "fieldname": "section_break_42",
@@ -852,7 +853,7 @@
"icon": "icon-truck", "icon": "icon-truck",
"idx": 1, "idx": 1,
"is_submittable": 1, "is_submittable": 1,
"modified": "2015-03-23 14:47:44.335393", "modified": "2015-05-15 14:21:33.694753",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Purchase Receipt", "name": "Purchase Receipt",