Merge pull request #51509 from khushi8112/fix-test-cases

fix: use system configured float precision for depreciation rate
This commit is contained in:
Khushi Rawat
2026-01-13 11:58:58 +05:30
committed by GitHub
2 changed files with 24 additions and 14 deletions

View File

@@ -592,9 +592,7 @@ class Asset(AccountsController):
def set_depreciation_rate(self):
for d in self.get("finance_books"):
self.validate_asset_finance_books(d)
d.rate_of_depreciation = flt(
self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation")
)
d.rate_of_depreciation = self.get_depreciation_rate(d, on_validate=True)
def validate_asset_finance_books(self, row):
row.expected_value_after_useful_life = flt(
@@ -984,7 +982,7 @@ class Asset(AccountsController):
if isinstance(args, str):
args = json.loads(args)
rate_field_precision = frappe.get_precision(args.doctype, "rate_of_depreciation") or 2
rate_field_precision = frappe.get_single_value("System Settings", "float_precision") or 2
if args.get("depreciation_method") == "Double Declining Balance":
return self.get_double_declining_balance_rate(args, rate_field_precision)

View File

@@ -826,6 +826,18 @@ class TestAsset(AssetSetup):
class TestDepreciationMethods(AssetSetup):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._old_float_precision = frappe.db.get_single_value("System Settings", "float_precision")
frappe.db.set_single_value("System Settings", "float_precision", 2)
@classmethod
def tearDownClass(cls):
frappe.db.set_single_value("System Settings", "float_precision", cls._old_float_precision)
super().tearDownClass()
def test_schedule_for_straight_line_method(self):
asset = create_asset(
calculate_depreciation=1,
@@ -923,9 +935,9 @@ class TestDepreciationMethods(AssetSetup):
self.assertEqual(asset.status, "Draft")
expected_schedules = [
["2030-12-31", 66667.00, 66667.00],
["2031-12-31", 22222.11, 88889.11],
["2032-12-31", 1110.89, 90000.0],
["2030-12-31", 66670.0, 66670.0],
["2031-12-31", 22221.11, 88891.11],
["2032-12-31", 1108.89, 90000.0],
]
schedules = [
@@ -951,7 +963,7 @@ class TestDepreciationMethods(AssetSetup):
self.assertEqual(asset.status, "Draft")
expected_schedules = [["2031-12-31", 33333.50, 83333.50], ["2032-12-31", 6666.50, 90000.0]]
expected_schedules = [["2031-12-31", 33335.0, 83335.0], ["2032-12-31", 6665.0, 90000.0]]
schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
@@ -1069,12 +1081,12 @@ class TestDepreciationMethods(AssetSetup):
)
expected_schedules = [
["2022-02-28", 337.72, 337.72],
["2022-03-31", 675.45, 1013.17],
["2022-04-30", 675.45, 1688.62],
["2022-05-31", 675.45, 2364.07],
["2022-06-30", 675.45, 3039.52],
["2022-07-15", 1960.48, 5000.0],
["2022-02-28", 337.71, 337.71],
["2022-03-31", 675.42, 1013.13],
["2022-04-30", 675.42, 1688.55],
["2022-05-31", 675.42, 2363.97],
["2022-06-30", 675.42, 3039.39],
["2022-07-15", 1960.61, 5000.0],
]
schedules = [