Merge pull request #14109 from rohitwaghchaure/asset_adjustment_fixes

[Fix] Asset adjustment issues
This commit is contained in:
rohitwaghchaure 2018-05-17 11:23:26 +05:30 committed by GitHub
commit 509847a674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 15 deletions

View File

@ -82,7 +82,7 @@ frappe.ui.form.on('Asset', {
}
if (frm.doc.status != 'Fully Depreciated') {
frm.add_custom_button(__("Asset Adjustment"), function() {
frm.trigger("create_asset_maintenance");
frm.trigger("create_asset_adjustment");
}, __("Make"));
}
@ -233,6 +233,22 @@ frappe.ui.form.on('Asset', {
})
},
create_asset_adjustment: function(frm) {
frappe.call({
args: {
"asset": frm.doc.name,
"asset_category": frm.doc.asset_category,
"company": frm.doc.company
},
method: "erpnext.assets.doctype.asset.asset.create_asset_adjustment",
freeze: 1,
callback: function(r) {
var doclist = frappe.model.sync(r.message);
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
}
})
},
calculate_depreciation: function(frm) {
frappe.db.get_value("Asset Settings", {'name':"Asset Settings"}, 'schedule_based_on_fiscal_year', (data) => {
if (data.schedule_based_on_fiscal_year == 1) {
@ -328,6 +344,42 @@ erpnext.asset.transfer_asset = function(frm) {
},
"reqd": 1
},
{
"label": __("Select Serial No"),
"fieldname": "serial_nos",
"fieldtype": "Link",
"options": "Serial No",
"get_query": function () {
return {
filters: {
'asset': frm.doc.name
}
}
},
"onchange": function() {
let val = this.get_value();
if (val) {
let serial_nos = dialog.get_value("serial_no") || val;
if (serial_nos) {
serial_nos = serial_nos.split('\n');
serial_nos.push(val);
const unique_sn = serial_nos.filter(function(elem, index, self) {
return index === self.indexOf(elem);
});
dialog.set_value("serial_no", unique_sn.join('\n'));
dialog.set_value("serial_nos", "");
}
}
}
},
{
"label": __("Serial No"),
"fieldname": "serial_no",
"read_only": 1,
"fieldtype": "Small Text"
},
{
"label": __("Date"),
"fieldname": "transfer_date",
@ -349,8 +401,9 @@ erpnext.asset.transfer_asset = function(frm) {
args: {
"asset": frm.doc.name,
"transaction_date": args.transfer_date,
"source_warehouse": frm.doc.location,
"target_warehouse": args.target_location,
"source_location": frm.doc.location,
"target_location": args.target_location,
"serial_no": args.serial_no,
"company": frm.doc.company
}
},

View File

@ -421,10 +421,24 @@ def create_asset_maintenance(asset, item_code, item_name, asset_category, compan
})
return asset_maintenance
@frappe.whitelist()
def create_asset_adjustment(asset, asset_category, company):
asset_maintenance = frappe.new_doc("Asset Adjustment")
asset_maintenance.update({
"asset": asset,
"company": company,
"asset_category": asset_category
})
return asset_maintenance
@frappe.whitelist()
def transfer_asset(args):
import json
args = json.loads(args)
if args.get('serial_no'):
args['quantity'] = len(args.get('serial_no').split('\n'))
movement_entry = frappe.new_doc("Asset Movement")
movement_entry.update(args)
movement_entry.insert()

View File

@ -2,6 +2,18 @@
// For license information, please see license.txt
frappe.ui.form.on('Asset Adjustment', {
setup: function(frm) {
frm.add_fetch('company', 'cost_center', 'cost_center');
frm.set_query('cost_center', function() {
return {
filters: {
company: frm.doc.company,
is_group: 0
}
}
});
},
asset: function(frm) {
frm.trigger("set_current_asset_value");
},
@ -11,7 +23,6 @@ frappe.ui.form.on('Asset Adjustment', {
},
set_current_asset_value: function(frm) {
debugger
if (frm.doc.finance_book && frm.doc.asset) {
frm.call({
method: "erpnext.assets.doctype.asset_adjustment.asset_adjustment.get_current_asset_value",

View File

@ -41,6 +41,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -72,6 +73,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -103,6 +105,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -134,6 +137,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -165,6 +169,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -194,6 +199,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -203,7 +209,7 @@
"collapsible": 0,
"columns": 0,
"fieldname": "date",
"fieldtype": "Datetime",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -224,6 +230,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -254,6 +261,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -284,6 +292,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -314,6 +323,39 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "cost_center",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Cost Center",
"length": 0,
"no_copy": 0,
"options": "Cost Center",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -344,6 +386,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}
],
@ -357,7 +400,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-05-11 21:45:03.459696",
"modified": "2018-05-17 11:12:38.110774",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Adjustment",
@ -366,7 +409,6 @@
"permissions": [
{
"amend": 1,
"apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
@ -386,7 +428,6 @@
},
{
"amend": 1,
"apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
@ -406,7 +447,6 @@
},
{
"amend": 1,
"apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,

View File

@ -16,12 +16,14 @@ class AssetAdjustment(Document):
def on_submit(self):
self.make_depreciation_entry()
self.reschedule_depreciations()
self.reschedule_depreciations(self.new_asset_value)
def on_cancel(self):
if self.journal_entry:
frappe.throw(_("Cancel the journal entry {0} first").format(self.journal_entry))
self.reschedule_depreciations(self.current_asset_value)
def set_difference_amount(self):
self.difference_amount = flt(self.current_asset_value - self.new_asset_value)
@ -47,12 +49,13 @@ class AssetAdjustment(Document):
je.append("accounts", {
"account": accumulated_depreciation_account,
"credit_in_account_currency": self.difference_amount,
"cost_center": depreciation_cost_center or self.cost_center
})
je.append("accounts", {
"account": depreciation_expense_account,
"debit_in_account_currency": self.difference_amount,
"cost_center": depreciation_cost_center
"cost_center": depreciation_cost_center or self.cost_center
})
je.flags.ignore_permissions = True
@ -60,11 +63,11 @@ class AssetAdjustment(Document):
self.db_set("journal_entry", je.name)
def reschedule_depreciations(self):
def reschedule_depreciations(self, asset_value):
asset = frappe.get_doc('Asset', self.asset)
for d in asset.finance_books:
d.value_after_depreciation = self.new_asset_value
d.value_after_depreciation = asset_value
if d.depreciation_method in ("Straight Line", "Manual"):
end_date = max([s.schedule_date for s in asset.schedules if cint(s.finance_book_id) == d.idx])

View File

@ -635,8 +635,8 @@ class AccountsController(TransactionBase):
frappe.throw(_("Row #{0}: Asset {1} does not linked to Item {2}")
.format(d.idx, d.asset, d.item_code))
elif asset.docstatus != 1:
frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
# elif asset.docstatus != 1:
# frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
elif self.doctype == "Purchase Invoice":
# if asset.status != "Submitted":