fix(patch): validation error on cost center allocation migration (#33835)

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.

(cherry picked from commit de10f2dc00)

Co-authored-by: ruthra kumar <ruthra@erpnext.com>
This commit is contained in:
mergify[bot]
2023-01-28 10:28:06 +05:30
committed by GitHub
parent 5c28ca2b0b
commit 5d4967ceee
2 changed files with 8 additions and 1 deletions

View File

@@ -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()

View File

@@ -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()