chore: fix validation and add make_schedules_editable

This commit is contained in:
anandbaburajan 2022-12-12 18:19:34 +05:30
parent 1ea2ba0dea
commit 28d4942d6c
2 changed files with 34 additions and 6 deletions

View File

@ -2,6 +2,20 @@
// For license information, please see license.txt
frappe.provide("erpnext.asset");
frappe.ui.form.on('Asset Depreciation Schedule', {
onload: function(frm) {
frm.events.make_schedules_editable(frm);
},
make_schedules_editable: function(frm) {
var is_editable = frm.doc.depreciation_method == "Manual" ? true : false;
frm.toggle_enable("depreciation_schedule", is_editable);
frm.fields_dict["depreciation_schedule"].grid.toggle_enable("schedule_date", is_editable);
frm.fields_dict["depreciation_schedule"].grid.toggle_enable("depreciation_amount", is_editable);
}
});
frappe.ui.form.on('Depreciation Schedule', {
make_depreciation_entry: function(frm, cdt, cdn) {
var row = locals[cdt][cdn];

View File

@ -22,14 +22,28 @@ class AssetDepreciationSchedule(Document):
self.validate_another_asset_depr_schedule_does_not_exist()
def validate_another_asset_depr_schedule_does_not_exist(self):
asset_depr_schedule_name = get_asset_depr_schedule_name(self.asset, self.finance_book)
finance_book_filter = ["finance_book", "is", "not set"]
if self.finance_book:
finance_book_filter = ["finance_book", "=", self.finance_book]
if asset_depr_schedule_name:
frappe.throw(
_("Asset Depreciation Schedule for Asset {0} and Finance Book {1} already exists.").format(
self.asset, self.finance_book
num_asset_depr_schedules = frappe.db.count(
"Asset Depreciation Schedule",
[
["asset", "=", self.asset],
finance_book_filter,
["docstatus", "<", 2],
],
)
if num_asset_depr_schedules == 1:
asset_depr_schedule_name = get_asset_depr_schedule_name(self.asset, self.finance_book)
if self.name != asset_depr_schedule_name:
frappe.throw(
_("Asset Depreciation Schedule for Asset {0} and Finance Book {1} already exists.").format(
self.asset, self.finance_book
)
)
)
def make_draft_asset_depr_schedules(asset_doc, date_of_disposal=None, date_of_return=None):