mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-10 05:48:15 +00:00
Merge pull request #29388 from frappe/mergify/bp/version-13-hotfix/pr-29373
fix: cost center validation of asset (backport #29373)
This commit is contained in:
@@ -37,6 +37,7 @@ class Asset(AccountsController):
|
||||
self.validate_asset_values()
|
||||
self.validate_asset_and_reference()
|
||||
self.validate_item()
|
||||
self.validate_cost_center()
|
||||
self.set_missing_values()
|
||||
self.prepare_depreciation_data()
|
||||
self.validate_gross_and_purchase_amount()
|
||||
@@ -96,6 +97,19 @@ class Asset(AccountsController):
|
||||
elif item.is_stock_item:
|
||||
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")
|
||||
)
|
||||
|
||||
def validate_in_use_date(self):
|
||||
if not self.available_for_use_date:
|
||||
frappe.throw(_("Available for use date is required"))
|
||||
|
||||
@@ -1131,6 +1131,15 @@ class TestDepreciationBasics(AssetSetup):
|
||||
self.assertEqual(gle, expected_gle)
|
||||
self.assertEqual(asset.get("value_after_depreciation"), 0)
|
||||
|
||||
def test_asset_cost_center(self):
|
||||
asset = create_asset(is_existing_asset = 1, do_not_save=1)
|
||||
asset.cost_center = "Main - WP"
|
||||
|
||||
self.assertRaises(frappe.ValidationError, asset.submit)
|
||||
|
||||
asset.cost_center = "Main - _TC"
|
||||
asset.submit()
|
||||
|
||||
def create_asset_data():
|
||||
if not frappe.db.exists("Asset Category", "Computers"):
|
||||
create_asset_category()
|
||||
|
||||
Reference in New Issue
Block a user