brotherton-erpnext/erpnext/patches/v5_0/rename_total_fields.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
2.3 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2015-02-12 06:18:20 +00:00
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
2015-07-17 09:42:52 +00:00
from frappe.model.utils.rename_field import rename_field
2015-02-12 06:18:20 +00:00
from frappe.modules import scrub, get_doctype_module
selling_doctypes = ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice")
2015-02-18 06:24:08 +00:00
buying_doctypes = ("Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice")
2015-02-12 06:18:20 +00:00
selling_renamed_fields = (
("net_total", "base_net_total"),
("net_total_export", "net_total"),
("other_charges_total", "base_total_taxes_and_charges"),
("other_charges_total_export", "total_taxes_and_charges"),
("grand_total", "base_grand_total"),
("grand_total_export", "grand_total"),
("rounded_total", "base_rounded_total"),
("rounded_total_export", "rounded_total"),
("in_words", "base_in_words"),
("in_words_export", "in_words")
)
buying_renamed_fields = (
("net_total", "base_net_total"),
("net_total_import", "net_total"),
("grand_total", "base_grand_total"),
("grand_total_import", "grand_total"),
("rounded_total", "base_rounded_total"),
("in_words", "base_in_words"),
("in_words_import", "in_words"),
("other_charges_added", "base_taxes_and_charges_added"),
("other_charges_added_import", "taxes_and_charges_added"),
("other_charges_deducted", "base_taxes_and_charges_deducted"),
("other_charges_deducted_import", "taxes_and_charges_deducted"),
("total_tax", "base_total_taxes_and_charges")
)
def execute():
2015-02-18 09:40:29 +00:00
for doctypes, fields in [[selling_doctypes, selling_renamed_fields], [buying_doctypes, buying_renamed_fields]]:
for dt in doctypes:
frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
2015-03-31 12:01:53 +00:00
table_columns = frappe.db.get_table_columns(dt)
2015-02-18 09:40:29 +00:00
base_net_total = frappe.db.sql("select sum(ifnull({0}, 0)) from `tab{1}`".format(fields[0][1], dt))[0][0]
if not base_net_total:
for f in fields:
2015-03-31 12:01:53 +00:00
if f[0] in table_columns:
2015-02-18 09:40:29 +00:00
rename_field(dt, f[0], f[1])
# Added new field "total_taxes_and_charges" in buying cycle, updating value
if dt in ("Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"):
frappe.db.sql("""update `tab{0}` set total_taxes_and_charges =
round(base_total_taxes_and_charges/conversion_rate, 2)""".format(dt))