flat discount replaced to discount amount
This commit is contained in:
parent
829eda47a8
commit
57738a0ff3
@ -9,7 +9,7 @@
|
||||
{
|
||||
"doc_type": "Sales Invoice",
|
||||
"doctype": "Print Format",
|
||||
"html": "<html>\n<head>\n<!--Item Table, Totals and Other Charges-->\n<script>\nfunction get_print_format() {\n\tvar oc = getchildren('Sales Invoice Item', doc.name, 'entries');\n\tvar rows = '<table width=\"100%\" cellpadding=\"0\" class=\"cart\">\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td width=\"60%\" align=\"left\">ITEM NAME</td>\\\n <td width=\"10%\" align=\"right\">QTY</td>\\\n <td width=\"30%\" align=\"right\">AMOUNT</td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>';\n\n\tfor (var x=0; x<oc.length; x++) {\n\t\trows += '<tr>\\\n <td align=\"left\">' + oc[x].item_code + \n (oc[x].item_code!=oc[x].item_name ? ('<br>' + oc[x].item_name) : '') + '</td>\\\n <td align=\"right\" style=\"vertical-align:top;\">' + oc[x].qty + '</td>\\\n <td align=\"right\" valign=\"top\">' + format_currency(oc[x].export_amount, doc.currency) + '</td>\\\n </tr>';\n\t}\n\n rows += '<tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"2\" align=\"right\"><b>Net Total</b></td>\\\n <td align=\"right\">' + format_currency(doc.net_total_export, doc.currency) + '</td>\\\n </tr>';\n\n if (doc.other_charges_total_export != 0) {\n var taxes = wn.model.get_children(\"Sales Taxes and Charges\", doc.name, \"other_charges\", \"Sales Invoice\");\n\t\t$.each(taxes, function(i, d) {\n\t\t\trows += '<tr>\\\n \t\t\t\t<td colspan=\"2\" align=\"right\">' + d.description + '</td>\\\n \t\t\t\t<td style=\"text-align: right;\">' + format_currency(d.tax_amount / doc.conversion_rate, doc.currency) + '</td>\\\n \t\t\t<tr>';\n\t\t});\n }\n\n if (doc.flat_discount) {\n\t\trows += '<tr>\\\n \t\t\t<td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\">Flat Discount</td>\\\n \t\t\t<td style=\"text-align: right;\">' + format_currency(doc.flat_discount, doc.currency) + '</td>\\\n \t\t<tr>';\n }\n\n rows += '<tr>\\\n <td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\"><b>Grand Total</b></td>\\\n <td align=\"right\"><hr width=\"90%\" align=\"right\">' + format_currency(doc.grand_total_export, doc.currency) + '<br>\\\n <hr width=\"90%\" align=\"right\"></td>\\\n </tr>\\\n <tr>\\\n <td align=\"center\" colspan=\"3\">Thank You. Please visit again.</td>\\\n </tr>\\\n </table>';\n\treturn rows;\n}\n</script>\n<style>\n table, tr, td, div, p {\n font-family: Monospace;\n line-height: 200%;\n }\n h1, h2, h3, h4, h5, h6 {\n text-align: center;\n }\n\t@media screen {\n\t\tbody {\n\t\t\twidth: 4in;\n\t\t}\n\t}\n</style>\n</head>\n\n<body>\n<table width=\"100%\" cellpadding=\"4\">\n <tr>\n <td align=\"left\">RECEIPT NO: <script>doc.name</script></td>\n <td align=\"right\">DATE: <script>date.str_to_user(doc.posting_date)</script></td>\n </tr>\n <tr>\n <td>M/s <script>doc.customer</script></td>\n </tr>\n</table>\n<!--Item Table & Totals-->\n<div><script>get_print_format();</script></div>\n</body>\n</html>\n",
|
||||
"html": "<html>\n<head>\n<!--Item Table, Totals and Other Charges-->\n<script>\nfunction get_print_format() {\n\tvar oc = getchildren('Sales Invoice Item', doc.name, 'entries');\n\tvar rows = '<table width=\"100%\" cellpadding=\"0\" class=\"cart\">\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td width=\"60%\" align=\"left\">ITEM NAME</td>\\\n <td width=\"10%\" align=\"right\">QTY</td>\\\n <td width=\"30%\" align=\"right\">AMOUNT</td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>';\n\n\tfor (var x=0; x<oc.length; x++) {\n\t\trows += '<tr>\\\n <td align=\"left\">' + oc[x].item_code + \n (oc[x].item_code!=oc[x].item_name ? ('<br>' + oc[x].item_name) : '') + '</td>\\\n <td align=\"right\" style=\"vertical-align:top;\">' + oc[x].qty + '</td>\\\n <td align=\"right\" valign=\"top\">' + format_currency(oc[x].export_amount, doc.currency) + '</td>\\\n </tr>';\n\t}\n\n rows += '<tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"2\" align=\"right\"><b>Net Total</b></td>\\\n <td align=\"right\">' + format_currency(doc.net_total_export, doc.currency) + '</td>\\\n </tr>';\n\n if (doc.other_charges_total_export != 0) {\n var taxes = wn.model.get_children(\"Sales Taxes and Charges\", doc.name, \"other_charges\", \"Sales Invoice\");\n\t\t$.each(taxes, function(i, d) {\n\t\t\trows += '<tr>\\\n \t\t\t\t<td colspan=\"2\" align=\"right\">' + d.description + '</td>\\\n \t\t\t\t<td style=\"text-align: right;\">' + format_currency(d.tax_amount / doc.conversion_rate, doc.currency) + '</td>\\\n \t\t\t<tr>';\n\t\t});\n }\n\n if (doc.discount_amount) {\n\t\trows += '<tr>\\\n \t\t\t<td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\">Discount Amount</td>\\\n \t\t\t<td style=\"text-align: right;\">' + format_currency(doc.discount_amount, doc.currency) + '</td>\\\n \t\t<tr>';\n }\n\n rows += '<tr>\\\n <td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\"><b>Grand Total</b></td>\\\n <td align=\"right\"><hr width=\"90%\" align=\"right\">' + format_currency(doc.grand_total_export, doc.currency) + '<br>\\\n <hr width=\"90%\" align=\"right\"></td>\\\n </tr>\\\n <tr>\\\n <td align=\"center\" colspan=\"3\">Thank You. Please visit again.</td>\\\n </tr>\\\n </table>';\n\treturn rows;\n}\n</script>\n<style>\n table, tr, td, div, p {\n font-family: Monospace;\n line-height: 200%;\n }\n h1, h2, h3, h4, h5, h6 {\n text-align: center;\n }\n\t@media screen {\n\t\tbody {\n\t\t\twidth: 4in;\n\t\t}\n\t}\n</style>\n</head>\n\n<body>\n<table width=\"100%\" cellpadding=\"4\">\n <tr>\n <td align=\"left\">RECEIPT NO: <script>doc.name</script></td>\n <td align=\"right\">DATE: <script>date.str_to_user(doc.posting_date)</script></td>\n </tr>\n <tr>\n <td>M/s <script>doc.customer</script></td>\n </tr>\n</table>\n<!--Item Table & Totals-->\n<div><script>get_print_format();</script></div>\n</body>\n</html>\n",
|
||||
"module": "Accounts",
|
||||
"name": "__common__",
|
||||
"print_format_type": "Client",
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -50,13 +50,13 @@ erpnext.POS = Class.extend({
|
||||
</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
<div class="flat-discount-area">\
|
||||
<div class="discount-amount-area">\
|
||||
<table class="table table-condensed">\
|
||||
<tr>\
|
||||
<td style="vertical-align: middle;" width="50%"><b>Flat Discount</b></td>\
|
||||
<td style="vertical-align: middle;" width="50%"><b>Discount Amount</b></td>\
|
||||
<td width="20%"></td>\
|
||||
<td style="text-align: right;">\
|
||||
<input type="text" class="form-control flat-discount" \
|
||||
<input type="text" class="form-control discount-amount" \
|
||||
style="text-align: right;">\
|
||||
</td>\
|
||||
</tr>\
|
||||
@ -96,8 +96,8 @@ erpnext.POS = Class.extend({
|
||||
me.refresh();
|
||||
});
|
||||
|
||||
this.wrapper.find('input.flat-discount').on("change", function() {
|
||||
wn.model.set_value(me.frm.doctype, me.frm.docname, "flat_discount", this.value);
|
||||
this.wrapper.find('input.discount-amount').on("change", function() {
|
||||
wn.model.set_value(me.frm.doctype, me.frm.docname, "discount_amount", this.value);
|
||||
});
|
||||
|
||||
this.call_function("delete-items", function() {me.remove_selected_item();});
|
||||
@ -339,7 +339,7 @@ erpnext.POS = Class.extend({
|
||||
refresh: function() {
|
||||
var me = this;
|
||||
this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]);
|
||||
this.wrapper.find('input.flat-discount').val(this.frm.doc.flat_discount);
|
||||
this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount);
|
||||
this.barcode.set_input("");
|
||||
|
||||
this.show_items_in_item_cart();
|
||||
|
@ -556,12 +556,12 @@ class DocType(SellingController):
|
||||
|
||||
def make_tax_gl_entries(self, gl_entries):
|
||||
for tax in self.doclist.get({"parentfield": "other_charges"}):
|
||||
if flt(tax.tax_amount_after_flat_discount):
|
||||
if flt(tax.tax_amount_after_discount_amount):
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": tax.account_head,
|
||||
"against": self.doc.debit_to,
|
||||
"credit": flt(tax.tax_amount_after_flat_discount),
|
||||
"credit": flt(tax.tax_amount_after_discount_amount),
|
||||
"remarks": self.doc.remarks,
|
||||
"cost_center": tax.cost_center
|
||||
})
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-05-24 19:29:05",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-12-26 17:50:21",
|
||||
"modified": "2014-01-03 14:52:16",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -457,9 +457,9 @@
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "flat_discount",
|
||||
"fieldname": "discount_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Flat Discount",
|
||||
"label": "Discount Amount",
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 0
|
||||
},
|
||||
|
@ -136,9 +136,9 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
self.assertEquals(si.doc.grand_total, 1627.05)
|
||||
self.assertEquals(si.doc.grand_total_export, 32.54)
|
||||
|
||||
def test_sales_invoice_flat_discount(self):
|
||||
def test_sales_invoice_discount_amount(self):
|
||||
si = webnotes.bean(copy=test_records[3])
|
||||
si.doc.flat_discount = 104.95
|
||||
si.doc.discount_amount = 104.95
|
||||
si.doclist.append({
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"parentfield": "other_charges",
|
||||
@ -174,7 +174,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
# check tax calculation
|
||||
expected_values = {
|
||||
"keys": ["tax_amount", "tax_amount_after_flat_discount", "total"],
|
||||
"keys": ["tax_amount", "tax_amount_after_discount_amount", "total"],
|
||||
"_Test Account Excise Duty - _TC": [140, 130.31, 1293.76],
|
||||
"_Test Account Education Cess - _TC": [2.8, 2.61, 1296.37],
|
||||
"_Test Account S&H Education Cess - _TC": [1.4, 1.31, 1297.68],
|
||||
@ -193,9 +193,9 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
self.assertEquals(si.doc.grand_total, 1500)
|
||||
self.assertEquals(si.doc.grand_total_export, 1500)
|
||||
|
||||
def test_flat_discount_gl_entry(self):
|
||||
def test_discount_amount_gl_entry(self):
|
||||
si = webnotes.bean(copy=test_records[3])
|
||||
si.doc.flat_discount = 104.95
|
||||
si.doc.discount_amount = 104.95
|
||||
si.doclist.append({
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"parentfield": "other_charges",
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-04-24 11:39:32",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-12-20 19:21:45",
|
||||
"modified": "2014-01-03 15:04:25",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -133,10 +133,10 @@
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "tax_amount_after_flat_discount",
|
||||
"fieldname": "tax_amount_after_discount_amount",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
"label": "Tax Amount After Flat Discount",
|
||||
"label": "Tax Amount After Discount Amount",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
|
@ -19,7 +19,7 @@ cur_frm.pformat.net_total_export = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
cur_frm.pformat.flat_discount = function(doc) {
|
||||
cur_frm.pformat.discount_amount = function(doc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@ -77,9 +77,9 @@ cur_frm.pformat.other_charges= function(doc){
|
||||
}
|
||||
}
|
||||
|
||||
// flat discount
|
||||
if(!print_hide('flat_discount') && doc.flat_discount) {
|
||||
out += make_row('Flat Discount', doc.flat_discount, 0);
|
||||
// Discount Amount
|
||||
if(!print_hide('discount_amount') && doc.discount_amount) {
|
||||
out += make_row('Discount Amount', convert_rate(doc.discount_amount), 0);
|
||||
}
|
||||
|
||||
// grand total
|
||||
|
@ -79,7 +79,7 @@ def get_columns(invoice_list):
|
||||
|
||||
tax_accounts = webnotes.conn.sql_list("""select distinct account_head
|
||||
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
|
||||
and docstatus = 1 and ifnull(tax_amount_after_flat_discount, 0) != 0
|
||||
and docstatus = 1 and ifnull(tax_amount_after_discount_amount, 0) != 0
|
||||
and parent in (%s) order by account_head""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||
|
||||
@ -127,7 +127,7 @@ def get_invoice_income_map(invoice_list):
|
||||
|
||||
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
|
||||
tax_details = webnotes.conn.sql("""select parent, account_head,
|
||||
sum(tax_amount_after_flat_discount) as tax_amount
|
||||
sum(tax_amount_after_discount_amount) as tax_amount
|
||||
from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" %
|
||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
|
||||
|
||||
|
@ -362,9 +362,9 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
|
||||
if(this.frm.tax_doclist.length) {
|
||||
if(!wn.meta.get_docfield(this.frm.tax_doclist[0].doctype, "tax_amount_after_flat_discount", this.frm.doctype)) {
|
||||
if(!wn.meta.get_docfield(this.frm.tax_doclist[0].doctype, "tax_amount_after_discount_amount", this.frm.doctype)) {
|
||||
$.each(this.frm.tax_doclist, function(i, tax) {
|
||||
delete tax["tax_amount_after_flat_discount"];
|
||||
delete tax["tax_amount_after_discount_amount"];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,7 @@ class AccountsController(TransactionBase):
|
||||
self.set_missing_values(for_validate=True)
|
||||
self.validate_date_with_fiscal_year()
|
||||
if self.meta.get_field("currency"):
|
||||
self.flat_discount_applied = False
|
||||
self.calculate_taxes_and_totals()
|
||||
if hasattr(self, "apply_flat_discount"):
|
||||
self.apply_flat_discount()
|
||||
self.validate_value("grand_total", ">=", 0)
|
||||
self.set_total_in_words()
|
||||
|
||||
@ -136,6 +133,12 @@ class AccountsController(TransactionBase):
|
||||
self.doclist.append(tax)
|
||||
|
||||
def calculate_taxes_and_totals(self):
|
||||
self.discount_amount_applied = False
|
||||
self._calculate_taxes_and_totals()
|
||||
if self.meta.get_field(self.doc.doctype, "discount_amount"):
|
||||
self.apply_discount_amount()
|
||||
|
||||
def _calculate_taxes_and_totals(self):
|
||||
# validate conversion rate
|
||||
company_currency = get_company_currency(self.doc.company)
|
||||
if not self.doc.currency or self.doc.currency == company_currency:
|
||||
@ -148,10 +151,6 @@ class AccountsController(TransactionBase):
|
||||
self.doc.conversion_rate = flt(self.doc.conversion_rate)
|
||||
self.item_doclist = self.doclist.get({"parentfield": self.fname})
|
||||
self.tax_doclist = self.doclist.get({"parentfield": self.other_fname})
|
||||
|
||||
# for buying
|
||||
if not hasattr(self, "flat_discount_applied"):
|
||||
self.flat_discount_applied = False
|
||||
|
||||
self.calculate_item_values()
|
||||
self.initialize_taxes()
|
||||
@ -164,17 +163,14 @@ class AccountsController(TransactionBase):
|
||||
self.calculate_totals()
|
||||
self._cleanup()
|
||||
|
||||
# TODO
|
||||
# print format: show net_total_export instead of net_total
|
||||
|
||||
def initialize_taxes(self):
|
||||
for tax in self.tax_doclist:
|
||||
tax.item_wise_tax_detail = {}
|
||||
tax_fields = ["total", "tax_amount_after_flat_discount",
|
||||
tax_fields = ["total", "tax_amount_after_discount_amount",
|
||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
|
||||
|
||||
if not self.flat_discount_applied:
|
||||
if not self.discount_amount_applied:
|
||||
tax_fields.append("tax_amount")
|
||||
|
||||
for fieldname in tax_fields:
|
||||
@ -261,10 +257,10 @@ class AccountsController(TransactionBase):
|
||||
tax.tax_amount_for_current_item = current_tax_amount
|
||||
|
||||
# accumulate tax amount into tax.tax_amount
|
||||
if not self.flat_discount_applied:
|
||||
if not self.discount_amount_applied:
|
||||
tax.tax_amount += current_tax_amount
|
||||
|
||||
tax.tax_amount_after_flat_discount += current_tax_amount
|
||||
tax.tax_amount_after_discount_amount += current_tax_amount
|
||||
|
||||
if tax.category:
|
||||
# if just for valuation, do not add the tax amount in total
|
||||
@ -291,21 +287,21 @@ class AccountsController(TransactionBase):
|
||||
if n == len(self.item_doclist) - 1:
|
||||
self.round_off_totals(tax)
|
||||
|
||||
# adjust flat discount loss in last tax iteration
|
||||
if i == (len(self.tax_doclist) - 1) and self.flat_discount_applied:
|
||||
self.adjust_flat_discount_loss(tax)
|
||||
# adjust Discount Amount loss in last tax iteration
|
||||
if i == (len(self.tax_doclist) - 1) and self.discount_amount_applied:
|
||||
self.adjust_discount_amount_loss(tax)
|
||||
|
||||
def round_off_totals(self, tax):
|
||||
tax.total = flt(tax.total, self.precision("total", tax))
|
||||
tax.tax_amount = flt(tax.tax_amount, self.precision("tax_amount", tax))
|
||||
tax.tax_amount_after_flat_discount = flt(tax.tax_amount_after_flat_discount,
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
|
||||
self.precision("tax_amount", tax))
|
||||
|
||||
def adjust_flat_discount_loss(self, tax):
|
||||
flat_discount_loss = self.doc.grand_total - self.doc.flat_discount - tax.total
|
||||
tax.tax_amount_after_flat_discount = flt(tax.tax_amount_after_flat_discount +
|
||||
flat_discount_loss, self.precision("tax_amount", tax))
|
||||
tax.total = flt(tax.total + flat_discount_loss, self.precision("total", tax))
|
||||
def adjust_discount_amount_loss(self, tax):
|
||||
discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
|
||||
discount_amount_loss, self.precision("tax_amount", tax))
|
||||
tax.total = flt(tax.total + discount_amount_loss, self.precision("total", tax))
|
||||
|
||||
def get_current_tax_amount(self, item, tax, item_tax_map):
|
||||
tax_rate = self._get_tax_rate(tax, item_tax_map)
|
||||
|
@ -147,7 +147,7 @@ class BuyingController(StockController):
|
||||
def _cleanup(self):
|
||||
super(BuyingController, self)._cleanup()
|
||||
|
||||
# except in purchase invoice, rate field is purchase_rate
|
||||
# except in purchase invoice, rate field is purchase_rate
|
||||
# reset fieldname of rate
|
||||
if self.doc.doctype != "Purchase Invoice":
|
||||
df = self.meta.get_field("rate", parentfield=self.fname)
|
||||
@ -161,9 +161,9 @@ class BuyingController(StockController):
|
||||
for item in self.item_doclist:
|
||||
del item.fields["item_tax_amount"]
|
||||
|
||||
if not self.meta.get_field("tax_amount_after_flat_discount", parentfield=self.other_fname):
|
||||
if not self.meta.get_field("tax_amount_after_discount_amount", parentfield=self.other_fname):
|
||||
for tax in self.tax_doclist:
|
||||
del tax.fields["tax_amount_after_flat_discount"]
|
||||
del tax.fields["tax_amount_after_discount_amount"]
|
||||
|
||||
def set_item_tax_amount(self, item, tax, current_tax_amount):
|
||||
"""
|
||||
|
@ -121,7 +121,7 @@ class SellingController(StockController):
|
||||
|
||||
cumulated_tax_fraction += tax.tax_fraction_for_current_item
|
||||
|
||||
if cumulated_tax_fraction and not self.flat_discount_applied:
|
||||
if cumulated_tax_fraction and not self.discount_amount_applied:
|
||||
item.amount = flt((item.export_amount * self.doc.conversion_rate) /
|
||||
(1 + cumulated_tax_fraction), self.precision("amount", item))
|
||||
|
||||
@ -158,7 +158,7 @@ class SellingController(StockController):
|
||||
return current_tax_fraction
|
||||
|
||||
def calculate_item_values(self):
|
||||
if not self.flat_discount_applied:
|
||||
if not self.discount_amount_applied:
|
||||
for item in self.item_doclist:
|
||||
self.round_floats_in(item)
|
||||
|
||||
@ -193,25 +193,25 @@ class SellingController(StockController):
|
||||
self.doc.other_charges_total = flt(self.doc.grand_total - self.doc.net_total,
|
||||
self.precision("other_charges_total"))
|
||||
self.doc.other_charges_total_export = flt(self.doc.grand_total_export -
|
||||
self.doc.net_total_export + flt(self.doc.flat_discount), self.precision("other_charges_total_export"))
|
||||
self.doc.net_total_export + flt(self.doc.discount_amount), self.precision("other_charges_total_export"))
|
||||
|
||||
self.doc.rounded_total = _round(self.doc.grand_total)
|
||||
self.doc.rounded_total_export = _round(self.doc.grand_total_export)
|
||||
|
||||
def apply_flat_discount(self):
|
||||
if self.doc.flat_discount:
|
||||
total_amount_for_flat_discount = self.get_flat_discountable_amount()
|
||||
def apply_discount_amount(self):
|
||||
if self.doc.discount_amount:
|
||||
grand_total_for_discount_amount = self.get_grand_total_for_discount_amount()
|
||||
|
||||
if total_amount_for_flat_discount:
|
||||
# calculate item amount after flat discount
|
||||
if grand_total_for_discount_amount:
|
||||
# calculate item amount after Discount Amount
|
||||
for item in self.item_doclist:
|
||||
distributed_amount = self.doc.flat_discount * item.amount / total_amount_for_flat_discount
|
||||
distributed_amount = flt(self.doc.discount_amount) * item.amount / grand_total_for_discount_amount
|
||||
item.amount = flt(item.amount - distributed_amount, self.precision("amount", item))
|
||||
|
||||
self.flat_discount_applied = True
|
||||
self.calculate_taxes_and_totals()
|
||||
self.discount_amount_applied = True
|
||||
self._calculate_taxes_and_totals()
|
||||
|
||||
def get_flat_discountable_amount(self):
|
||||
def get_grand_total_for_discount_amount(self):
|
||||
actual_taxes_dict = {}
|
||||
|
||||
for tax in self.tax_doclist:
|
||||
@ -222,9 +222,9 @@ class SellingController(StockController):
|
||||
flt(tax.rate) / 100
|
||||
actual_taxes_dict.setdefault(tax.idx, actual_tax_amount)
|
||||
|
||||
total_amount_for_flat_discount = flt(self.doc.grand_total - sum(actual_taxes_dict.values()),
|
||||
grand_total_for_discount_amount = flt(self.doc.grand_total - sum(actual_taxes_dict.values()),
|
||||
self.precision("grand_total"))
|
||||
return total_amount_for_flat_discount
|
||||
return grand_total_for_discount_amount
|
||||
|
||||
def calculate_outstanding_amount(self):
|
||||
# NOTE:
|
||||
|
@ -1,3 +1,21 @@
|
||||
erpnext.patches.4_0.update_user_properties
|
||||
erpnext.patches.4_0.move_warehouse_user_to_restrictions
|
||||
erpnext.patches.4_0.new_permissions
|
||||
erpnext.patches.4_0.new_permissions
|
||||
|
||||
execute:webnotes.reload_doc('accounts', 'doctype', 'sales_invoice') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'doctype', 'sales_order') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'doctype', 'quotation') # 2014-01-03
|
||||
execute:webnotes.reload_doc('stock', 'doctype', 'delivery_note') # 2014-01-03
|
||||
execute:webnotes.reload_doc('accounts', 'Print Format', 'POS Invoice') # 2014-01-03
|
||||
execute:webnotes.reload_doc('accounts', 'Print Format', 'Sales Invoice Classic') # 2014-01-03
|
||||
execute:webnotes.reload_doc('accounts', 'Print Format', 'Sales Invoice Modern') # 2014-01-03
|
||||
execute:webnotes.reload_doc('accounts', 'Print Format', 'Sales Invoice Spartan') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'Print Format', 'Quotation Classic') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'Print Format', 'Quotation Modern') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'Print Format', 'Quotation Spartan') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'Print Format', 'Sales Order Classic') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'Print Format', 'Sales Order Modern') # 2014-01-03
|
||||
execute:webnotes.reload_doc('selling', 'Print Format', 'Sales Order Spartan') # 2014-01-03
|
||||
execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Classic') # 2014-01-03
|
||||
execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Modern') # 2014-01-03
|
||||
execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Spartan') # 2014-01-03
|
@ -146,9 +146,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
},
|
||||
|
||||
validate: function() {
|
||||
this.flat_discount_applied = false;
|
||||
this.calculate_taxes_and_totals();
|
||||
this.apply_flat_discount && this.apply_flat_discount();
|
||||
},
|
||||
|
||||
set_default_values: function() {
|
||||
@ -513,6 +511,13 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
},
|
||||
|
||||
calculate_taxes_and_totals: function() {
|
||||
this.discount_amount_applied = false;
|
||||
this._calculate_taxes_and_totals();
|
||||
if (wn.meta.get_docfield(this.frm.doc.doctype, "discount_amount"))
|
||||
this.apply_discount_amount();
|
||||
},
|
||||
|
||||
_calculate_taxes_and_totals: function() {
|
||||
this.validate_conversion_rate();
|
||||
this.frm.item_doclist = this.get_item_doclist();
|
||||
this.frm.tax_doclist = this.get_tax_doclist();
|
||||
@ -524,7 +529,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
this.calculate_taxes();
|
||||
this.calculate_totals();
|
||||
this._cleanup();
|
||||
|
||||
|
||||
this.show_item_wise_taxes();
|
||||
},
|
||||
|
||||
@ -533,11 +538,11 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
|
||||
$.each(this.frm.tax_doclist, function(i, tax) {
|
||||
tax.item_wise_tax_detail = {};
|
||||
tax_fields = ["total", "tax_amount_after_flat_discount",
|
||||
tax_fields = ["total", "tax_amount_after_discount_amount",
|
||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
|
||||
|
||||
if (!me.flat_discount_applied)
|
||||
if (!me.discount_amount_applied)
|
||||
tax_fields.push("tax_amount");
|
||||
|
||||
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
|
||||
@ -581,10 +586,10 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
tax.tax_amount_for_current_item = current_tax_amount;
|
||||
|
||||
// accumulate tax amount into tax.tax_amount
|
||||
if (!me.flat_discount_applied)
|
||||
if (!me.discount_amount_applied)
|
||||
tax.tax_amount += current_tax_amount;
|
||||
|
||||
tax.tax_amount_after_flat_discount += current_tax_amount;
|
||||
tax.tax_amount_after_discount_amount += current_tax_amount;
|
||||
|
||||
// for buying
|
||||
if(tax.category) {
|
||||
@ -614,9 +619,9 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
if (n == me.frm.item_doclist.length - 1) {
|
||||
me.round_off_totals(tax);
|
||||
|
||||
// adjust flat discount loss in last tax iteration
|
||||
if ((i == me.frm.tax_doclist.length - 1) && me.flat_discount_applied)
|
||||
me.adjust_flat_discount_loss(tax);
|
||||
// adjust Discount Amount loss in last tax iteration
|
||||
if ((i == me.frm.tax_doclist.length - 1) && me.discount_amount_applied)
|
||||
me.adjust_discount_amount_loss(tax);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -625,15 +630,15 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
round_off_totals: function(tax) {
|
||||
tax.total = flt(tax.total, precision("total", tax));
|
||||
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
|
||||
tax.tax_amount_after_flat_discount = flt(tax.tax_amount_after_flat_discount,
|
||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
|
||||
precision("tax_amount", tax));
|
||||
},
|
||||
|
||||
adjust_flat_discount_loss: function(tax) {
|
||||
var flat_discount_loss = this.frm.doc.grand_total - this.frm.doc.flat_discount - tax.total;
|
||||
tax.tax_amount_after_flat_discount = flt(tax.tax_amount_after_flat_discount +
|
||||
flat_discount_loss, precision("tax_amount", tax));
|
||||
tax.total = flt(tax.total + flat_discount_loss, precision("total", tax));
|
||||
adjust_discount_amount_loss: function(tax) {
|
||||
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));
|
||||
},
|
||||
|
||||
get_current_tax_amount: function(item, tax, item_tax_map) {
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-05-24 19:29:08",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-12-26 17:54:55",
|
||||
"modified": "2014-01-03 14:54:05",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -462,9 +462,9 @@
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "flat_discount",
|
||||
"fieldname": "discount_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Flat Discount",
|
||||
"label": "Discount Amount",
|
||||
"options": "Company:company:default_currency"
|
||||
},
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-06-18 12:39:59",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-12-26 17:55:43",
|
||||
"modified": "2014-01-03 14:51:19",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -482,9 +482,9 @@
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "flat_discount",
|
||||
"fieldname": "discount_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Flat Discount",
|
||||
"label": "Discount Amount",
|
||||
"options": "Company:company:default_currency"
|
||||
},
|
||||
{
|
||||
|
@ -226,10 +226,8 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
this.calculate_taxes_and_totals();
|
||||
},
|
||||
|
||||
flat_discount: function() {
|
||||
this.flat_discount_applied = false;
|
||||
discount_amount: function() {
|
||||
this.calculate_taxes_and_totals();
|
||||
this.apply_flat_discount();
|
||||
},
|
||||
|
||||
commission_rate: function() {
|
||||
@ -317,7 +315,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
calculate_item_values: function() {
|
||||
var me = this;
|
||||
|
||||
if (!this.flat_discount_applied) {
|
||||
if (!this.discount_amount_applied) {
|
||||
$.each(this.frm.item_doclist, function(i, item) {
|
||||
wn.model.round_floats_in(item);
|
||||
item.export_amount = flt(item.export_rate * item.qty, precision("export_amount", item));
|
||||
@ -349,7 +347,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
cumulated_tax_fraction += tax.tax_fraction_for_current_item;
|
||||
});
|
||||
|
||||
if(cumulated_tax_fraction && !me.flat_discount_applied) {
|
||||
if(cumulated_tax_fraction && !me.discount_amount_applied) {
|
||||
item.amount = flt(
|
||||
(item.export_amount * me.frm.doc.conversion_rate) / (1 + cumulated_tax_fraction),
|
||||
precision("amount", item));
|
||||
@ -416,31 +414,33 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
this.frm.doc.other_charges_total = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
|
||||
precision("other_charges_total"));
|
||||
this.frm.doc.other_charges_total_export = flt(this.frm.doc.grand_total_export -
|
||||
this.frm.doc.net_total_export + this.frm.doc.flat_discount,
|
||||
this.frm.doc.net_total_export + flt(this.frm.doc.discount_amount),
|
||||
precision("other_charges_total_export"));
|
||||
|
||||
this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
|
||||
this.frm.doc.rounded_total_export = Math.round(this.frm.doc.grand_total_export);
|
||||
},
|
||||
|
||||
apply_flat_discount: function() {
|
||||
apply_discount_amount: function() {
|
||||
var me = this;
|
||||
var distributed_amount = 0.0;
|
||||
|
||||
if (this.frm.doc.flat_discount) {
|
||||
var total_amount_for_flat_discount = this.get_flat_discountable_amount();
|
||||
// calculate item amount after flat discount
|
||||
$.each(this.frm.item_doclist, function(i, item) {
|
||||
distributed_amount = me.frm.doc.flat_discount * item.amount / total_amount_for_flat_discount;
|
||||
item.amount = flt(item.amount - distributed_amount, precision("amount", item));
|
||||
});
|
||||
if (this.frm.doc.discount_amount) {
|
||||
var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
|
||||
// calculate item amount after Discount Amount
|
||||
if (grand_total_for_discount_amount) {
|
||||
$.each(this.frm.item_doclist, function(i, item) {
|
||||
distributed_amount = flt(me.frm.doc.discount_amount) * item.amount / grand_total_for_discount_amount;
|
||||
item.amount = flt(item.amount - distributed_amount, precision("amount", item));
|
||||
});
|
||||
|
||||
this.flat_discount_applied = true;
|
||||
this.calculate_taxes_and_totals();
|
||||
this.discount_amount_applied = true;
|
||||
this._calculate_taxes_and_totals();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get_flat_discountable_amount: function() {
|
||||
get_grand_total_for_discount_amount: function() {
|
||||
var me = this;
|
||||
var total_actual_tax = 0.0;
|
||||
var actual_taxes_dict = {};
|
||||
@ -459,9 +459,9 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
total_actual_tax += value;
|
||||
});
|
||||
|
||||
total_amount_for_flat_discount = flt(this.frm.doc.grand_total - total_actual_tax,
|
||||
grand_total_for_discount_amount = flt(this.frm.doc.grand_total - total_actual_tax,
|
||||
precision("grand_total"));
|
||||
return total_amount_for_flat_discount;
|
||||
return grand_total_for_discount_amount;
|
||||
},
|
||||
|
||||
calculate_outstanding_amount: function() {
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-05-24 19:29:09",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-12-26 18:01:33",
|
||||
"modified": "2014-01-03 14:53:03",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -492,9 +492,9 @@
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "flat_discount",
|
||||
"fieldname": "discount_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Flat Discount",
|
||||
"label": "Discount Amount",
|
||||
"options": "Company:company:default_currency"
|
||||
},
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user