diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index c285a33f73e6..64e0e786f305 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -40,6 +40,7 @@ "dimensions_section", "cost_center", "column_break_lmnm", + "asset", "project", "more_info_section", "finance_book", @@ -298,6 +299,12 @@ "fieldtype": "Small Text", "label": "Voucher Subtype" }, + { + "fieldname": "asset", + "fieldtype": "Link", + "label": "Asset", + "options": "Asset" + }, { "fieldname": "dates_section", "fieldtype": "Section Break", diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index a7e7edb098dd..70d4ea822a58 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -34,6 +34,7 @@ class GLEntry(Document): against: DF.Text | None against_voucher: DF.DynamicLink | None against_voucher_type: DF.Link | None + asset: DF.Link | None company: DF.Link | None cost_center: DF.Link | None credit: DF.Currency diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index d55798c25fcd..eb8592725223 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1101,6 +1101,7 @@ def build_gl_map(self): "cost_center": d.cost_center, "project": d.project, "finance_book": self.finance_book, + "asset": getattr(d, "asset", None), }, item=d, ) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 8715f2b23547..bb514a83b594 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -752,6 +752,7 @@ def make_gl_entries(self): "debit": self.purchase_amount, "debit_in_account_currency": self.purchase_amount, "cost_center": self.cost_center, + "asset": self.name, }, item=self, ) diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 5bf0386d3a3b..bbfdd41bc4c5 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -285,6 +285,7 @@ def _make_journal_entry_for_depreciation( "reference_type": "Asset", "reference_name": asset.name, "cost_center": depreciation_cost_center, + "asset": asset.name, } debit_entry = { @@ -293,6 +294,7 @@ def _make_journal_entry_for_depreciation( "reference_type": "Asset", "reference_name": asset.name, "cost_center": depreciation_cost_center, + "asset": asset.name, } for dimension in accounting_dimensions: @@ -718,6 +720,7 @@ def get_gl_entries_on_asset_disposal( "credit": asset.gross_purchase_amount, "cost_center": depreciation_cost_center, "posting_date": date, + "asset": asset.name, }, item=asset, ), diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py index 2cdd94b15c8b..e2523a099a30 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py @@ -550,6 +550,7 @@ def get_gl_entries_for_consumed_asset_items(self, gl_entries, target_account, ta for gle in fixed_asset_gl_entries: gle["against"] = target_account + gle["asset"] = asset gl_entries.append(self.get_gl_dict(gle, item=item)) target_against.add(gle["account"]) diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index e42450e83e4e..6f17f7838cc8 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -338,6 +338,7 @@ def get_gl_entries_for_repair_cost(self, gl_entries, fixed_asset_account): "posting_date": getdate(), "against_voucher_type": "Purchase Invoice", "company": self.company, + "asset": self.asset, }, item=self, ) @@ -391,6 +392,7 @@ def get_gl_entries_for_consumed_items(self, gl_entries, fixed_asset_account): "against_voucher_type": "Stock Entry", "against_voucher": stock_entry.name, "company": self.company, + "asset": self.asset, }, item=self, ) diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py index 6766b827f7f8..0f8758b8a658 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py @@ -117,6 +117,7 @@ def make_depreciation_entry(self): credit_entry = { "account": fixed_asset_account, "credit_in_account_currency": -self.difference_amount, + "asset": self.asset, **entry_template, } debit_entry = { @@ -133,6 +134,7 @@ def make_depreciation_entry(self): debit_entry = { "account": fixed_asset_account, "debit_in_account_currency": self.difference_amount, + "asset": self.asset, **entry_template, } diff --git a/erpnext/patches.txt b/erpnext/patches.txt index f53dcd42581a..ed7888a52f96 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -391,5 +391,6 @@ erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter erpnext.patches.v15_0.migrate_old_item_wise_tax_detail_data_format erpnext.patches.v15_0.set_is_exchange_gain_loss_in_payment_entry_deductions erpnext.patches.v14_0.update_stock_uom_in_work_order_item +erpnext.patches.v15_0.link_asset_to_gl_entry erpnext.patches.v15_0.enable_allow_existing_serial_no -erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts \ No newline at end of file +erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts diff --git a/erpnext/patches/v15_0/link_asset_to_gl_entry.py b/erpnext/patches/v15_0/link_asset_to_gl_entry.py new file mode 100644 index 000000000000..8cdb687e758e --- /dev/null +++ b/erpnext/patches/v15_0/link_asset_to_gl_entry.py @@ -0,0 +1,71 @@ +import frappe +from frappe.query_builder import DocType +from frappe.query_builder.functions import Coalesce + + +def execute(): + if frappe.db.has_column("GL Entry", "asset"): + process_asset_submission_entries() + process_asset_repair_entries() + process_asset_related_journal_entries() # Revaluation and Depreciation + process_asset_capitalization_entries() + + +def process_asset_submission_entries(): + gl_entry = DocType("GL Entry") + asset = DocType("Asset") + + query = ( + frappe.qb.update(gl_entry) + .join(asset) + .on(gl_entry.voucher_no == asset.name) + .set(gl_entry.asset, Coalesce(asset.name, "")) + .where((gl_entry.voucher_type == "Asset") & (gl_entry.debit > 0) & (gl_entry.is_cancelled == 0)) + ) + query.run() + + +def process_asset_repair_entries(): + # nosemgrep + frappe.db.sql( + """ + UPDATE `tabGL Entry` AS gl + INNER JOIN `tabAsset Repair` AS ar + ON gl.voucher_no = ar.name + SET gl.asset = ar.asset + WHERE gl.voucher_type = 'Asset Repair' + AND gl.debit > 0 + """ + ) + + +def process_asset_related_journal_entries(): + gl_entry = DocType("GL Entry") + asset = DocType("Asset") + + query = ( + frappe.qb.update(gl_entry) + .join(asset) + .on(gl_entry.against_voucher == asset.name) + .set(gl_entry.asset, Coalesce(asset.name, "")) + .where((gl_entry.voucher_type == "Journal Entry") & (gl_entry.against_voucher_type == "Asset")) + ) + query.run() + + +def process_asset_capitalization_entries(): + # nosemgrep + frappe.db.sql( + """ + UPDATE `tabGL Entry` AS gl + INNER JOIN `tabAsset Capitalization Asset Item` AS acai + ON gl.voucher_no = acai.parent + AND gl.account = acai.fixed_asset_account + INNER JOIN `tabAsset` AS asset + ON acai.asset = asset.name + AND gl.credit = asset.gross_purchase_amount + SET gl.asset = acai.asset + WHERE gl.voucher_type = 'Asset Capitalization' + AND gl.credit > 0 + """ + )