mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-28 22:28:24 +00:00
Code cleanup and fixes for the asset
This commit is contained in:
@@ -10,7 +10,7 @@ from frappe.model.document import Document
|
||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||
from erpnext.assets.doctype.asset.depreciation \
|
||||
import get_disposal_account_and_cost_center, get_depreciation_accounts
|
||||
from erpnext.accounts.general_ledger import make_gl_entries
|
||||
from erpnext.accounts.general_ledger import make_gl_entries, delete_gl_entries
|
||||
from erpnext.accounts.utils import get_account_currency
|
||||
from erpnext.controllers.accounts_controller import AccountsController
|
||||
|
||||
@@ -33,11 +33,15 @@ class Asset(AccountsController):
|
||||
self.validate_in_use_date()
|
||||
self.set_status()
|
||||
self.update_stock_movement()
|
||||
if not self.booked_fixed_asset:
|
||||
self.make_gl_entries()
|
||||
|
||||
def on_cancel(self):
|
||||
self.validate_cancellation()
|
||||
self.delete_depreciation_entries()
|
||||
self.set_status()
|
||||
delete_gl_entries()
|
||||
self.db_set('booked_fixed_asset', 0)
|
||||
|
||||
def validate_item(self):
|
||||
item = frappe.db.get_value("Item", self.item_code,
|
||||
@@ -325,12 +329,14 @@ class Asset(AccountsController):
|
||||
doc.submit()
|
||||
|
||||
def make_gl_entries(self):
|
||||
if self.purchase_receipt and self.purchase_receipt_amount:
|
||||
if self.purchase_receipt and self.purchase_receipt_amount and self.available_for_use_date <= nowdate():
|
||||
from erpnext.accounts.general_ledger import make_gl_entries
|
||||
|
||||
gl_entries = []
|
||||
|
||||
cwip_account = get_cwip_account(self.name, self.asset_category, self.company)
|
||||
cwip_account = get_asset_account("capital_work_in_progress_account",
|
||||
self.name, self.asset_category, self.company)
|
||||
|
||||
fixed_aseet_account = get_asset_category_account(self.name, 'fixed_asset_account',
|
||||
asset_category = self.asset_category, company = self.company)
|
||||
|
||||
@@ -471,15 +477,17 @@ def get_item_details(item_code, asset_category=None):
|
||||
|
||||
return books
|
||||
|
||||
def get_cwip_account(asset, asset_category=None, company=None):
|
||||
cwip_account = get_asset_category_account(asset, 'capital_work_in_progress_account',
|
||||
asset_category = asset_category, company = company)
|
||||
def get_asset_account(account_name, asset=None, asset_category=None, company=None):
|
||||
account = None
|
||||
if asset:
|
||||
account = get_asset_category_account(asset, account_name,
|
||||
asset_category = asset_category, company = company)
|
||||
|
||||
if not cwip_account:
|
||||
cwip_account = frappe.db.get_value('Company', company, 'capital_work_in_progress_account')
|
||||
if not account:
|
||||
account = frappe.db.get_value('Company', company, account_name)
|
||||
|
||||
if not cwip_account:
|
||||
frappe.throw(_("Set Capital Work In Progress Account in asset category {0} or company {1}")
|
||||
.format(asset_category, company))
|
||||
if not account:
|
||||
frappe.throw(_("Set {0} in asset category {1} or company {2}")
|
||||
.format(account_name.replace('_', ' ').title(), asset_category, company))
|
||||
|
||||
return cwip_account
|
||||
return account
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
frappe.ui.form.on('Asset Movement', {
|
||||
onload: function(frm) {
|
||||
|
||||
//
|
||||
}
|
||||
});
|
||||
|
||||
@@ -277,7 +277,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fetch_from": "asset.location",
|
||||
"fetch_from": "",
|
||||
"fieldname": "source_location",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
@@ -575,7 +575,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2018-06-06 06:21:36.607432",
|
||||
"modified": "2018-06-11 18:42:55.381972",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Movement",
|
||||
|
||||
@@ -31,7 +31,7 @@ class AssetMovement(Document):
|
||||
if self.purpose in ['Transfer', 'Issue']:
|
||||
self.source_location = frappe.db.get_value("Asset", self.asset, "location")
|
||||
|
||||
if self.source_location == self.target_location:
|
||||
if self.source_location == self.target_location and self.purpose == 'Transfer':
|
||||
frappe.throw(_("Source and Target Location cannot be same"))
|
||||
|
||||
def on_submit(self):
|
||||
|
||||
Reference in New Issue
Block a user