Skip to content

Commit

Permalink
chore: better cost center validation for assets (#36477)
Browse files Browse the repository at this point in the history
(cherry picked from commit 38a612c)
  • Loading branch information
anandbaburajan authored and mergify[bot] committed Aug 3, 2023
1 parent a165b37 commit e47c8b7
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,33 @@ def validate_item(self):
frappe.throw(_("Item {0} must be a non-stock item").format(self.item_code))

def validate_cost_center(self):
if not self.cost_center:
return

cost_center_company = frappe.db.get_value("Cost Center", self.cost_center, "company")
if cost_center_company != self.company:
frappe.throw(
_("Selected Cost Center {} doesn't belongs to {}").format(
frappe.bold(self.cost_center), frappe.bold(self.company)
),
title=_("Invalid Cost Center"),
if self.cost_center:
cost_center_company, cost_center_is_group = frappe.db.get_value(
"Cost Center", self.cost_center, ["company", "is_group"]
)
if cost_center_company != self.company:
frappe.throw(
_("Cost Center {} doesn't belong to Company {}").format(
frappe.bold(self.cost_center), frappe.bold(self.company)
),
title=_("Invalid Cost Center"),
)
if cost_center_is_group:
frappe.throw(
_(
"Cost Center {} is a group cost center and group cost centers cannot be used in transactions"
).format(frappe.bold(self.cost_center)),
title=_("Invalid Cost Center"),
)

else:
if not frappe.get_cached_value("Company", self.company, "depreciation_cost_center"):
frappe.throw(
_(
"Please set a Cost Center for the Asset or set an Asset Depreciation Cost Center for the Company {}"
).format(frappe.bold(self.company)),
title=_("Missing Cost Center"),
)

def validate_in_use_date(self):
if not self.available_for_use_date:
Expand Down

0 comments on commit e47c8b7

Please sign in to comment.