From de10f2dc005e5aa493d08bfd1047a36b8040f46f Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 27 Jan 2023 12:08:18 +0530 Subject: [PATCH] fix(patch): validation error on cost center allocation migration If Distributed cost centers have GL postings on patch run date, patch failes with valiation error. --- .../cost_center_allocation/cost_center_allocation.py | 7 ++++++- erpnext/patches/v14_0/migrate_cost_center_allocations.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py index d25016fe59..54ffe21a15 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py @@ -28,9 +28,14 @@ class InvalidDateError(frappe.ValidationError): class CostCenterAllocation(Document): + def __init__(self, *args, **kwargs): + super(CostCenterAllocation, self).__init__(*args, **kwargs) + self._skip_from_date_validation = False + def validate(self): self.validate_total_allocation_percentage() - self.validate_from_date_based_on_existing_gle() + if not self._skip_from_date_validation: + self.validate_from_date_based_on_existing_gle() self.validate_backdated_allocation() self.validate_main_cost_center() self.validate_child_cost_centers() diff --git a/erpnext/patches/v14_0/migrate_cost_center_allocations.py b/erpnext/patches/v14_0/migrate_cost_center_allocations.py index 3bd26933ba..48f4e6d989 100644 --- a/erpnext/patches/v14_0/migrate_cost_center_allocations.py +++ b/erpnext/patches/v14_0/migrate_cost_center_allocations.py @@ -18,9 +18,11 @@ def create_new_cost_center_allocation_records(cc_allocations): cca = frappe.new_doc("Cost Center Allocation") cca.main_cost_center = main_cc cca.valid_from = today() + cca._skip_from_date_validation = True for child_cc, percentage in allocations.items(): cca.append("allocation_percentages", ({"cost_center": child_cc, "percentage": percentage})) + cca.save() cca.submit()