mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-27 10:38:30 +00:00
fix(asset value adjustment): skip cancelling revaluation journal entry if already cancelled (backport #51666) (#51716)
Co-authored-by: Navin-S-R <navin@aerele.in>
This commit is contained in:
@@ -184,6 +184,9 @@ class JournalEntry(AccountsController):
|
|||||||
else:
|
else:
|
||||||
return self._submit()
|
return self._submit()
|
||||||
|
|
||||||
|
def before_cancel(self):
|
||||||
|
self.has_asset_adjustment_entry()
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
if len(self.accounts) > 100:
|
if len(self.accounts) > 100:
|
||||||
queue_submission(self, "_cancel")
|
queue_submission(self, "_cancel")
|
||||||
@@ -554,12 +557,27 @@ class JournalEntry(AccountsController):
|
|||||||
)
|
)
|
||||||
frappe.db.set_value("Journal Entry", self.name, "inter_company_journal_entry_reference", "")
|
frappe.db.set_value("Journal Entry", self.name, "inter_company_journal_entry_reference", "")
|
||||||
|
|
||||||
def unlink_asset_adjustment_entry(self):
|
def has_asset_adjustment_entry(self):
|
||||||
frappe.db.sql(
|
if self.flags.get("via_asset_value_adjustment"):
|
||||||
""" update `tabAsset Value Adjustment`
|
return
|
||||||
set journal_entry = null where journal_entry = %s""",
|
|
||||||
self.name,
|
asset_value_adjustment = frappe.db.get_value(
|
||||||
|
"Asset Value Adjustment", {"docstatus": 1, "journal_entry": self.name}, "name"
|
||||||
)
|
)
|
||||||
|
if asset_value_adjustment:
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Cannot cancel this document as it is linked with the submitted Asset Value Adjustment <b>{0}</b>. Please cancel the Asset Value Adjustment to continue."
|
||||||
|
).format(frappe.utils.get_link_to_form("Asset Value Adjustment", asset_value_adjustment))
|
||||||
|
)
|
||||||
|
|
||||||
|
def unlink_asset_adjustment_entry(self):
|
||||||
|
AssetValueAdjustment = frappe.qb.DocType("Asset Value Adjustment")
|
||||||
|
(
|
||||||
|
frappe.qb.update(AssetValueAdjustment)
|
||||||
|
.set(AssetValueAdjustment.journal_entry, None)
|
||||||
|
.where(AssetValueAdjustment.journal_entry == self.name)
|
||||||
|
).run()
|
||||||
|
|
||||||
def validate_party(self):
|
def validate_party(self):
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class AssetValueAdjustment(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
frappe.get_doc("Journal Entry", self.journal_entry).cancel()
|
self.cancel_asset_revaluation_entry()
|
||||||
self.update_asset()
|
self.update_asset()
|
||||||
add_asset_activity(
|
add_asset_activity(
|
||||||
self.asset,
|
self.asset,
|
||||||
@@ -167,6 +167,17 @@ class AssetValueAdjustment(Document):
|
|||||||
if dimension.get("mandatory_for_pl"):
|
if dimension.get("mandatory_for_pl"):
|
||||||
debit_entry.update({dimension["fieldname"]: dimension_value})
|
debit_entry.update({dimension["fieldname"]: dimension_value})
|
||||||
|
|
||||||
|
def cancel_asset_revaluation_entry(self):
|
||||||
|
if not self.journal_entry:
|
||||||
|
return
|
||||||
|
|
||||||
|
revaluation_entry = frappe.get_doc("Journal Entry", self.journal_entry)
|
||||||
|
if revaluation_entry.docstatus == 1:
|
||||||
|
# Ignore permissions to match Journal Entry submission behavior
|
||||||
|
revaluation_entry.flags.ignore_permissions = True
|
||||||
|
revaluation_entry.flags.via_asset_value_adjustment = True
|
||||||
|
revaluation_entry.cancel()
|
||||||
|
|
||||||
def update_asset(self):
|
def update_asset(self):
|
||||||
asset = self.update_asset_value_after_depreciation()
|
asset = self.update_asset_value_after_depreciation()
|
||||||
note = self.get_adjustment_note()
|
note = self.get_adjustment_note()
|
||||||
|
|||||||
Reference in New Issue
Block a user