Patch to copy old field data to new field (#11997)

* patch to copy old fields data to new ones

* fix for patches related to project

* use rename_field function, copy if only field present
This commit is contained in:
Zarrar 2017-12-14 12:21:00 +05:30 committed by Nabin Hait
parent 5759258dcf
commit 6e0acbe4d0
3 changed files with 17 additions and 2 deletions

View File

@ -480,3 +480,4 @@ erpnext.patches.v9_2.delete_process_payroll
erpnext.patches.v10_0.add_agriculture_domain
erpnext.patches.v10_0.add_non_profit_domain
erpnext.patches.v10_0.setup_vat_for_uae_and_saudi_arabia
erpnext.patches.v10_0.copy_projects_renamed_fields

View File

@ -0,0 +1,12 @@
import frappe
from frappe.model.utils.rename_field import rename_field
def execute():
""" copy data from old fields to new """
frappe.reload_doc("projects", "doctype", "project")
if frappe.db.has_column('Project', 'total_sales_cost'):
rename_field('Project', "total_sales_cost", "total_sales_amount")
if frappe.db.has_column('Project', 'total_billing_amount'):
rename_field('Project', "total_billing_amount", "total_billable_amount")

View File

@ -2,8 +2,10 @@ from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("projects", "doctype", "project")
frappe.db.sql("""
update `tabProject` p
set total_sales_cost = ifnull((select sum(base_grand_total)
set total_sales_amount = ifnull((select sum(base_grand_total)
from `tabSales Order` where project=p.name and docstatus=1), 0)
""")