refactor: asset capitalization form cleanup

This commit is contained in:
khushi8112
2026-02-06 01:55:11 +05:30
parent e8e8d233ab
commit eb7932ed73
4 changed files with 85 additions and 137 deletions

View File

@@ -17,10 +17,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
refresh() { refresh() {
this.show_general_ledger(); this.show_general_ledger();
if ( if (this.frm.doc.stock_items && this.frm.doc.stock_items.length) {
(this.frm.doc.stock_items && this.frm.doc.stock_items.length) ||
!this.frm.doc.target_is_fixed_asset
) {
this.show_stock_ledger(); this.show_stock_ledger();
} }
@@ -240,10 +237,6 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
this.calculate_totals(); this.calculate_totals();
} }
target_qty() {
this.calculate_totals();
}
rate() { rate() {
this.calculate_totals(); this.calculate_totals();
} }
@@ -485,10 +478,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
me.frm.doc.stock_items_total + me.frm.doc.asset_items_total + me.frm.doc.service_items_total; me.frm.doc.stock_items_total + me.frm.doc.asset_items_total + me.frm.doc.service_items_total;
me.frm.doc.total_value = flt(me.frm.doc.total_value, precision("total_value")); me.frm.doc.total_value = flt(me.frm.doc.total_value, precision("total_value"));
me.frm.doc.target_qty = flt(me.frm.doc.target_qty, precision("target_qty")); me.frm.doc.target_incoming_rate = me.frm.doc.total_value;
me.frm.doc.target_incoming_rate = me.frm.doc.target_qty
? me.frm.doc.total_value / flt(me.frm.doc.target_qty)
: me.frm.doc.total_value;
me.frm.refresh_fields(); me.frm.refresh_fields();
} }

View File

