Fixes for discount amount
This commit is contained in:
parent
ce24512ed7
commit
2b019ed430
@ -76,7 +76,7 @@ class calculate_taxes_and_totals(object):
|
||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
|
||||
|
||||
if not self.discount_amount_applied:
|
||||
if tax.charge_type != "Actual" and not self.discount_amount_applied:
|
||||
tax_fields.append("tax_amount")
|
||||
|
||||
for fieldname in tax_fields:
|
||||
@ -214,14 +214,15 @@ class calculate_taxes_and_totals(object):
|
||||
if n == len(self.doc.get("items")) - 1:
|
||||
current_tax_amount += actual_tax_dict[tax.idx]
|
||||
|
||||
# accumulate tax amount into tax.tax_amount
|
||||
if tax.charge_type != "Actual" and not self.discount_amount_applied:
|
||||
tax.tax_amount += current_tax_amount
|
||||
|
||||
# store tax_amount for current item as it will be used for
|
||||
# charge type = 'On Previous Row Amount'
|
||||
tax.tax_amount_for_current_item = current_tax_amount
|
||||
|
||||
# accumulate tax amount into tax.tax_amount
|
||||
if not self.discount_amount_applied:
|
||||
tax.tax_amount += current_tax_amount
|
||||
|
||||
# set tax after discount
|
||||
tax.tax_amount_after_discount_amount += current_tax_amount
|
||||
|
||||
if getattr(tax, "category", None):
|
||||
|
@ -35,7 +35,6 @@ doctype_series_map = {
|
||||
def execute():
|
||||
series_to_set = get_series_to_set()
|
||||
for doctype, opts in series_to_set.items():
|
||||
print "Setting naming series", doctype, opts
|
||||
set_series(doctype, opts["options"], opts["default"])
|
||||
|
||||
def set_series(doctype, options, default):
|
||||
|
@ -1,10 +1,6 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.ui.form.on(cur_frm.doctype, "refresh", function(frm) {
|
||||
frm.set_footnote(frappe.markdown(frm.meta.description));
|
||||
}
|
||||
|
||||
// get tax rate
|
||||
cur_frm.cscript.account_head = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
@ -28,8 +24,8 @@ var validate_taxes_and_charges = function(cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
|
||||
msgprint(__("Please select Charge Type first"));
|
||||
d.row_id = ""
|
||||
d.rate = d.tax_amount = 0.0
|
||||
d.row_id = "";
|
||||
d.rate = d.tax_amount = 0.0;
|
||||
} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
|
||||
msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
|
||||
d.row_id = "";
|
||||
@ -48,19 +44,19 @@ var validate_taxes_and_charges = function(cdt, cdn) {
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
});
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
});
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
});
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "charge_type", function(frm, cdt, cdn) {
|
||||
validate_taxes_and_charges(cdt, cdn);
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
cur_frm.set_query("account_head", "taxes", function(doc) {
|
||||
@ -86,7 +82,7 @@ cur_frm.set_query("cost_center", "taxes", function(doc) {
|
||||
'group_or_ledger': "Ledger"
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// For customizing print
|
||||
cur_frm.pformat.print_total = function(doc) { return ''; }
|
||||
|
@ -88,7 +88,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
|
||||
|
||||
if (!me.discount_amount_applied)
|
||||
if (cstr(tax.charge_type) != "Actual" && !me.discount_amount_applied)
|
||||
tax_fields.push("tax_amount");
|
||||
|
||||
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
|
||||
@ -216,14 +216,15 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
}
|
||||
}
|
||||
|
||||
// accumulate tax amount into tax.tax_amount
|
||||
if (tax.charge_type != "Actual" && !me.discount_amount_applied)
|
||||
tax.tax_amount += current_tax_amount;
|
||||
|
||||
// store tax_amount for current item as it will be used for
|
||||
// charge type = 'On Previous Row Amount'
|
||||
tax.tax_amount_for_current_item = current_tax_amount;
|
||||
|
||||
// accumulate tax amount into tax.tax_amount
|
||||
if (!me.discount_amount_applied)
|
||||
tax.tax_amount += current_tax_amount;
|
||||
|
||||
// tax amount after discount amount
|
||||
tax.tax_amount_after_discount_amount += current_tax_amount;
|
||||
|
||||
// for buying
|
||||
@ -239,7 +240,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
// note: grand_total_for_current_item contains the contribution of
|
||||
// item's amount, previously applied tax and the current tax on that item
|
||||
if(i==0) {
|
||||
tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount);
|
||||
tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount);
|
||||
} else {
|
||||
tax.grand_total_for_current_item =
|
||||
flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount);
|
||||
@ -313,7 +314,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
},
|
||||
|
||||
adjust_discount_amount_loss: function(tax) {
|
||||
var discount_amount_loss = this.frm.doc.base_grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
|
||||
var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
|
||||
discount_amount_loss, precision("tax_amount", tax));
|
||||
tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
|
||||
@ -326,7 +327,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
|
||||
|
||||
if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
|
||||
this.frm.doc.base_grand_total = (this.frm.doc.base_total_taxes_and_charges) ?
|
||||
this.frm.doc.base_grand_total = (this.frm.doc.total_taxes_and_charges) ?
|
||||
flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total;
|
||||
} else {
|
||||
// other charges added/deducted
|
||||
@ -345,7 +346,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
frappe.model.round_floats_in(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
|
||||
}
|
||||
|
||||
this.frm.doc.grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
|
||||
this.frm.doc.base_grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
|
||||
flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total);
|
||||
|
||||
this.set_in_company_currency(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
|
||||
@ -354,6 +355,8 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
|
||||
precision("total_taxes_and_charges"));
|
||||
|
||||
this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
|
||||
|
||||
// Round grand total as per precision
|
||||
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "base_grand_total"]);
|
||||
|
||||
@ -408,7 +411,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
if (total_for_discount_amount) {
|
||||
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||
distributed_amount = flt(me.frm.doc.discount_amount) * item.net_amount / total_for_discount_amount;
|
||||
item.base_amount = flt(item.net_amount - distributed_amount, precision("base_amount", item));
|
||||
item.net_amount = flt(item.net_amount - distributed_amount, precision("base_amount", item));
|
||||
item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
|
||||
|
||||
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
||||
@ -441,8 +444,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
});
|
||||
|
||||
$.each(actual_taxes_dict, function(key, value) {
|
||||
if (value)
|
||||
total_actual_tax += value;
|
||||
if (value) total_actual_tax += value;
|
||||
});
|
||||
|
||||
return flt(this.frm.doc.grand_total - total_actual_tax, precision("grand_total"));
|
||||
|
@ -151,6 +151,7 @@ cur_frm.cscript['Declare Order Lost'] = function(){
|
||||
})
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
||||
|
@ -8,11 +8,8 @@ import unittest
|
||||
|
||||
class TestCompany(unittest.TestCase):
|
||||
def atest_coa(self):
|
||||
for country, chart_name in frappe.db.sql("""select country, chart_name
|
||||
for country, chart_name in frappe.db.sql("""select country, chart_name
|
||||
from `tabChart of Accounts` where name = 'Deutscher Kontenplan SKR03'""", as_list=1):
|
||||
print "Country: ", country
|
||||
print "Chart Name: ", chart_name
|
||||
|
||||
company_doc = frappe.get_doc({
|
||||
"doctype": "Company",
|
||||
"company_name": "_Test Company 2",
|
||||
@ -23,10 +20,10 @@ class TestCompany(unittest.TestCase):
|
||||
})
|
||||
|
||||
company_doc.insert()
|
||||
self.assertTrue(frappe.db.sql("""select count(*) from tabAccount
|
||||
self.assertTrue(frappe.db.sql("""select count(*) from tabAccount
|
||||
where company='_Test Company 2'""")[0][0] > 10)
|
||||
|
||||
frappe.delete_doc("Company", "_Test Company 2")
|
||||
|
||||
|
||||
test_records = frappe.get_test_records('Company')
|
||||
frappe.delete_doc("Company", "_Test Company 2")
|
||||
|
||||
|
||||
test_records = frappe.get_test_records('Company')
|
||||
|
Loading…
x
Reference in New Issue
Block a user