Skip to content

Commit

Permalink
Merge pull request #37044 from frappe/version-13-hotfix
Browse files Browse the repository at this point in the history
chore: release v13
  • Loading branch information
deepeshgarg007 authored Sep 12, 2023
2 parents efab1e7 + 437a294 commit cd99630
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def validate(self):
self.validate_item()
self.validate_cost_center()
self.set_missing_values()
self.validate_finance_books()
self.prepare_depreciation_data()
self.validate_gross_and_purchase_amount()
if self.get("schedules"):
Expand Down Expand Up @@ -197,6 +198,27 @@ def set_missing_values(self):
finance_books = get_item_details(self.item_code, self.asset_category)
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):
if not self.asset_category:
self.asset_category = frappe.get_cached_value("Item", self.item_code, "asset_category")
Expand Down
14 changes: 14 additions & 0 deletions erpnext/assets/doctype/asset/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ def test_clear_depreciation_schedule_for_multiple_finance_books(self):
asset.append(
"finance_books",
{
"finance_book": "Test Finance Book 1",
"depreciation_method": "Straight Line",
"frequency_of_depreciation": 1,
"total_number_of_depreciations": 3,
Expand All @@ -1297,6 +1298,7 @@ def test_clear_depreciation_schedule_for_multiple_finance_books(self):
asset.append(
"finance_books",
{
"finance_book": "Test Finance Book 2",
"depreciation_method": "Straight Line",
"frequency_of_depreciation": 1,
"total_number_of_depreciations": 6,
Expand All @@ -1307,6 +1309,7 @@ def test_clear_depreciation_schedule_for_multiple_finance_books(self):
asset.append(
"finance_books",
{
"finance_book": "Test Finance Book 3",
"depreciation_method": "Straight Line",
"frequency_of_depreciation": 12,
"total_number_of_depreciations": 3,
Expand Down Expand Up @@ -1336,6 +1339,7 @@ def test_depreciation_schedules_are_set_up_for_multiple_finance_books(self):
asset.append(
"finance_books",
{
"finance_book": "Test Finance Book 1",
"depreciation_method": "Straight Line",
"frequency_of_depreciation": 12,
"total_number_of_depreciations": 3,
Expand All @@ -1346,6 +1350,7 @@ def test_depreciation_schedules_are_set_up_for_multiple_finance_books(self):
asset.append(
"finance_books",
{
"finance_book": "Test Finance Book 2",
"depreciation_method": "Straight Line",
"frequency_of_depreciation": 12,
"total_number_of_depreciations": 6,
Expand Down Expand Up @@ -1581,6 +1586,15 @@ def create_asset_data():
if not frappe.db.exists("Location", "Test Location"):
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):
args = frappe._dict(args)
Expand Down

0 comments on commit cd99630

Please sign in to comment.