From 613ef344f3d61c9f731b22871ca851f5c3f26f64 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 16 Aug 2016 18:31:09 +0530 Subject: [PATCH] Patch fixed for v6 to v7 migration --- .../v7_0/convert_timelog_to_timesheet.py | 31 ++++++++++++------- erpnext/patches/v7_0/make_guardian.py | 30 +++++++++++------- .../v7_0/migrate_schools_to_erpnext.py | 18 +++++------ .../v7_0/rename_examination_to_assessment.py | 4 ++- .../projects/doctype/timesheet/timesheet.py | 4 +-- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/erpnext/patches/v7_0/convert_timelog_to_timesheet.py b/erpnext/patches/v7_0/convert_timelog_to_timesheet.py index 072ba13cd0..b802656f7f 100644 --- a/erpnext/patches/v7_0/convert_timelog_to_timesheet.py +++ b/erpnext/patches/v7_0/convert_timelog_to_timesheet.py @@ -1,23 +1,30 @@ import frappe from erpnext.manufacturing.doctype.production_order.production_order \ import make_timesheet, add_timesheet_detail -from erpnext.projects.doctype.timesheet.timesheet import OverlapError def execute(): frappe.reload_doc('projects', 'doctype', 'timesheet') for data in frappe.get_all('Time Log', fields=["*"], filters = [["docstatus", "<", "2"]]): - try: - time_sheet = make_timesheet(data.production_order) - args = get_timelog_data(data) - add_timesheet_detail(time_sheet, args) - time_sheet.docstatus = data.docstatus - time_sheet.note = data.note - time_sheet.company = frappe.db.get_single_value('Global Defaults', 'default_company') - time_sheet.save(ignore_permissions=True) - except OverlapError: - time_sheet.flags.ignore_validate = True - time_sheet.save(ignore_permissions=True) + if data.task: + company = frappe.db.get_value("Task", data.task, "company") + elif data.production_order: + company = frappe.db.get_value("Prodction Order", data.production_order, "company") + else: + company = frappe.db.get_single_value('Global Defaults', 'default_company') + + time_sheet = make_timesheet(data.production_order) + args = get_timelog_data(data) + add_timesheet_detail(time_sheet, args) + time_sheet.docstatus = data.docstatus + time_sheet.note = data.note + time_sheet.company = company + + time_sheet.set_status() + time_sheet.update_cost() + time_sheet.calculate_total_amounts() + time_sheet.flags.ignore_validate = True + time_sheet.save(ignore_permissions=True) def get_timelog_data(data): return { diff --git a/erpnext/patches/v7_0/make_guardian.py b/erpnext/patches/v7_0/make_guardian.py index f654b796f4..0839c4f624 100644 --- a/erpnext/patches/v7_0/make_guardian.py +++ b/erpnext/patches/v7_0/make_guardian.py @@ -2,19 +2,25 @@ from __future__ import unicode_literals import frappe def execute(): - if frappe.db.exists("DocType", "Student") and "father_name" in frappe.db.get_table_columns("Student"): - frappe.reload_doc("schools", "doctype", "student") - frappe.reload_doc("schools", "doctype", "guardian") - frappe.reload_doc("schools", "doctype", "guardian_interest") - frappe.reload_doc("hr", "doctype", "interest") + if frappe.db.exists("DocType", "Student"): + student_table_cols = frappe.db.get_table_columns("Student") + if "father_name" in student_table_cols: + frappe.reload_doc("schools", "doctype", "student") + frappe.reload_doc("schools", "doctype", "guardian") + frappe.reload_doc("schools", "doctype", "guardian_interest") + frappe.reload_doc("hr", "doctype", "interest") + + fields = ["name", "father_name", "mother_name"] + + if "father_email_id" in student_table_cols: + fields += ["father_email_id", "mother_email_id"] - students = frappe.get_all("Student", fields=["name", "father_name", "father_email_id", - "mother_name", "mother_email_id"]) - for stud in students: - if stud.father_name: - make_guardian(stud.father_name, stud.name, stud.father_email_id) - if stud.mother_name: - make_guardian(stud.mother_name, stud.name, stud.mother_email_id) + students = frappe.get_all("Student", fields) + for stud in students: + if stud.father_name: + make_guardian(stud.father_name, stud.name, stud.father_email_id) + if stud.mother_name: + make_guardian(stud.mother_name, stud.name, stud.mother_email_id) def make_guardian(name, student, email=None): frappe.get_doc({ diff --git a/erpnext/patches/v7_0/migrate_schools_to_erpnext.py b/erpnext/patches/v7_0/migrate_schools_to_erpnext.py index 80e9eac896..f64f400feb 100644 --- a/erpnext/patches/v7_0/migrate_schools_to_erpnext.py +++ b/erpnext/patches/v7_0/migrate_schools_to_erpnext.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals import frappe, os +from frappe.installer import remove_from_installed_apps def execute(): reload_doctypes_for_schools_icons() @@ -10,18 +11,15 @@ def execute(): if 'schools' in frappe.get_installed_apps(): frappe.db.sql("""delete from `tabDesktop Icon`""") - if not frappe.db.exists('Module Def', 'Schools'): - frappe.get_doc({ - 'doctype': 'Module Def', - 'module_name': 'Schools', - 'app_name': 'erpnext' - }).insert() - frappe.db.sql("""update `tabDocType` set module='Schools' where module='Academics'""") - from frappe.installer import remove_from_installed_apps + + if not frappe.db.exists('Module Def', 'Schools') and frappe.db.exists('Module Def', 'Academics'): + frappe.rename_doc("Module Def", "Academics", "Schools") + remove_from_installed_apps("schools") def reload_doctypes_for_schools_icons(): base_path = frappe.get_app_path('erpnext', 'schools', 'doctype') for doctype in os.listdir(base_path): - if os.path.exists(os.path.join(base_path, doctype, doctype + '.json')): - frappe.reload_doc('schools', 'doctype', doctype) + if os.path.exists(os.path.join(base_path, doctype, doctype + '.json')) \ + and doctype not in ("fee_component", "assessment", "assessment_result"): + frappe.reload_doc('schools', 'doctype', doctype) \ No newline at end of file diff --git a/erpnext/patches/v7_0/rename_examination_to_assessment.py b/erpnext/patches/v7_0/rename_examination_to_assessment.py index 3c79c51763..1d6e688282 100644 --- a/erpnext/patches/v7_0/rename_examination_to_assessment.py +++ b/erpnext/patches/v7_0/rename_examination_to_assessment.py @@ -9,7 +9,9 @@ from frappe.model.utils.rename_field import rename_field def execute(): if frappe.db.exists("DocType", "Examination"): frappe.rename_doc("DocType", "Examination", "Assessment") - frappe.reload_doctype("Assessment") + frappe.rename_doc("DocType", "Examination Result", "Assessment Result") + frappe.reload_doc("schools", "doctype", "assessment") + frappe.reload_doc("schools", "doctype", "assessment_result") rename_field("Assessment", "exam_name", "assessment_name") rename_field("Assessment", "exam_code", "assessment_code") diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 9140927279..0379f906de 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -159,8 +159,8 @@ class Timesheet(Document): existing = self.get_overlap_for(fieldname, args, value) if existing: - frappe.throw(_("Row {0}: From Time and To Time overlap with existing from and to time").format(args.idx), - OverlapError) + frappe.throw(_("Row {0}: From Time and To Time of {1} is overlapping with {2}") + .format(args.idx, self.name, existing.name), OverlapError) def get_overlap_for(self, fieldname, args, value): cond = "ts.`{0}`".format(fieldname)