From 6dfbc2465b702ab4d98a09b7ba077a017fa73200 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 23 Feb 2015 20:00:17 +0530 Subject: [PATCH] Patch: taxes and totals in party currency --- erpnext/patches.txt | 3 +- ...ds_in_custom_scripts_and_print_formats.py} | 9 ++- .../taxes_and_totals_in_party_currency.py | 66 +++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) rename erpnext/patches/v5_0/{replace_renamed_fields_in_custom_script_and_print_formats.py => replace_renamed_fields_in_custom_scripts_and_print_formats.py} (88%) create mode 100644 erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 05b92b1684..f6ac86007e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -112,7 +112,6 @@ erpnext.patches.v5_0.remove_birthday_events erpnext.patches.v5_0.update_item_name_in_bom erpnext.patches.v5_0.rename_customer_issue erpnext.patches.v5_0.rename_total_fields -erpnext.patches.v5_0.replace_renamed_fields_in_custom_script_and_print_formats erpnext.patches.v5_0.new_crm_module erpnext.patches.v5_0.rename_customer_issue erpnext.patches.v5_0.update_material_transfer_for_manufacture @@ -124,3 +123,5 @@ erpnext.patches.v5_0.convert_stock_reconciliation erpnext.patches.v5_0.update_projects erpnext.patches.v5_0.item_patches erpnext.patches.v5_0.update_journal_entry_title +erpnext.patches.v5_0.taxes_and_totals_in_party_currency +erpnext.patches.v5_0.replace_renamed_fields_in_custom_scripts_and_print_formats diff --git a/erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py b/erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py similarity index 88% rename from erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py rename to erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py index f8775c12f3..7fe775b005 100644 --- a/erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py +++ b/erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py @@ -21,9 +21,10 @@ def get_all_renamed_fields(): from erpnext.patches.v5_0.rename_table_fieldnames import rename_map renamed_fields = ( + ("base_amount", "base_net_amount"), ("net_total", "base_net_total"), - ("net_total_export", "net_total"), - ("net_total_import", "net_total"), + ("net_total_export", "total"), + ("net_total_import", "total"), ("other_charges_total", "base_total_taxes_and_charges"), ("other_charges_total_export", "total_taxes_and_charges"), ("other_charges_added", "base_taxes_and_charges_added"), @@ -39,7 +40,9 @@ def get_all_renamed_fields(): ("rounded_total_import", "rounded_total"), ("in_words", "base_in_words"), ("in_words_export", "in_words"), - ("in_words_import", "in_words") + ("in_words_import", "in_words"), + ("tax_amount", "base_tax_amount"), + ("tax_amount_after_discount_amount", "base_tax_amount_after_discount_amount"), ) for fields in rename_map.values(): diff --git a/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py b/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py new file mode 100644 index 0000000000..b588971407 --- /dev/null +++ b/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py @@ -0,0 +1,66 @@ + +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe + +def execute(): + selling_doctypes = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"] + buying_doctypes = ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"] + + for dt in selling_doctypes: + update_values(dt, "Sales Taxes and Charges") + + for dt in buying_doctypes: + update_values(dt, "Purchase Taxes and Charges") + +def update_values(dt, tax_table): + frappe.reload_doctype(dt) + frappe.reload_doctype(dt + " Item") + frappe.reload_doctype(tax_table) + + # update net_total, discount_on + frappe.db.sql(""" + UPDATE + `tab{0}` + SET + total = net_total, + base_total = net_total*conversion_rate, + net_total = base_net_total / conversion_rate, + apply_discount_on = "Grand Total" + WHERE + docstatus < 2 + """.format(dt)) + + + # update net_amount + frappe.db.sql(""" + UPDATE + `tab{0}` par, `tab{1}` item + SET + item.base_net_amount = item.base_amount, + item.base_net_rate = item.base_rate, + item.net_amount = item.base_net_amount / par.conversion_rate, + item.net_rate = item.base_net_rate / par.conversion_rate, + item.base_amount = item.amount * par.conversion_rate, + item.base_rate = item.rate * par.conversion_rate + WHERE + par.name = item.parent + and par.docstatus < 2 + """.format(dt, dt + " Item")) + + # update tax in party currency + frappe.db.sql(""" + UPDATE + `tab{0}` par, `tab{1}` tax + SET + tax.base_tax_amount = tax.tax_amount, + tax.tax_amount = tax.base_tax_amount / par.conversion_rate, + tax.base_total = tax.total, + tax.total = tax.base_total / conversion_rate, + tax.base_tax_amount_after_discount_amount = tax.tax_amount_after_discount_amount, + tax.tax_amount_after_discount_amount = tax.base_tax_amount_after_discount_amount / conversion_rate + WHERE + par.name = tax.parent + and par.docstatus < 2 + """.format(dt, tax_table))