Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add asset field to GL Entry to link associated asset #44422

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
7 changes: 7 additions & 0 deletions erpnext/accounts/doctype/gl_entry/gl_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dimensions_section",
"cost_center",
"column_break_lmnm",
"asset",
"project",
"more_info_section",
"finance_book",
Expand Down Expand Up @@ -298,6 +299,12 @@
"fieldtype": "Small Text",
"label": "Voucher Subtype"
},
{
"fieldname": "asset",
"fieldtype": "Link",
"label": "Asset",
"options": "Asset"
},
{
"fieldname": "dates_section",
"fieldtype": "Section Break",
Expand Down
1 change: 1 addition & 0 deletions erpnext/accounts/doctype/gl_entry/gl_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
3 changes: 3 additions & 0 deletions erpnext/assets/doctype/asset/depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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:
Expand Down Expand Up @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
2 changes: 2 additions & 0 deletions erpnext/assets/doctype/asset_repair/asset_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
}

Expand Down
3 changes: 2 additions & 1 deletion erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts
71 changes: 71 additions & 0 deletions erpnext/patches/v15_0/link_asset_to_gl_entry.py
Original file line number Diff line number Diff line change
@@ -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
"""
)
Loading