From 2244ac4d52a500f89e5c88a451b8cc9dc4e9ebe1 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 12 Jan 2015 17:35:14 +0530 Subject: [PATCH] Discount amount in party currency --- .../doctype/sales_invoice/sales_invoice.json | 32 +++++++++----- .../sales_taxes_and_charges_master.js | 16 +++---- erpnext/controllers/accounts_controller.py | 2 +- erpnext/controllers/selling_controller.py | 9 ++-- erpnext/patches.txt | 1 + erpnext/patches/v4_2/discount_amount.py | 12 ++++++ erpnext/public/js/transaction.js | 5 +-- .../selling/doctype/quotation/quotation.json | 32 +++++++++----- .../doctype/sales_order/sales_order.json | 42 ++++++++++++------- erpnext/selling/sales_common.js | 16 ++++--- .../doctype/delivery_note/delivery_note.json | 32 +++++++++----- erpnext/stock/get_item_details.py | 4 +- 12 files changed, 132 insertions(+), 71 deletions(-) create mode 100644 erpnext/patches/v4_2/discount_amount.py diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index b27a2abc75..9f70c70d32 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -422,6 +422,15 @@ "fieldtype": "Section Break", "permlevel": 0 }, + { + "fieldname": "other_charges_total_export", + "fieldtype": "Currency", + "label": "Total Taxes and Charges", + "options": "currency", + "permlevel": 0, + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "other_charges_total", "fieldtype": "Currency", @@ -438,23 +447,24 @@ "fieldtype": "Column Break", "permlevel": 0 }, - { - "fieldname": "other_charges_total_export", - "fieldtype": "Currency", - "label": "Total Taxes and Charges", - "options": "currency", - "permlevel": 0, - "print_hide": 1, - "read_only": 1 - }, { "fieldname": "discount_amount", "fieldtype": "Currency", "label": "Discount Amount", - "options": "Company:company:default_currency", + "options": "currency", "permlevel": 0, "print_hide": 0 }, + { + "fieldname": "base_discount_amount", + "fieldtype": "Currency", + "label": "Discount Amount (Company Currency)", + "options": "Company:company:default_currency", + "permlevel": 0, + "precision": "", + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "totals", "fieldtype": "Section Break", @@ -1192,7 +1202,7 @@ "icon": "icon-file-text", "idx": 1, "is_submittable": 1, - "modified": "2014-12-11 16:26:12.402110", + "modified": "2015-01-12 17:34:36.353241", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", 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 d11bf294f8..f4e14b8103 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 @@ -46,17 +46,17 @@ cur_frm.pformat.other_charges= function(doc){ var new_val = flt(val)/flt(doc.conversion_rate); return new_val; } - + function print_hide(fieldname) { var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name); return doc_field.print_hide; } - + out =''; if (!doc.print_without_amount) { var cl = doc.other_charges || []; - // outer table + // outer table var out='
'; // main table @@ -77,12 +77,12 @@ cur_frm.pformat.other_charges= function(doc){ // Discount Amount if(!print_hide('discount_amount') && doc.discount_amount) - out += make_row('Discount Amount', convert_rate(doc.discount_amount), 0); + out += make_row('Discount Amount', doc.discount_amount, 0); // grand total if(!print_hide('grand_total_export')) out += make_row('Grand Total', doc.grand_total_export, 1); - + if(!print_hide('rounded_total_export')) out += make_row('Rounded Total', doc.rounded_total_export, 1); @@ -92,7 +92,7 @@ cur_frm.pformat.other_charges= function(doc){ out += ''; out += ''; } - out += '
In Words' + doc.in_words_export + '
'; + out += ''; } return out; } @@ -139,14 +139,14 @@ cur_frm.fields_dict['other_charges'].grid.get_field("account_head").get_query = "account_type": ["Tax", "Chargeable", "Income Account"], "company": doc.company } - } + } } cur_frm.fields_dict['other_charges'].grid.get_field("cost_center").get_query = function(doc) { return{ 'company': doc.company, 'group_or_ledger': "Ledger" - } + } } cur_frm.cscript.rate = function(doc, cdt, cdn) { diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 02fdf2ca99..5219339476 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -295,7 +295,7 @@ class AccountsController(TransactionBase): self.precision("tax_amount", tax)) def adjust_discount_amount_loss(self, tax): - discount_amount_loss = self.grand_total - flt(self.discount_amount) - tax.total + discount_amount_loss = self.grand_total - flt(self.base_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)) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 68cdf189bd..4b0cd4eeb1 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -218,8 +218,7 @@ class SellingController(StockController): def calculate_totals(self): self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total) - self.grand_total_export = flt(self.grand_total / self.conversion_rate) \ - if self.tax_doclist else self.net_total_export + self.grand_total_export = flt(self.grand_total / self.conversion_rate) self.other_charges_total = flt(self.grand_total - self.net_total, self.precision("other_charges_total")) @@ -234,16 +233,20 @@ class SellingController(StockController): def apply_discount_amount(self): if self.discount_amount: + self.base_discount_amount = flt(self.discount_amount * self.conversion_rate, self.precision("base_discount_amount")) + grand_total_for_discount_amount = self.get_grand_total_for_discount_amount() if grand_total_for_discount_amount: # calculate item amount after Discount Amount for item in self.item_doclist: - distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount + distributed_amount = flt(self.base_discount_amount) * item.base_amount / grand_total_for_discount_amount item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item)) self.discount_amount_applied = True self._calculate_taxes_and_totals() + else: + self.base_discount_amount = 0 def get_grand_total_for_discount_amount(self): actual_taxes_dict = {} diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 33fa396649..7fda960356 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -90,3 +90,4 @@ erpnext.patches.v4_2.fix_gl_entries_for_stock_transactions erpnext.patches.v4_2.update_requested_and_ordered_qty execute:frappe.delete_doc("DocType", "Contact Control") erpnext.patches.v4_2.recalculate_bom_costs +erpnext.patches.v4_2.discount_amount diff --git a/erpnext/patches/v4_2/discount_amount.py b/erpnext/patches/v4_2/discount_amount.py new file mode 100644 index 0000000000..e23a10e06c --- /dev/null +++ b/erpnext/patches/v4_2/discount_amount.py @@ -0,0 +1,12 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from frappe.modules import scrub, get_doctype_module + +def execute(): + for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales invoice"]: + frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt)) + frappe.db.sql("""update `tab{0}` set base_discount_amount=discount_amount, + discount_amount=discount_amount/conversion_rate""".format(dt)) diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index acb841b8a0..6d38b46b78 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -734,7 +734,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ }, adjust_discount_amount_loss: function(tax) { - var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total; + var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.base_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)); @@ -748,8 +748,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ // distribute the tax amount proportionally to each item row var actual = flt(tax.rate, precision("tax_amount", tax)); current_tax_amount = this.frm.doc.net_total ? - ((item.base_amount / this.frm.doc.net_total) * actual) : - 0.0; + ((item.base_amount / this.frm.doc.net_total) * actual) : 0.0; } else if(tax.charge_type == "On Net Total") { current_tax_amount = (tax_rate / 100.0) * item.base_amount; diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json index 5d960e9556..9af5029e79 100644 --- a/erpnext/selling/doctype/quotation/quotation.json +++ b/erpnext/selling/doctype/quotation/quotation.json @@ -405,6 +405,15 @@ "fieldtype": "Section Break", "permlevel": 0 }, + { + "fieldname": "other_charges_total_export", + "fieldtype": "Currency", + "label": "Taxes and Charges Total", + "options": "currency", + "permlevel": 0, + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "other_charges_total", "fieldtype": "Currency", @@ -421,22 +430,23 @@ "fieldtype": "Column Break", "permlevel": 0 }, - { - "fieldname": "other_charges_total_export", - "fieldtype": "Currency", - "label": "Taxes and Charges Total", - "options": "currency", - "permlevel": 0, - "print_hide": 1, - "read_only": 1 - }, { "fieldname": "discount_amount", "fieldtype": "Currency", "label": "Discount Amount", - "options": "Company:company:default_currency", + "options": "currency", "permlevel": 0 }, + { + "fieldname": "base_discount_amount", + "fieldtype": "Currency", + "label": "Discount Amount (Company Currency)", + "options": "Company:company:default_currency", + "permlevel": 0, + "precision": "", + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "totals", "fieldtype": "Section Break", @@ -832,7 +842,7 @@ "idx": 1, "is_submittable": 1, "max_attachments": 1, - "modified": "2014-09-09 05:35:33.413559", + "modified": "2015-01-12 16:57:14.706270", "modified_by": "Administrator", "module": "Selling", "name": "Quotation", diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json index 50647030fe..4ffc603466 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.json +++ b/erpnext/selling/doctype/sales_order/sales_order.json @@ -420,11 +420,6 @@ "print_hide": 1, "read_only": 1 }, - { - "fieldname": "column_break_46", - "fieldtype": "Column Break", - "permlevel": 0 - }, { "fieldname": "other_charges_total", "fieldtype": "Currency", @@ -437,12 +432,28 @@ "read_only": 1, "width": "150px" }, + { + "fieldname": "column_break_46", + "fieldtype": "Column Break", + "permlevel": 0 + }, { "fieldname": "discount_amount", "fieldtype": "Currency", "label": "Discount Amount", + "options": "currency", + "permlevel": 0, + "print_hide": 0 + }, + { + "fieldname": "base_discount_amount", + "fieldtype": "Currency", + "label": "Discount Amount (Company Currency)", "options": "Company:company:default_currency", - "permlevel": 0 + "permlevel": 0, + "precision": "", + "print_hide": 1, + "read_only": 1 }, { "fieldname": "totals", @@ -490,14 +501,6 @@ "read_only": 1, "width": "200px" }, - { - "fieldname": "advance_paid", - "fieldtype": "Currency", - "label": "Advance Paid", - "permlevel": 0, - "print_hide": 1, - "read_only": 1 - }, { "fieldname": "column_break3", "fieldtype": "Column Break", @@ -542,6 +545,15 @@ "read_only": 1, "width": "200px" }, + { + "fieldname": "advance_paid", + "fieldtype": "Currency", + "label": "Advance Paid", + "options": "Company:company:default_currency", + "permlevel": 0, + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "view_details", "fieldtype": "Fold", @@ -1021,7 +1033,7 @@ "idx": 1, "is_submittable": 1, "issingle": 0, - "modified": "2014-12-16 10:36:47.295144", + "modified": "2015-01-12 15:16:51.611467", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order", diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index c7c21fdda9..3a01811ba8 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -342,8 +342,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ var tax_count = this.frm.tax_doclist.length; this.frm.doc.grand_total = flt(tax_count ? this.frm.tax_doclist[tax_count - 1].total : this.frm.doc.net_total); - this.frm.doc.grand_total_export = flt(tax_count ? - flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total_export); + this.frm.doc.grand_total_export = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate); this.frm.doc.other_charges_total = flt(this.frm.doc.grand_total - this.frm.doc.net_total, precision("other_charges_total")); @@ -363,17 +362,22 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ var distributed_amount = 0.0; if (this.frm.doc.discount_amount) { + this.frm.set_value("base_discount_amount", + flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_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.base_amount / grand_total_for_discount_amount; + distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount; item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item)); }); this.discount_amount_applied = true; this._calculate_taxes_and_totals(); } + } else { + this.frm.set_value("base_discount_amount", 0); } }, @@ -507,12 +511,12 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ } }); }; - setup_field_label_map(["net_total", "other_charges_total", "grand_total", + setup_field_label_map(["net_total", "other_charges_total", "base_discount_amount", "grand_total", "rounded_total", "in_words", "outstanding_amount", "total_advance", "paid_amount", "write_off_amount"], company_currency); - setup_field_label_map(["net_total_export", "other_charges_total_export", "grand_total_export", + setup_field_label_map(["net_total_export", "other_charges_total_export", "discount_amount", "grand_total_export", "rounded_total_export", "in_words_export"], this.frm.doc.currency); cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency @@ -525,7 +529,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ // toggle fields this.frm.toggle_display(["conversion_rate", "net_total", "other_charges_total", - "grand_total", "rounded_total", "in_words"], + "grand_total", "rounded_total", "in_words", "base_discount_amount"], this.frm.doc.currency != company_currency); this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"], diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json index 98e774804f..c7a25d2e61 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.json +++ b/erpnext/stock/doctype/delivery_note/delivery_note.json @@ -434,6 +434,15 @@ "fieldtype": "Section Break", "permlevel": 0 }, + { + "fieldname": "other_charges_total_export", + "fieldtype": "Currency", + "label": "Taxes and Charges Total", + "options": "Company:company:default_currency", + "permlevel": 0, + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "other_charges_total", "fieldtype": "Currency", @@ -452,22 +461,23 @@ "fieldtype": "Column Break", "permlevel": 0 }, - { - "fieldname": "other_charges_total_export", - "fieldtype": "Currency", - "label": "Taxes and Charges Total", - "options": "Company:company:default_currency", - "permlevel": 0, - "print_hide": 1, - "read_only": 1 - }, { "fieldname": "discount_amount", "fieldtype": "Currency", "label": "Discount Amount", - "options": "Company:company:default_currency", + "options": "currency", "permlevel": 0 }, + { + "fieldname": "base_discount_amount", + "fieldtype": "Currency", + "label": "Discount Amount (Company Currency)", + "options": "Company:company:default_currency", + "permlevel": 0, + "precision": "", + "print_hide": 1, + "read_only": 1 + }, { "fieldname": "totals", "fieldtype": "Section Break", @@ -1013,7 +1023,7 @@ "idx": 1, "in_create": 0, "is_submittable": 1, - "modified": "2014-12-22 14:58:19.575566", + "modified": "2015-01-12 16:56:39.975961", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index fffb52e835..5145e0ab17 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe from frappe import _, throw -from frappe.utils import flt, cint, add_days +from frappe.utils import flt, cint, add_days, cstr import json from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item from erpnext.setup.utils import get_exchange_rate @@ -140,7 +140,7 @@ def get_basic_details(args, item_doc): "item_code": item.name, "item_name": item.item_name, - "description": item.description_html or item.description, + "description": cstr(item.description_html).strip() or cstr(item.description).strip(), "warehouse": user_default_warehouse or args.warehouse or item.default_warehouse, "income_account": (item.income_account or args.income_account