chore: allow manually submitting and cancelling asset depr schedule
This commit is contained in:
parent
21a09e7431
commit
7c5168eeac
@ -289,7 +289,7 @@ class JournalEntry(AccountsController):
|
||||
for row in asset.get("finance_books"):
|
||||
depr_schedule = get_draft_or_active_depr_schedule(asset.name, row.finance_book)
|
||||
|
||||
for s in depr_schedule:
|
||||
for s in depr_schedule or []:
|
||||
if s.journal_entry == self.name:
|
||||
s.db_set("journal_entry", None)
|
||||
|
||||
|
@ -395,7 +395,7 @@ class Asset(AccountsController):
|
||||
for row in self.get("finance_books"):
|
||||
depr_schedule = get_draft_or_active_depr_schedule(self.name, row.finance_book)
|
||||
|
||||
for d in depr_schedule:
|
||||
for d in depr_schedule or []:
|
||||
if d.journal_entry:
|
||||
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
||||
d.db_set("journal_entry", None)
|
||||
@ -903,6 +903,7 @@ def update_existing_asset(asset, remaining_qty, new_asset_name):
|
||||
)
|
||||
new_asset_depr_schedule_doc.notes = notes
|
||||
|
||||
current_asset_depr_schedule_doc.flags.should_not_cancel_depreciation_entries = True
|
||||
current_asset_depr_schedule_doc.cancel()
|
||||
|
||||
new_asset_depr_schedule_doc.submit()
|
||||
|
@ -65,8 +65,7 @@
|
||||
"fieldname": "finance_book",
|
||||
"fieldtype": "Link",
|
||||
"label": "Finance Book",
|
||||
"options": "Finance Book",
|
||||
"read_only": 1
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname": "depreciation_method",
|
||||
@ -115,7 +114,8 @@
|
||||
{
|
||||
"fieldname": "notes",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Notes"
|
||||
"label": "Notes",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
@ -133,7 +133,6 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "expected_value_after_useful_life",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Expected Value After Useful Life",
|
||||
@ -157,11 +156,10 @@
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-12-26 20:32:43.342271",
|
||||
"modified": "2023-01-02 15:38:30.766779",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Depreciation Schedule",
|
||||
|
@ -18,6 +18,12 @@ import erpnext
|
||||
|
||||
|
||||
class AssetDepreciationSchedule(Document):
|
||||
def before_save(self):
|
||||
if not self.finance_book_id:
|
||||
self.prepare_draft_asset_depr_schedule_data_from_asset_name_and_fb_name(
|
||||
self.asset, self.finance_book
|
||||
)
|
||||
|
||||
def validate(self):
|
||||
self.validate_another_asset_depr_schedule_does_not_exist()
|
||||
|
||||
@ -45,9 +51,33 @@ class AssetDepreciationSchedule(Document):
|
||||
def on_submit(self):
|
||||
self.db_set("status", "Active")
|
||||
|
||||
def before_cancel(self):
|
||||
if not self.flags.should_not_cancel_depreciation_entries:
|
||||
self.cancel_depreciation_entries()
|
||||
|
||||
def cancel_depreciation_entries(self):
|
||||
for d in self.get("depreciation_schedule"):
|
||||
if d.journal_entry:
|
||||
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
||||
|
||||
def on_cancel(self):
|
||||
self.db_set("status", "Cancelled")
|
||||
|
||||
def prepare_draft_asset_depr_schedule_data_from_asset_name_and_fb_name(self, asset_name, fb_name):
|
||||
asset_doc = frappe.get_doc("Asset", asset_name)
|
||||
|
||||
finance_book_filter = ["finance_book", "is", "not set"]
|
||||
if fb_name:
|
||||
finance_book_filter = ["finance_book", "=", fb_name]
|
||||
|
||||
asset_finance_book_name = frappe.db.get_value(
|
||||
doctype="Asset Finance Book",
|
||||
filters=[["parent", "=", asset_name], finance_book_filter],
|
||||
)
|
||||
asset_finance_book_doc = frappe.get_doc("Asset Finance Book", asset_finance_book_name)
|
||||
|
||||
prepare_draft_asset_depr_schedule_data(self, asset_doc, asset_finance_book_doc)
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedules_if_not_present(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
@ -138,7 +168,8 @@ def cancel_asset_depr_schedules(asset_doc):
|
||||
if not asset_depr_schedule_doc:
|
||||
continue
|
||||
|
||||
asset_depr_schedule_doc.cancel()
|
||||
if asset_depr_schedule_doc.status == "Active":
|
||||
asset_depr_schedule_doc.cancel()
|
||||
|
||||
|
||||
def make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
@ -163,6 +194,7 @@ def make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
|
||||
new_asset_depr_schedule_doc.notes = notes
|
||||
|
||||
current_asset_depr_schedule_doc.flags.should_not_cancel_depreciation_entries = True
|
||||
current_asset_depr_schedule_doc.cancel()
|
||||
|
||||
new_asset_depr_schedule_doc.submit()
|
||||
|
@ -124,6 +124,7 @@ class AssetValueAdjustment(Document):
|
||||
new_asset_depr_schedule_doc.status = "Draft"
|
||||
new_asset_depr_schedule_doc.docstatus = 0
|
||||
|
||||
current_asset_depr_schedule_doc.flags.should_not_cancel_depreciation_entries = True
|
||||
current_asset_depr_schedule_doc.cancel()
|
||||
|
||||
notes = _(
|
||||
|
Loading…
Reference in New Issue
Block a user