@@ -9,30 +9,33 @@
"field_order": [ "field_order": [
"title", "title",
"naming_series", "naming_series",
"company",
"target_asset", "target_asset",
"target_asset_name", "target_asset_name",
"target_item_code",
"finance_book",
"target_qty",
"column_break_9", "column_break_9",
"company", "finance_book",
"posting_date", "posting_date",
"posting_time", "posting_time",
"set_posting_time", "set_posting_time",
"target_batch_no", "target_item_code",
"target_serial_no",
"amended_from", "amended_from",
"target_is_fixed_asset",
"target_has_batch_no",
"target_has_serial_no",
"section_break_16", "section_break_16",
"stock_items", "stock_items",
"section_break_urtz",
"column_break_gqep",
"column_break_yvlx",
"stock_items_total", "stock_items_total",
"section_break_26", "section_break_26",
"asset_items", "asset_items",
"section_break_arbh",
"column_break_boeu",
"column_break_qecy",
"asset_items_total", "asset_items_total",
"service_expenses_section", "service_expenses_section",
"service_items", "service_items",
"section_break_ptna",
"column_break_szvh",
"column_break_katv",
"service_items_total", "service_items_total",
"totals_section", "totals_section",
"total_value", "total_value",
@@ -55,20 +58,12 @@
"depends_on": "eval:(doc.target_item_code && !doc.__islocal)", "depends_on": "eval:(doc.target_item_code && !doc.__islocal)",
"fieldname": "target_item_code", "fieldname": "target_item_code",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Target Item Code", "label": "Target Item Code",
"options": "Item", "options": "Item",
"read_only": 1 "read_only": 1
}, },
{
"default": "0",
"fetch_from": "target_item_code.is_fixed_asset",
"fieldname": "target_is_fixed_asset",
"fieldtype": "Check",
"hidden": 1,
"label": "Target Is Fixed Asset",
"read_only": 1
},
{ {
"fieldname": "target_asset", "fieldname": "target_asset",
"fieldtype": "Link", "fieldtype": "Link",
@@ -143,6 +138,7 @@
"depends_on": "eval:doc.docstatus == 0 || (doc.stock_items && doc.stock_items.length)", "depends_on": "eval:doc.docstatus == 0 || (doc.stock_items && doc.stock_items.length)",
"fieldname": "section_break_16", "fieldname": "section_break_16",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hide_border": 1,
"label": "Consumed Stock Items" "label": "Consumed Stock Items"
}, },
{ {
@@ -151,49 +147,11 @@
"label": "Stock Items", "label": "Stock Items",
"options": "Asset Capitalization Stock Item" "options": "Asset Capitalization Stock Item"
}, },
{
"depends_on": "target_has_batch_no",
"fieldname": "target_batch_no",
"fieldtype": "Link",
"label": "Target Batch No",
"options": "Batch"
},
{
"default": "1",
"fieldname": "target_qty",
"fieldtype": "Float",
"hidden": 1,
"label": "Target Qty",
"read_only": 1
},
{
"default": "0",
"fetch_from": "target_item_code.has_batch_no",
"fieldname": "target_has_batch_no",
"fieldtype": "Check",
"hidden": 1,
"label": "Target Has Batch No",
"read_only": 1
},
{
"default": "0",
"fetch_from": "target_item_code.has_serial_no",
"fieldname": "target_has_serial_no",
"fieldtype": "Check",
"hidden": 1,
"label": "Target Has Serial No",
"read_only": 1
},
{
"depends_on": "target_has_serial_no",
"fieldname": "target_serial_no",
"fieldtype": "Small Text",
"label": "Target Serial No"
},
{ {
"depends_on": "eval:doc.docstatus == 0 || (doc.asset_items && doc.asset_items.length)", "depends_on": "eval:doc.docstatus == 0 || (doc.asset_items && doc.asset_items.length)",
"fieldname": "section_break_26", "fieldname": "section_break_26",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hide_border": 1,
"label": "Consumed Assets" "label": "Consumed Assets"
}, },
{ {
@@ -203,6 +161,7 @@
"options": "Asset Capitalization Asset Item" "options": "Asset Capitalization Asset Item"
}, },
{ {
"depends_on": "eval: doc.stock_items_total",
"fieldname": "stock_items_total", "fieldname": "stock_items_total",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Consumed Stock Total Value", "label": "Consumed Stock Total Value",
@@ -210,6 +169,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "eval: doc.asset_items_total",
"fieldname": "asset_items_total", "fieldname": "asset_items_total",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Consumed Asset Total Value", "label": "Consumed Asset Total Value",
@@ -226,6 +186,7 @@
"depends_on": "eval:doc.docstatus == 0 || (doc.service_items && doc.service_items.length)", "depends_on": "eval:doc.docstatus == 0 || (doc.service_items && doc.service_items.length)",
"fieldname": "service_expenses_section", "fieldname": "service_expenses_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hide_border": 1,
"label": "Service Expenses" "label": "Service Expenses"
}, },
{ {
@@ -235,6 +196,7 @@
"options": "Asset Capitalization Service Item" "options": "Asset Capitalization Service Item"
}, },
{ {
"depends_on": "eval: doc.service_items_total",
"fieldname": "service_items_total", "fieldname": "service_items_total",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Service Expense Total Amount", "label": "Service Expense Total Amount",
@@ -277,10 +239,10 @@
"options": "Cost Center" "options": "Cost Center"
}, },
{ {
"fieldname": "project", "fieldname": "project",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Project", "label": "Project",
"options": "Project" "options": "Project"
}, },
{ {
"fieldname": "dimension_col_break", "fieldname": "dimension_col_break",
@@ -292,12 +254,48 @@
"label": "Target Fixed Asset Account", "label": "Target Fixed Asset Account",
"options": "Account", "options": "Account",
"read_only": 1 "read_only": 1
},
{
"fieldname": "section_break_urtz",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_gqep",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_yvlx",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_arbh",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_boeu",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_qecy",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_ptna",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_szvh",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_katv",
"fieldtype": "Column Break"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2025-05-20 15:15:12.110035", "modified": "2026-02-06 01:52:41.890713",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Capitalization", "name": "Asset Capitalization",

View File

@@ -38,9 +38,6 @@ force_fields = [
"target_asset_name", "target_asset_name",
"item_name", "item_name",
"asset_name", "asset_name",
"target_is_fixed_asset",
"target_has_serial_no",
"target_has_batch_no",
"stock_uom", "stock_uom",
"fixed_asset_account", "fixed_asset_account",
"valuation_rate", "valuation_rate",
@@ -75,6 +72,7 @@ class AssetCapitalization(StockController):
naming_series: DF.Literal["ACC-ASC-.YYYY.-"] naming_series: DF.Literal["ACC-ASC-.YYYY.-"]
posting_date: DF.Date posting_date: DF.Date
posting_time: DF.Time posting_time: DF.Time
project: DF.Link | None
service_items: DF.Table[AssetCapitalizationServiceItem] service_items: DF.Table[AssetCapitalizationServiceItem]
service_items_total: DF.Currency service_items_total: DF.Currency
set_posting_time: DF.Check set_posting_time: DF.Check
@@ -82,15 +80,9 @@ class AssetCapitalization(StockController):
stock_items_total: DF.Currency stock_items_total: DF.Currency
target_asset: DF.Link | None target_asset: DF.Link | None
target_asset_name: DF.Data | None target_asset_name: DF.Data | None
target_batch_no: DF.Link | None
target_fixed_asset_account: DF.Link | None target_fixed_asset_account: DF.Link | None
target_has_batch_no: DF.Check
target_has_serial_no: DF.Check
target_incoming_rate: DF.Currency target_incoming_rate: DF.Currency
target_is_fixed_asset: DF.Check
target_item_code: DF.Link | None target_item_code: DF.Link | None
target_qty: DF.Float
target_serial_no: DF.SmallText | None
title: DF.Data | None title: DF.Data | None
total_value: DF.Currency total_value: DF.Currency
# end: auto-generated types # end: auto-generated types
@@ -189,15 +181,6 @@ class AssetCapitalization(StockController):
if not target_item.is_fixed_asset: if not target_item.is_fixed_asset:
frappe.throw(_("Target Item {0} must be a Fixed Asset item").format(target_item.name)) frappe.throw(_("Target Item {0} must be a Fixed Asset item").format(target_item.name))
if target_item.is_fixed_asset:
self.target_qty = 1
if flt(self.target_qty) <= 0:
frappe.throw(_("Target Qty must be a positive number"))
if not target_item.has_batch_no:
self.target_batch_no = None
if not target_item.has_serial_no:
self.target_serial_no = ""
self.validate_item(target_item) self.validate_item(target_item)
def validate_target_asset(self): def validate_target_asset(self):
@@ -379,8 +362,7 @@ class AssetCapitalization(StockController):
self.total_value = self.stock_items_total + self.asset_items_total + self.service_items_total self.total_value = self.stock_items_total + self.asset_items_total + self.service_items_total
self.total_value = flt(self.total_value, self.precision("total_value")) self.total_value = flt(self.total_value, self.precision("total_value"))
self.target_qty = flt(self.target_qty, self.precision("target_qty")) self.target_incoming_rate = self.total_value
self.target_incoming_rate = self.total_value / self.target_qty
def update_stock_ledger(self): def update_stock_ledger(self):
sl_entries = [] sl_entries = []
@@ -549,22 +531,21 @@ class AssetCapitalization(StockController):
def get_gl_entries_for_target_item( def get_gl_entries_for_target_item(
self, gl_entries, target_account, target_against, precision, composite_component_value self, gl_entries, target_account, target_against, precision, composite_component_value
): ):
if self.target_is_fixed_asset: total_value = flt(self.total_value - composite_component_value, precision)
total_value = flt(self.total_value - composite_component_value, precision) if total_value:
if total_value: # Capitalization
# Capitalization gl_entries.append(
gl_entries.append( self.get_gl_dict(
self.get_gl_dict( {
{ "account": target_account,
"account": target_account, "against": ", ".join(target_against),
"against": ", ".join(target_against), "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"remarks": self.get("remarks") or _("Accounting Entry for Asset"), "debit": total_value,
"debit": total_value, "cost_center": self.get("cost_center"),
"cost_center": self.get("cost_center"), },
}, item=self,
item=self,
)
) )
)
def update_target_asset(self): def update_target_asset(self):
total_target_asset_value = flt(self.total_value, self.precision("total_value")) total_target_asset_value = flt(self.total_value, self.precision("total_value"))
@@ -610,14 +591,13 @@ class AssetCapitalization(StockController):
def set_consumed_asset_status(self, asset): def set_consumed_asset_status(self, asset):
if self.docstatus == 1: if self.docstatus == 1:
if self.target_is_fixed_asset: asset.set_status("Capitalized")
asset.set_status("Capitalized") add_asset_activity(
add_asset_activity( asset.name,
asset.name, _("Asset capitalized after Asset Capitalization {0} was submitted").format(
_("Asset capitalized after Asset Capitalization {0} was submitted").format( get_link_to_form("Asset Capitalization", self.name)
get_link_to_form("Asset Capitalization", self.name) ),
), )
)
else: else:
asset.set_status() asset.set_status()
add_asset_activity( add_asset_activity(
@@ -639,17 +619,6 @@ def get_target_item_details(item_code=None, company=None):
# Set Item Details # Set Item Details
out.target_item_name = item.item_name out.target_item_name = item.item_name
out.target_is_fixed_asset = cint(item.is_fixed_asset)
out.target_has_batch_no = cint(item.has_batch_no)
out.target_has_serial_no = cint(item.has_serial_no)
if out.target_is_fixed_asset:
out.target_qty = 1
if not out.target_has_batch_no:
out.target_batch_no = None
if not out.target_has_serial_no:
out.target_serial_no = ""
# Cost Center # Cost Center
item_defaults = get_item_defaults(item.name, company) item_defaults = get_item_defaults(item.name, company)

View File

@@ -79,7 +79,6 @@ class TestAssetCapitalization(IntegrationTestCase):
) )
# Test Asset Capitalization values # Test Asset Capitalization values
self.assertEqual(asset_capitalization.target_qty, 1)
self.assertEqual(asset_capitalization.stock_items[0].valuation_rate, stock_rate) self.assertEqual(asset_capitalization.stock_items[0].valuation_rate, stock_rate)
self.assertEqual(asset_capitalization.stock_items[0].amount, stock_amount) self.assertEqual(asset_capitalization.stock_items[0].amount, stock_amount)
@@ -174,8 +173,6 @@ class TestAssetCapitalization(IntegrationTestCase):
) )
# Test Asset Capitalization values # Test Asset Capitalization values
self.assertEqual(asset_capitalization.target_qty, 1)
self.assertEqual(asset_capitalization.stock_items[0].valuation_rate, stock_rate) self.assertEqual(asset_capitalization.stock_items[0].valuation_rate, stock_rate)
self.assertEqual(asset_capitalization.stock_items[0].amount, stock_amount) self.assertEqual(asset_capitalization.stock_items[0].amount, stock_amount)
self.assertEqual(asset_capitalization.stock_items_total, stock_amount) self.assertEqual(asset_capitalization.stock_items_total, stock_amount)
@@ -260,8 +257,6 @@ class TestAssetCapitalization(IntegrationTestCase):
) )
# Test Asset Capitalization values # Test Asset Capitalization values
self.assertEqual(asset_capitalization.target_qty, 1)
self.assertEqual(asset_capitalization.stock_items[0].valuation_rate, stock_rate) self.assertEqual(asset_capitalization.stock_items[0].valuation_rate, stock_rate)
self.assertEqual(asset_capitalization.stock_items[0].amount, stock_amount) self.assertEqual(asset_capitalization.stock_items[0].amount, stock_amount)
self.assertEqual(asset_capitalization.stock_items_total, stock_amount) self.assertEqual(asset_capitalization.stock_items_total, stock_amount)
@@ -398,7 +393,6 @@ class TestAssetCapitalization(IntegrationTestCase):
) )
# Test Asset Capitalization values # Test Asset Capitalization values
self.assertEqual(asset_capitalization.target_qty, 1)
self.assertEqual(asset_capitalization.asset_items[0].asset_value, consumed_asset_value) self.assertEqual(asset_capitalization.asset_items[0].asset_value, consumed_asset_value)
actual_gle = get_actual_gle_dict(asset_capitalization.name) actual_gle = get_actual_gle_dict(asset_capitalization.name)
@@ -432,9 +426,6 @@ def create_asset_capitalization(**args):
"target_item_code": target_item_code, "target_item_code": target_item_code,
"target_asset": target_asset.name, "target_asset": target_asset.name,
"target_asset_location": "Test Location", "target_asset_location": "Test Location",
"target_qty": flt(args.target_qty) or 1,
"target_batch_no": args.target_batch_no,
"target_serial_no": args.target_serial_no,
"finance_book": args.finance_book, "finance_book": args.finance_book,
} }
) )