From e6acd4c57aef5e964bb03403a35e098b0f76cda7 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 16 May 2018 22:12:39 +0530 Subject: [PATCH] Multiple fixes in asset --- erpnext/assets/doctype/asset/asset.js | 7 +++++++ erpnext/assets/doctype/asset/asset.py | 5 ++++- erpnext/assets/doctype/asset_movement/asset_movement.py | 6 ++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index c05667a767..88e7f78a02 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -157,6 +157,13 @@ frappe.ui.form.on('Asset', { } }, + available_for_use_date: function(frm) { + $.each(frm.doc.finance_books || [], function(i, d) { + if(!d.depreciation_start_date) d.depreciation_start_date = frm.doc.available_for_use_date; + }); + refresh_field("finance_books"); + }, + is_existing_asset: function(frm) { // frm.toggle_reqd("next_depreciation_date", (!frm.doc.is_existing_asset && frm.doc.calculate_depreciation)); }, diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index e37038a5a8..75e808870f 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -51,7 +51,7 @@ class Asset(AccountsController): def validate_in_use_date(self): if not self.available_for_use_date: - frappe.throw(_("Available for use data is required")) + frappe.throw(_("Available for use date is required")) def set_missing_values(self): if not self.asset_category: @@ -162,6 +162,9 @@ class Asset(AccountsController): frappe.throw(_("Row {0}: Expected Value After Useful Life must be less than Gross Purchase Amount") .format(row.idx)) + if not row.depreciation_start_date: + frappe.throw(_("Row {0}: Depreciation Start Date is required").format(row.idx)) + if not self.is_existing_asset: self.opening_accumulated_depreciation = 0 self.number_of_depreciations_booked = 0 diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.py b/erpnext/assets/doctype/asset_movement/asset_movement.py index e34d2a3066..638987ee96 100644 --- a/erpnext/assets/doctype/asset_movement/asset_movement.py +++ b/erpnext/assets/doctype/asset_movement/asset_movement.py @@ -55,7 +55,5 @@ class AssetMovement(Document): frappe.db.set_value("Asset", self.asset, "location", location) if self.serial_no: - serial_nos = get_serial_nos(self.serial_no) - - frappe.db.sql(""" update `tabSerial No` set location = %s where name in (%s)""" - %('%s', ','.join(['%s'] * len(serial_nos))), (location, tuple(serial_nos))) + for d in get_serial_nos(self.serial_no): + frappe.db.set_value('Serial No', d, 'location', location)