From 8e12a59d9baa404458f19be0cd7e6f6af061e0b2 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 21 May 2018 18:52:07 +0530 Subject: [PATCH] [Fix] Patch --- .../salary_structure_assignment.py | 5 +++- .../create_salary_structure_assignments.py | 28 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py b/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py index d4e8ccdf11..2168a36c9b 100644 --- a/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py +++ b/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py @@ -8,6 +8,8 @@ from frappe import _ from frappe.utils import getdate from frappe.model.document import Document +class DuplicateAssignment(frappe.ValidationError): pass + class SalaryStructureAssignment(Document): def validate(self): self.validate_dates() @@ -56,7 +58,8 @@ class SalaryStructureAssignment(Document): }) if assignment: - frappe.throw(_("Active Salary Structure Assignment {0} found for employee {1} for the given dates").format(assignment[0][0], self.employee)) + frappe.throw(_("Active Salary Structure Assignment {0} found for employee {1} for the given dates"). + format(assignment[0][0], self.employee), DuplicateAssignment) def get_assigned_salary_structure(employee, on_date): if not employee or not on_date: diff --git a/erpnext/patches/v11_0/create_salary_structure_assignments.py b/erpnext/patches/v11_0/create_salary_structure_assignments.py index 8648e15b25..12b477b820 100644 --- a/erpnext/patches/v11_0/create_salary_structure_assignments.py +++ b/erpnext/patches/v11_0/create_salary_structure_assignments.py @@ -4,24 +4,28 @@ from __future__ import unicode_literals import frappe from datetime import datetime +from erpnext.hr.doctype.salary_structure_assignment.salary_structure_assignment import DuplicateAssignment def execute(): frappe.reload_doc("hr", "doctype", "salary_structure_assignment") for d in frappe.db.sql(""" select sse.*, ss.company from `tabSalary Structure Employee` sse, `tabSalary Structure` ss where ss.name = sse.parent AND sse.employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')""", as_dict=1): - s = frappe.new_doc("Salary Structure Assignment") - s.employee = d.employee - s.employee_name = d.employee_name - s.salary_structure = d.parent - s.from_date = d.from_date - s.to_date = d.to_date if isinstance(d.to_date, datetime) else None - s.base = d.base - s.variable = d.variable - s.company = d.company + try: + s = frappe.new_doc("Salary Structure Assignment") + s.employee = d.employee + s.employee_name = d.employee_name + s.salary_structure = d.parent + s.from_date = d.from_date + s.to_date = d.to_date if isinstance(d.to_date, datetime) else None + s.base = d.base + s.variable = d.variable + s.company = d.company - # to migrate the data of the old employees - s.flags.old_employee = True - s.save() + # to migrate the data of the old employees + s.flags.old_employee = True + s.save() + except DuplicateAssignment: + pass frappe.db.sql("update `tabSalary Structure` set docstatus=1") \ No newline at end of file