chore: fixing all tests
This commit is contained in:
parent
df134c7c5b
commit
22ef342ac7
@ -1192,6 +1192,7 @@ class SalesInvoice(SellingController):
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
reset_depreciation_schedule(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
else:
|
||||
if asset.calculate_depreciation:
|
||||
@ -1202,6 +1203,7 @@ class SalesInvoice(SellingController):
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
depreciate_asset(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(
|
||||
asset, item.base_net_amount, item.finance_book, self.get("doctype"), self.get("name")
|
||||
|
@ -21,6 +21,9 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_comp
|
||||
from erpnext.accounts.utils import PaymentEntryUnlinkError
|
||||
from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries
|
||||
from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_depr_schedule,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import update_invoice_status
|
||||
from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data
|
||||
from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency
|
||||
@ -2774,7 +2777,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
["2021-09-30", 5041.1, 26407.22],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name)):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
@ -2805,7 +2808,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
expected_values = [["2020-12-31", 30000, 30000], ["2021-12-31", 30000, 60000]]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name)):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
@ -2834,7 +2837,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
["2025-06-06", 18633.88, 100000.0, False],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name)):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
|
@ -11,8 +11,8 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
)
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_asset_depr_schedule_doc,
|
||||
get_asset_depr_schedule_name,
|
||||
get_depr_schedule,
|
||||
get_temp_asset_depr_schedule_doc,
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones,
|
||||
)
|
||||
@ -220,6 +220,13 @@ def scrap_asset(asset_name):
|
||||
|
||||
date = today()
|
||||
|
||||
notes = _("This schedule was created when Asset {0} was scrapped.").format(
|
||||
get_link_to_form(asset.doctype, asset.name)
|
||||
)
|
||||
|
||||
depreciate_asset(asset, date, notes)
|
||||
asset.reload()
|
||||
|
||||
depreciation_series = frappe.get_cached_value(
|
||||
"Company", asset.company, "series_for_depreciation_entry"
|
||||
)
|
||||
@ -238,12 +245,6 @@ def scrap_asset(asset_name):
|
||||
je.flags.ignore_permissions = True
|
||||
je.submit()
|
||||
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was scrapped through Journal Entry {1}."
|
||||
).format(get_link_to_form(asset.doctype, asset.name), get_link_to_form(je.doctype, je.name))
|
||||
|
||||
depreciate_asset(asset, date, notes)
|
||||
|
||||
frappe.db.set_value("Asset", asset_name, "disposal_date", date)
|
||||
frappe.db.set_value("Asset", asset_name, "journal_entry_for_scrap", je.name)
|
||||
asset.set_status("Scrapped")
|
||||
@ -259,9 +260,9 @@ def restore_asset(asset_name):
|
||||
|
||||
je = asset.journal_entry_for_scrap
|
||||
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was restored after being scrapped by Journal Entry {1}."
|
||||
).format(get_link_to_form(asset.doctype, asset.name), get_link_to_form(je.doctype, je.name))
|
||||
notes = _("This schedule was created when Asset {0} was restored.").format(
|
||||
get_link_to_form(asset.doctype, asset.name)
|
||||
)
|
||||
|
||||
reset_depreciation_schedule(asset, asset.disposal_date, notes)
|
||||
|
||||
@ -274,20 +275,28 @@ def restore_asset(asset_name):
|
||||
|
||||
|
||||
def depreciate_asset(asset_doc, date, notes):
|
||||
asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
asset_doc, notes, date_of_disposal=date
|
||||
)
|
||||
|
||||
asset_doc.save()
|
||||
|
||||
make_depreciation_entry_for_all_asset_depr_schedules(asset_doc, date)
|
||||
|
||||
|
||||
def reset_depreciation_schedule(asset_doc, date, notes):
|
||||
asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
asset_doc, notes, date_of_return=date
|
||||
)
|
||||
|
||||
modify_depreciation_schedule_for_asset_repairs(asset_doc)
|
||||
|
||||
asset_doc.save()
|
||||
|
||||
|
||||
def modify_depreciation_schedule_for_asset_repairs(asset):
|
||||
asset_repairs = frappe.get_all(
|
||||
@ -307,9 +316,9 @@ def modify_depreciation_schedule_for_asset_repairs(asset):
|
||||
|
||||
def reverse_depreciation_entry_made_after_disposal(asset, date):
|
||||
for row in asset.get("finance_books"):
|
||||
depr_schedule = get_depr_schedule(asset.name, row.finance_book)
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset.name, row.finance_book)
|
||||
|
||||
for schedule_idx, schedule in enumerate(depr_schedule):
|
||||
for schedule_idx, schedule in enumerate(asset_depr_schedule_doc.get("depreciation_schedule")):
|
||||
if schedule.schedule_date == date:
|
||||
if not disposal_was_made_on_original_schedule_date(
|
||||
schedule_idx, row, date
|
||||
@ -321,10 +330,12 @@ def reverse_depreciation_entry_made_after_disposal(asset, date):
|
||||
reverse_journal_entry.submit()
|
||||
|
||||
frappe.flags.is_reverse_depr_entry = False
|
||||
asset_depr_schedule_doc.flags.ignore_validate_update_after_submit = True
|
||||
asset.flags.ignore_validate_update_after_submit = True
|
||||
schedule.journal_entry = None
|
||||
depreciation_amount = get_depreciation_amount_in_je(reverse_journal_entry)
|
||||
row.value_after_depreciation += depreciation_amount
|
||||
asset_depr_schedule_doc.save()
|
||||
asset.save()
|
||||
|
||||
|
||||
|
@ -527,6 +527,8 @@ class AssetCapitalization(StockController):
|
||||
get_link_to_form(asset_doc.doctype, asset_doc.name), get_link_to_form(self.doctype, self.name)
|
||||
)
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(asset_doc, notes)
|
||||
asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
asset_doc.save()
|
||||
elif self.docstatus == 2:
|
||||
for item in self.asset_items:
|
||||
asset = self.get_asset(item)
|
||||
|
@ -12,6 +12,9 @@ from erpnext.assets.doctype.asset.test_asset import (
|
||||
create_asset_data,
|
||||
set_depreciation_settings_in_company,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_depr_schedule,
|
||||
)
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
|
||||
|
||||
@ -283,7 +286,9 @@ class TestAssetCapitalization(unittest.TestCase):
|
||||
self.assertEqual(consumed_asset.status, "Decapitalized")
|
||||
|
||||
consumed_depreciation_schedule = [
|
||||
d for d in consumed_asset.schedules if getdate(d.schedule_date) == getdate(capitalization_date)
|
||||
d
|
||||
for d in get_depr_schedule(consumed_asset.name)
|
||||
if getdate(d.schedule_date) == getdate(capitalization_date)
|
||||
]
|
||||
self.assertTrue(
|
||||
consumed_depreciation_schedule and consumed_depreciation_schedule[0].journal_entry
|
||||
|
@ -80,10 +80,17 @@ def update_draft_asset_depr_schedules(asset_doc):
|
||||
|
||||
|
||||
def prepare_draft_asset_depr_schedule_data(
|
||||
asset_depr_schedule_doc, asset_doc, row, date_of_disposal=None, date_of_return=None
|
||||
asset_depr_schedule_doc,
|
||||
asset_doc,
|
||||
row,
|
||||
date_of_disposal=None,
|
||||
date_of_return=None,
|
||||
update_asset_finance_book_row=True,
|
||||
):
|
||||
set_draft_asset_depr_schedule_details(asset_depr_schedule_doc, asset_doc, row)
|
||||
make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, date_of_disposal)
|
||||
make_depr_schedule(
|
||||
asset_depr_schedule_doc, asset_doc, row, date_of_disposal, update_asset_finance_book_row
|
||||
)
|
||||
set_accumulated_depreciation(asset_depr_schedule_doc, row, date_of_disposal, date_of_return)
|
||||
|
||||
|
||||
@ -129,11 +136,18 @@ def make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
new_asset_depr_schedule_doc.submit()
|
||||
|
||||
|
||||
def get_temp_asset_depr_schedule_doc(asset_doc, row, date_of_disposal=None, date_of_return=None):
|
||||
def get_temp_asset_depr_schedule_doc(
|
||||
asset_doc, row, date_of_disposal=None, date_of_return=None, update_asset_finance_book_row=False
|
||||
):
|
||||
asset_depr_schedule_doc = frappe.new_doc("Asset Depreciation Schedule")
|
||||
|
||||
prepare_draft_asset_depr_schedule_data(
|
||||
asset_depr_schedule_doc, asset_doc, row, date_of_disposal, date_of_return
|
||||
asset_depr_schedule_doc,
|
||||
asset_doc,
|
||||
row,
|
||||
date_of_disposal,
|
||||
date_of_return,
|
||||
update_asset_finance_book_row,
|
||||
)
|
||||
|
||||
return asset_depr_schedule_doc
|
||||
@ -184,7 +198,9 @@ def get_asset_depr_schedule_doc(asset_name, finance_book=None):
|
||||
return asset_depr_schedule_doc
|
||||
|
||||
|
||||
def make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, date_of_disposal):
|
||||
def make_depr_schedule(
|
||||
asset_depr_schedule_doc, asset_doc, row, date_of_disposal, update_asset_finance_book_row=True
|
||||
):
|
||||
if row.depreciation_method != "Manual" and not asset_depr_schedule_doc.get(
|
||||
"depreciation_schedule"
|
||||
):
|
||||
@ -195,7 +211,9 @@ def make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, date_of_disposal
|
||||
|
||||
start = clear_depr_schedule(asset_depr_schedule_doc)
|
||||
|
||||
_make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, start, date_of_disposal)
|
||||
_make_depr_schedule(
|
||||
asset_depr_schedule_doc, asset_doc, row, start, date_of_disposal, update_asset_finance_book_row
|
||||
)
|
||||
|
||||
|
||||
def clear_depr_schedule(asset_depr_schedule_doc):
|
||||
@ -216,12 +234,17 @@ def clear_depr_schedule(asset_depr_schedule_doc):
|
||||
return start
|
||||
|
||||
|
||||
def _make_depr_schedule(asset_depr_schedule_doc, asset_doc, row, start, date_of_disposal):
|
||||
def _make_depr_schedule(
|
||||
asset_depr_schedule_doc, asset_doc, row, start, date_of_disposal, update_asset_finance_book_row
|
||||
):
|
||||
asset_doc.validate_asset_finance_books(row)
|
||||
|
||||
value_after_depreciation = asset_doc._get_value_after_depreciation(row)
|
||||
row.value_after_depreciation = value_after_depreciation
|
||||
|
||||
if update_asset_finance_book_row:
|
||||
row.db_update()
|
||||
|
||||
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint(
|
||||
asset_doc.number_of_depreciations_booked
|
||||
)
|
||||
|
@ -59,7 +59,9 @@ class AssetRepair(AccountsController):
|
||||
notes = _("This schedule was created when Asset Repair {0} was submitted.").format(
|
||||
get_link_to_form(self.doctype, self.name)
|
||||
)
|
||||
self.asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(self.asset_doc, notes)
|
||||
self.asset_doc.save()
|
||||
|
||||
def before_cancel(self):
|
||||
self.asset_doc = frappe.get_doc("Asset", self.asset)
|
||||
@ -81,7 +83,9 @@ class AssetRepair(AccountsController):
|
||||
notes = _("This schedule was created when Asset Repair {0} was cancelled.").format(
|
||||
get_link_to_form(self.doctype, self.name)
|
||||
)
|
||||
self.asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(self.asset_doc, notes)
|
||||
self.asset_doc.save()
|
||||
|
||||
def check_repair_status(self):
|
||||
if self.repair_status == "Pending":
|
||||
|
@ -12,6 +12,9 @@ from erpnext.assets.doctype.asset.test_asset import (
|
||||
create_asset_data,
|
||||
set_depreciation_settings_in_company,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_depr_schedule,
|
||||
)
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
|
||||
|
||||
@ -238,7 +241,7 @@ class TestAssetRepair(unittest.TestCase):
|
||||
|
||||
self.assertEqual((initial_num_of_depreciations + 1), num_of_depreciations(asset))
|
||||
self.assertEqual(
|
||||
asset.schedules[-1].accumulated_depreciation_amount,
|
||||
get_depr_schedule(asset.name)[-1].accumulated_depreciation_amount,
|
||||
asset.finance_books[0].value_after_depreciation,
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import date_diff, flt, formatdate, getdate
|
||||
from frappe.utils import date_diff, flt, formatdate, get_link_to_form, getdate
|
||||
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_checks_for_pl_and_bs_accounts,
|
||||
@ -123,9 +123,16 @@ class AssetValueAdjustment(Document):
|
||||
|
||||
new_asset_depr_schedule_doc = frappe.copy_doc(current_asset_depr_schedule_doc)
|
||||
|
||||
new_asset_depr_schedule_doc.notes = "Asset value adjustment"
|
||||
|
||||
current_asset_depr_schedule_doc.cancel()
|
||||
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was adjusted through Asset Value Adjustment {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.get("doctype"), self.get("name")),
|
||||
)
|
||||
new_asset_depr_schedule_doc.notes = notes
|
||||
|
||||
new_asset_depr_schedule_doc.insert()
|
||||
|
||||
depr_schedule = new_asset_depr_schedule_doc.get("depreciation_schedule")
|
||||
|
Loading…
x
Reference in New Issue
Block a user