mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-12 17:51:20 +00:00
* chore: asset finance books validation (#36979)
(cherry picked from commit 0077659e93)
* chore: fix tests
---------
Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
This commit is contained in:
@@ -40,6 +40,7 @@ class Asset(AccountsController):
|
|||||||
self.validate_item()
|
self.validate_item()
|
||||||
self.validate_cost_center()
|
self.validate_cost_center()
|
||||||
self.set_missing_values()
|
self.set_missing_values()
|
||||||
|
self.validate_finance_books()
|
||||||
if not self.split_from:
|
if not self.split_from:
|
||||||
self.prepare_depreciation_data()
|
self.prepare_depreciation_data()
|
||||||
self.validate_gross_and_purchase_amount()
|
self.validate_gross_and_purchase_amount()
|
||||||
@@ -206,6 +207,27 @@ class Asset(AccountsController):
|
|||||||
finance_books = get_item_details(self.item_code, self.asset_category)
|
finance_books = get_item_details(self.item_code, self.asset_category)
|
||||||
self.set("finance_books", finance_books)
|
self.set("finance_books", finance_books)
|
||||||
|
|
||||||
|
def validate_finance_books(self):
|
||||||
|
if not self.calculate_depreciation or len(self.finance_books) == 1:
|
||||||
|
return
|
||||||
|
|
||||||
|
finance_books = set()
|
||||||
|
|
||||||
|
for d in self.finance_books:
|
||||||
|
if d.finance_book in finance_books:
|
||||||
|
frappe.throw(
|
||||||
|
_("Row #{}: Please use a different Finance Book.").format(d.idx),
|
||||||
|
title=_("Duplicate Finance Book"),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
finance_books.add(d.finance_book)
|
||||||
|
|
||||||
|
if not d.finance_book:
|
||||||
|
frappe.throw(
|
||||||
|
_("Row #{}: Finance Book should not be empty since you're using multiple.").format(d.idx),
|
||||||
|
title=_("Missing Finance Book"),
|
||||||
|
)
|
||||||
|
|
||||||
def validate_asset_values(self):
|
def validate_asset_values(self):
|
||||||
if not self.asset_category:
|
if not self.asset_category:
|
||||||
self.asset_category = frappe.get_cached_value("Item", self.item_code, "asset_category")
|
self.asset_category = frappe.get_cached_value("Item", self.item_code, "asset_category")
|
||||||
|
|||||||
@@ -1332,6 +1332,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
asset.append(
|
asset.append(
|
||||||
"finance_books",
|
"finance_books",
|
||||||
{
|
{
|
||||||
|
"finance_book": "Test Finance Book 1",
|
||||||
"depreciation_method": "Straight Line",
|
"depreciation_method": "Straight Line",
|
||||||
"frequency_of_depreciation": 1,
|
"frequency_of_depreciation": 1,
|
||||||
"total_number_of_depreciations": 3,
|
"total_number_of_depreciations": 3,
|
||||||
@@ -1342,6 +1343,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
asset.append(
|
asset.append(
|
||||||
"finance_books",
|
"finance_books",
|
||||||
{
|
{
|
||||||
|
"finance_book": "Test Finance Book 2",
|
||||||
"depreciation_method": "Straight Line",
|
"depreciation_method": "Straight Line",
|
||||||
"frequency_of_depreciation": 1,
|
"frequency_of_depreciation": 1,
|
||||||
"total_number_of_depreciations": 6,
|
"total_number_of_depreciations": 6,
|
||||||
@@ -1352,6 +1354,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
asset.append(
|
asset.append(
|
||||||
"finance_books",
|
"finance_books",
|
||||||
{
|
{
|
||||||
|
"finance_book": "Test Finance Book 3",
|
||||||
"depreciation_method": "Straight Line",
|
"depreciation_method": "Straight Line",
|
||||||
"frequency_of_depreciation": 12,
|
"frequency_of_depreciation": 12,
|
||||||
"total_number_of_depreciations": 3,
|
"total_number_of_depreciations": 3,
|
||||||
@@ -1381,6 +1384,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
asset.append(
|
asset.append(
|
||||||
"finance_books",
|
"finance_books",
|
||||||
{
|
{
|
||||||
|
"finance_book": "Test Finance Book 1",
|
||||||
"depreciation_method": "Straight Line",
|
"depreciation_method": "Straight Line",
|
||||||
"frequency_of_depreciation": 12,
|
"frequency_of_depreciation": 12,
|
||||||
"total_number_of_depreciations": 3,
|
"total_number_of_depreciations": 3,
|
||||||
@@ -1391,6 +1395,7 @@ class TestDepreciationBasics(AssetSetup):
|
|||||||
asset.append(
|
asset.append(
|
||||||
"finance_books",
|
"finance_books",
|
||||||
{
|
{
|
||||||
|
"finance_book": "Test Finance Book 2",
|
||||||
"depreciation_method": "Straight Line",
|
"depreciation_method": "Straight Line",
|
||||||
"frequency_of_depreciation": 12,
|
"frequency_of_depreciation": 12,
|
||||||
"total_number_of_depreciations": 6,
|
"total_number_of_depreciations": 6,
|
||||||
@@ -1647,6 +1652,15 @@ def create_asset_data():
|
|||||||
if not frappe.db.exists("Location", "Test Location"):
|
if not frappe.db.exists("Location", "Test Location"):
|
||||||
frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert()
|
frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert()
|
||||||
|
|
||||||
|
if not frappe.db.exists("Finance Book", "Test Finance Book 1"):
|
||||||
|
frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 1"}).insert()
|
||||||
|
|
||||||
|
if not frappe.db.exists("Finance Book", "Test Finance Book 2"):
|
||||||
|
frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 2"}).insert()
|
||||||
|
|
||||||
|
if not frappe.db.exists("Finance Book", "Test Finance Book 3"):
|
||||||
|
frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 3"}).insert()
|
||||||
|
|
||||||
|
|
||||||
def create_asset(**args):
|
def create_asset(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
Reference in New Issue
Block a user