From 57738a0ff3e0880d40515b5be46a4b89aaab6962 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Fri, 3 Jan 2014 18:15:07 +0530 Subject: [PATCH] flat discount replaced to discount amount --- .../Print Format/POS Invoice/POS Invoice.txt | 2 +- .../Sales Invoice Classic.txt | 2 +- .../Sales Invoice Modern.txt | 2 +- .../Sales Invoice Spartan.txt | 2 +- erpnext/accounts/doctype/sales_invoice/pos.js | 12 +++--- .../doctype/sales_invoice/sales_invoice.py | 4 +- .../doctype/sales_invoice/sales_invoice.txt | 6 +-- .../sales_invoice/test_sales_invoice.py | 10 ++--- .../sales_taxes_and_charges.txt | 6 +-- .../sales_taxes_and_charges_master.js | 8 ++-- .../report/sales_register/sales_register.py | 4 +- .../purchase_common/purchase_common.js | 4 +- erpnext/controllers/accounts_controller.py | 42 +++++++++---------- erpnext/controllers/buying_controller.py | 6 +-- erpnext/controllers/selling_controller.py | 28 ++++++------- erpnext/patches.txt | 20 ++++++++- erpnext/public/js/transaction.js | 37 +++++++++------- .../Quotation Classic/Quotation Classic.txt | 2 +- .../Quotation Modern/Quotation Modern.txt | 2 +- .../Quotation Spartan/Quotation Spartan.txt | 2 +- .../Sales Order Classic.txt | 2 +- .../Sales Order Modern/Sales Order Modern.txt | 2 +- .../Sales Order Spartan.txt | 2 +- .../selling/doctype/quotation/quotation.txt | 6 +-- .../doctype/sales_order/sales_order.txt | 6 +-- erpnext/selling/sales_common.js | 38 ++++++++--------- .../Delivery Note Classic.txt | 2 +- .../Delivery Note Modern.txt | 2 +- .../Delivery Note Spartan.txt | 2 +- .../doctype/delivery_note/delivery_note.txt | 6 +-- 30 files changed, 144 insertions(+), 125 deletions(-) diff --git a/erpnext/accounts/Print Format/POS Invoice/POS Invoice.txt b/erpnext/accounts/Print Format/POS Invoice/POS Invoice.txt index 0907c4a865..980195642f 100644 --- a/erpnext/accounts/Print Format/POS Invoice/POS Invoice.txt +++ b/erpnext/accounts/Print Format/POS Invoice/POS Invoice.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Invoice", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n \n \n \n \n \n \n \n
RECEIPT NO: DATE:
M/s
\n\n
\n\n\n", + "html": "\n\n\n\n\n\n\n\n\n \n \n \n \n \n \n \n
RECEIPT NO: DATE:
M/s
\n\n
\n\n\n", "module": "Accounts", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt b/erpnext/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt index 4e8b12b943..09fcb91476 100644 --- a/erpnext/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt +++ b/erpnext/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Invoice", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Accounts", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt b/erpnext/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt index 6808c009e6..a85a11abc8 100644 --- a/erpnext/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt +++ b/erpnext/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Invoice", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Accounts", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt b/erpnext/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt index 45905fc2e1..e0850e1e9a 100644 --- a/erpnext/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt +++ b/erpnext/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Invoice", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Accounts", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/accounts/doctype/sales_invoice/pos.js b/erpnext/accounts/doctype/sales_invoice/pos.js index 1da6f735f6..1b14f05dc1 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.js +++ b/erpnext/accounts/doctype/sales_invoice/pos.js @@ -50,13 +50,13 @@ erpnext.POS = Class.extend({ \ \ \ -
\ +
\ \ \ - \ + \ \ \ \ @@ -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(); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 55c2ecaa59..4a059441fe 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -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 }) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt index 0fcb79d86b..66f7d32c3d 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt @@ -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 }, diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 4b49eb4715..709507abc1 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -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", diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt index 1b3b6f8939..f3c41a649f 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt +++ b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt @@ -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 }, diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js index 2ac6be7a25..0e9b3db6c0 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js +++ b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js @@ -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 diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py index 98ef93662d..8fab6a9d97 100644 --- a/erpnext/accounts/report/sales_register/sales_register.py +++ b/erpnext/accounts/report/sales_register/sales_register.py @@ -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) diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 29e4781d29..f528f6cf1b 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -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"]; }); } } diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 9b8dc2963d..e7393eb735 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -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) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index be07670450..f630f5ae83 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -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): """ diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 9e0fa1b2aa..04bcfaeb04 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -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: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c1ab098298..f39e214245 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index e716c278ae..7db7aef51d 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -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) { diff --git a/erpnext/selling/Print Format/Quotation Classic/Quotation Classic.txt b/erpnext/selling/Print Format/Quotation Classic/Quotation Classic.txt index dc845290fe..05c3c598ca 100644 --- a/erpnext/selling/Print Format/Quotation Classic/Quotation Classic.txt +++ b/erpnext/selling/Print Format/Quotation Classic/Quotation Classic.txt @@ -9,7 +9,7 @@ { "doc_type": "Quotation", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n
Flat DiscountDiscount Amount\ - \
\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t
\n\t\t\t\t\t\n\t\t\t

\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
Name
Address
Contact
\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t
Quotation Date
\n
\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Selling", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/selling/Print Format/Quotation Modern/Quotation Modern.txt b/erpnext/selling/Print Format/Quotation Modern/Quotation Modern.txt index 8b4b0d8f65..35850e62eb 100644 --- a/erpnext/selling/Print Format/Quotation Modern/Quotation Modern.txt +++ b/erpnext/selling/Print Format/Quotation Modern/Quotation Modern.txt @@ -9,7 +9,7 @@ { "doc_type": "Quotation", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Selling", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/selling/Print Format/Quotation Spartan/Quotation Spartan.txt b/erpnext/selling/Print Format/Quotation Spartan/Quotation Spartan.txt index c4a1362ad3..3b4452666b 100644 --- a/erpnext/selling/Print Format/Quotation Spartan/Quotation Spartan.txt +++ b/erpnext/selling/Print Format/Quotation Spartan/Quotation Spartan.txt @@ -9,7 +9,7 @@ { "doc_type": "Quotation", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Selling", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/selling/Print Format/Sales Order Classic/Sales Order Classic.txt b/erpnext/selling/Print Format/Sales Order Classic/Sales Order Classic.txt index 1d36ee6a77..7ee19c0f2d 100644 --- a/erpnext/selling/Print Format/Sales Order Classic/Sales Order Classic.txt +++ b/erpnext/selling/Print Format/Sales Order Classic/Sales Order Classic.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Order", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Selling", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/selling/Print Format/Sales Order Modern/Sales Order Modern.txt b/erpnext/selling/Print Format/Sales Order Modern/Sales Order Modern.txt index 157c8eb29c..7cf481d7b8 100644 --- a/erpnext/selling/Print Format/Sales Order Modern/Sales Order Modern.txt +++ b/erpnext/selling/Print Format/Sales Order Modern/Sales Order Modern.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Order", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Selling", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt b/erpnext/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt index 8dce87eca4..8da27b7d70 100644 --- a/erpnext/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt +++ b/erpnext/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt @@ -9,7 +9,7 @@ { "doc_type": "Sales Order", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Selling", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/selling/doctype/quotation/quotation.txt b/erpnext/selling/doctype/quotation/quotation.txt index 5453cb4e18..4795653262 100644 --- a/erpnext/selling/doctype/quotation/quotation.txt +++ b/erpnext/selling/doctype/quotation/quotation.txt @@ -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" }, { diff --git a/erpnext/selling/doctype/sales_order/sales_order.txt b/erpnext/selling/doctype/sales_order/sales_order.txt index 2469a467f6..2dc62f334a 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.txt +++ b/erpnext/selling/doctype/sales_order/sales_order.txt @@ -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" }, { diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 4562c2b217..330e725ed8 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -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() { diff --git a/erpnext/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt b/erpnext/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt index d16b67fea6..d4c0cc1983 100644 --- a/erpnext/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt +++ b/erpnext/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt @@ -9,7 +9,7 @@ { "doc_type": "Delivery Note", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Stock", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt b/erpnext/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt index 9965634355..3b36f6f1c0 100644 --- a/erpnext/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt +++ b/erpnext/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt @@ -9,7 +9,7 @@ { "doc_type": "Delivery Note", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Stock", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt b/erpnext/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt index 2623d76183..072d411004 100644 --- a/erpnext/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt +++ b/erpnext/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt @@ -9,7 +9,7 @@ { "doc_type": "Delivery Note", "doctype": "Print Format", - "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", + "html": "\n\n\n\n\n\n\n\n\n\n\n\n
\n\t\n\t\n
\n", "module": "Stock", "name": "__common__", "print_format_type": "Client", diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.txt b/erpnext/stock/doctype/delivery_note/delivery_note.txt index c328874959..b2677a39e5 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.txt +++ b/erpnext/stock/doctype/delivery_note/delivery_note.txt @@ -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" }, {