Code cleanup and fixes for the asset

This commit is contained in:
Rohit Waghchaure 2018-06-11 18:53:55 +05:30
parent e832aa4fe2
commit 647d595158
9 changed files with 49 additions and 40 deletions

View File

@ -16,11 +16,11 @@ from erpnext.accounts.general_ledger import make_gl_entries, merge_similar_entri
from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
from erpnext.buying.utils import check_for_closed_status from erpnext.buying.utils import check_for_closed_status
from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center
from erpnext.assets.doctype.asset.asset import get_asset_account
from frappe.model.mapper import get_mapped_doc from frappe.model.mapper import get_mapped_doc
from six import iteritems from six import iteritems
from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_company_party, update_linked_invoice,\ from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_company_party, update_linked_invoice,\
unlink_inter_company_invoice unlink_inter_company_invoice
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "items": "templates/form_grid/item_grid.html"
@ -474,17 +474,16 @@ class PurchaseInvoice(BuyingController):
def get_asset_gl_entry(self, gl_entries): def get_asset_gl_entry(self, gl_entries):
for item in self.get("items"): for item in self.get("items"):
if item.is_fixed_asset: if item.is_fixed_asset:
asset_accounts = self.get_company_default(["asset_received_but_not_billed", eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
"expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate) asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(item.base_net_amount + item.item_tax_amount) base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
item.expense_account = item.expense_account or asset_accounts[0] item.expense_account = item.expense_account
if (not item.expense_account or frappe.db.get_value('Account', if (not item.expense_account or frappe.db.get_value('Account',
item.expense_account, 'account_type') != 'Asset Received But Not Billed'): item.expense_account, 'account_type') != 'Asset Received But Not Billed'):
frappe.throw(_("Row {0}: Expense account must be of type Asset Received But Not Billed"). arbnb_account = self.get_company_default("asset_received_but_not_billed")
format(item.idx)) item.expense_account = arbnb_account
if not self.update_stock: if not self.update_stock:
asset_rbnb_currency = get_account_currency(item.expense_account) asset_rbnb_currency = get_account_currency(item.expense_account)
@ -498,9 +497,9 @@ class PurchaseInvoice(BuyingController):
})) }))
if item.item_tax_amount: if item.item_tax_amount:
asset_eiiav_currency = get_account_currency(asset_accounts[0]) asset_eiiav_currency = get_account_currency(eiiav_account)
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1], "account": eiiav_account,
"against": self.supplier, "against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"), "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"cost_center": item.cost_center, "cost_center": item.cost_center,
@ -510,8 +509,8 @@ class PurchaseInvoice(BuyingController):
item.item_tax_amount / self.conversion_rate) item.item_tax_amount / self.conversion_rate)
})) }))
else: else:
cwip_account = get_asset_category_account(item.asset, cwip_account = get_asset_account("capital_work_in_progress_account",
'capital_work_in_progress_account') or asset_accounts[2] item.asset, company = self.company)
cwip_account_currency = get_account_currency(cwip_account) cwip_account_currency = get_account_currency(cwip_account)
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
@ -524,9 +523,9 @@ class PurchaseInvoice(BuyingController):
})) }))
if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)): if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
asset_eiiav_currency = get_account_currency(asset_accounts[1]) asset_eiiav_currency = get_account_currency(eiiav_account)
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1], "account": eiiav_account,
"against": self.supplier, "against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"), "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"cost_center": item.cost_center, "cost_center": item.cost_center,

View File

@ -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_category.asset_category import get_asset_category_account
from erpnext.assets.doctype.asset.depreciation \ from erpnext.assets.doctype.asset.depreciation \
import get_disposal_account_and_cost_center, get_depreciation_accounts 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.accounts.utils import get_account_currency
from erpnext.controllers.accounts_controller import AccountsController from erpnext.controllers.accounts_controller import AccountsController
@ -33,11 +33,15 @@ class Asset(AccountsController):
self.validate_in_use_date() self.validate_in_use_date()
self.set_status() self.set_status()
self.update_stock_movement() self.update_stock_movement()
if not self.booked_fixed_asset:
self.make_gl_entries()
def on_cancel(self): def on_cancel(self):
self.validate_cancellation() self.validate_cancellation()
self.delete_depreciation_entries() self.delete_depreciation_entries()
self.set_status() self.set_status()
delete_gl_entries()
self.db_set('booked_fixed_asset', 0)
def validate_item(self): def validate_item(self):
item = frappe.db.get_value("Item", self.item_code, item = frappe.db.get_value("Item", self.item_code,
@ -325,12 +329,14 @@ class Asset(AccountsController):
doc.submit() doc.submit()
def make_gl_entries(self): 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 from erpnext.accounts.general_ledger import make_gl_entries
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', fixed_aseet_account = get_asset_category_account(self.name, 'fixed_asset_account',
asset_category = self.asset_category, company = self.company) asset_category = self.asset_category, company = self.company)
@ -471,15 +477,17 @@ def get_item_details(item_code, asset_category=None):
return books return books
def get_cwip_account(asset, asset_category=None, company=None): def get_asset_account(account_name, asset=None, asset_category=None, company=None):
cwip_account = get_asset_category_account(asset, 'capital_work_in_progress_account', account = None
asset_category = asset_category, company = company) if asset:
account = get_asset_category_account(asset, account_name,
asset_category = asset_category, company = company)
if not cwip_account: if not account:
cwip_account = frappe.db.get_value('Company', company, 'capital_work_in_progress_account') account = frappe.db.get_value('Company', company, account_name)
if not cwip_account: if not account:
frappe.throw(_("Set Capital Work In Progress Account in asset category {0} or company {1}") frappe.throw(_("Set {0} in asset category {1} or company {2}")
.format(asset_category, company)) .format(account_name.replace('_', ' ').title(), asset_category, company))
return cwip_account return account

View File

@ -3,6 +3,6 @@
frappe.ui.form.on('Asset Movement', { frappe.ui.form.on('Asset Movement', {
onload: function(frm) { onload: function(frm) {
//
} }
}); });

View File

@ -277,7 +277,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_from": "asset.location", "fetch_from": "",
"fieldname": "source_location", "fieldname": "source_location",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -575,7 +575,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-06-06 06:21:36.607432", "modified": "2018-06-11 18:42:55.381972",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Movement", "name": "Asset Movement",

View File

@ -31,7 +31,7 @@ class AssetMovement(Document):
if self.purpose in ['Transfer', 'Issue']: if self.purpose in ['Transfer', 'Issue']:
self.source_location = frappe.db.get_value("Asset", self.asset, "location") 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")) frappe.throw(_("Source and Target Location cannot be same"))
def on_submit(self): def on_submit(self):

View File

@ -558,7 +558,8 @@ class BuyingController(StockController):
'actual_qty': d.qty, 'actual_qty': d.qty,
'purchase_document_type': self.doctype, 'purchase_document_type': self.doctype,
'purchase_document_no': self.name, 'purchase_document_no': self.name,
'asset': d.asset 'asset': d.asset,
'location': d.asset_location
}) })
d.db_set('serial_no', serial_nos) d.db_set('serial_no', serial_nos)

View File

@ -1223,7 +1223,7 @@
"collapsible": 1, "collapsible": 1,
"collapsible_depends_on": "eval:doc.has_batch_no || doc.has_serial_no || doc.is_fixed_asset", "collapsible_depends_on": "eval:doc.has_batch_no || doc.has_serial_no || doc.is_fixed_asset",
"columns": 0, "columns": 0,
"depends_on": "is_stock_item", "depends_on": "eval:doc.is_stock_item || doc.is_fixed_asset",
"fieldname": "serial_nos_and_batches", "fieldname": "serial_nos_and_batches",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -3918,7 +3918,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 1, "max_attachments": 1,
"modified": "2018-05-28 14:18:03.234070", "modified": "2018-06-11 17:11:55.458770",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Item", "name": "Item",

View File

@ -13,8 +13,8 @@ from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.utils import get_account_currency from erpnext.accounts.utils import get_account_currency
from frappe.desk.notifications import clear_doctype_notifications from frappe.desk.notifications import clear_doctype_notifications
from erpnext.buying.utils import check_for_closed_status from erpnext.buying.utils import check_for_closed_status
from erpnext.assets.doctype.asset.asset import get_asset_account
from six import iteritems from six import iteritems
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "items": "templates/form_grid/item_grid.html"
@ -314,12 +314,11 @@ class PurchaseReceipt(BuyingController):
def get_asset_gl_entry(self, gl_entries): def get_asset_gl_entry(self, gl_entries):
for d in self.get("items"): for d in self.get("items"):
if d.is_fixed_asset: if d.is_fixed_asset:
asset_accounts = self.get_company_default(["capital_work_in_progress_account", arbnb_account = self.get_company_default("asset_received_but_not_billed")
"asset_received_but_not_billed"])
# CWIP entry # CWIP entry
cwip_account = get_asset_category_account(d.asset, cwip_account = get_asset_account("capital_work_in_progress_account", d.asset,
'capital_work_in_progress_account') or asset_accounts[0] company = self.company)
asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate) asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(d.base_net_amount + d.item_tax_amount) base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
@ -327,7 +326,7 @@ class PurchaseReceipt(BuyingController):
cwip_account_currency = get_account_currency(cwip_account) cwip_account_currency = get_account_currency(cwip_account)
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": cwip_account, "account": cwip_account,
"against": asset_accounts[1], "against": arbnb_account,
"cost_center": d.cost_center, "cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"), "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount, "debit": base_asset_amount,
@ -336,10 +335,10 @@ class PurchaseReceipt(BuyingController):
})) }))
# Asset received but not billed # Asset received but not billed
asset_rbnb_currency = get_account_currency(asset_accounts[1]) asset_rbnb_currency = get_account_currency(arbnb_account)
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1], "account": arbnb_account,
"against": asset_accounts[0], "against": cwip_account,
"cost_center": d.cost_center, "cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"), "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"credit": base_asset_amount, "credit": base_asset_amount,

View File

@ -306,6 +306,7 @@ def auto_make_serial_nos(args):
sr.via_stock_ledger = True sr.via_stock_ledger = True
sr.item_code = args.get('item_code') sr.item_code = args.get('item_code')
sr.warehouse = args.get('warehouse') if args.get('actual_qty', 0) > 0 else None sr.warehouse = args.get('warehouse') if args.get('actual_qty', 0) > 0 else None
sr.location = args.get('location')
sr.save(ignore_permissions=True) sr.save(ignore_permissions=True)
elif args.get('actual_qty', 0) > 0: elif args.get('actual_qty', 0) > 0:
make_serial_no(serial_no, args) make_serial_no(serial_no, args)
@ -330,6 +331,7 @@ def make_serial_no(serial_no, args):
sr.company = args.get('company') sr.company = args.get('company')
sr.via_stock_ledger = args.get('via_stock_ledger') or True sr.via_stock_ledger = args.get('via_stock_ledger') or True
sr.asset = args.get('asset') sr.asset = args.get('asset')
sr.location = args.get('location')
if args.get('purchase_document_type'): if args.get('purchase_document_type'):
sr.purchase_document_type = args.get('purchase_document_type') sr.purchase_document_type = args.get('purchase_document_type')