Merge pull request #14467 from rohitwaghchaure/update_location_in_serial_no
Code cleanup and fixes for the asset
This commit is contained in:
commit
2354c1eba3
@ -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.buying.utils import check_for_closed_status
|
||||
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 six import iteritems
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_company_party, update_linked_invoice,\
|
||||
unlink_inter_company_invoice
|
||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||
|
||||
form_grid_templates = {
|
||||
"items": "templates/form_grid/item_grid.html"
|
||||
@ -474,17 +474,16 @@ class PurchaseInvoice(BuyingController):
|
||||
def get_asset_gl_entry(self, gl_entries):
|
||||
for item in self.get("items"):
|
||||
if item.is_fixed_asset:
|
||||
asset_accounts = self.get_company_default(["asset_received_but_not_billed",
|
||||
"expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
|
||||
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
|
||||
|
||||
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)
|
||||
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',
|
||||
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").
|
||||
format(item.idx))
|
||||
arbnb_account = self.get_company_default("asset_received_but_not_billed")
|
||||
item.expense_account = arbnb_account
|
||||
|
||||
if not self.update_stock:
|
||||
asset_rbnb_currency = get_account_currency(item.expense_account)
|
||||
@ -498,9 +497,9 @@ class PurchaseInvoice(BuyingController):
|
||||
}))
|
||||
|
||||
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({
|
||||
"account": asset_accounts[1],
|
||||
"account": eiiav_account,
|
||||
"against": self.supplier,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
|
||||
"cost_center": item.cost_center,
|
||||
@ -510,8 +509,8 @@ class PurchaseInvoice(BuyingController):
|
||||
item.item_tax_amount / self.conversion_rate)
|
||||
}))
|
||||
else:
|
||||
cwip_account = get_asset_category_account(item.asset,
|
||||
'capital_work_in_progress_account') or asset_accounts[2]
|
||||
cwip_account = get_asset_account("capital_work_in_progress_account",
|
||||
item.asset, company = self.company)
|
||||
|
||||
cwip_account_currency = get_account_currency(cwip_account)
|
||||
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)):
|
||||
asset_eiiav_currency = get_account_currency(asset_accounts[1])
|
||||
asset_eiiav_currency = get_account_currency(eiiav_account)
|
||||
gl_entries.append(self.get_gl_dict({
|
||||
"account": asset_accounts[1],
|
||||
"account": eiiav_account,
|
||||
"against": self.supplier,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
|
||||
"cost_center": item.cost_center,
|
||||
|
@ -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):
|
||||
|
@ -558,7 +558,8 @@ class BuyingController(StockController):
|
||||
'actual_qty': d.qty,
|
||||
'purchase_document_type': self.doctype,
|
||||
'purchase_document_no': self.name,
|
||||
'asset': d.asset
|
||||
'asset': d.asset,
|
||||
'location': d.asset_location
|
||||
})
|
||||
d.db_set('serial_no', serial_nos)
|
||||
|
||||
|
@ -1223,7 +1223,7 @@
|
||||
"collapsible": 1,
|
||||
"collapsible_depends_on": "eval:doc.has_batch_no || doc.has_serial_no || doc.is_fixed_asset",
|
||||
"columns": 0,
|
||||
"depends_on": "is_stock_item",
|
||||
"depends_on": "eval:doc.is_stock_item || doc.is_fixed_asset",
|
||||
"fieldname": "serial_nos_and_batches",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@ -3918,7 +3918,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 1,
|
||||
"modified": "2018-05-28 14:18:03.234070",
|
||||
"modified": "2018-06-11 17:11:55.458770",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Item",
|
||||
|
@ -13,8 +13,8 @@ from erpnext.controllers.buying_controller import BuyingController
|
||||
from erpnext.accounts.utils import get_account_currency
|
||||
from frappe.desk.notifications import clear_doctype_notifications
|
||||
from erpnext.buying.utils import check_for_closed_status
|
||||
from erpnext.assets.doctype.asset.asset import get_asset_account
|
||||
from six import iteritems
|
||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||
|
||||
form_grid_templates = {
|
||||
"items": "templates/form_grid/item_grid.html"
|
||||
@ -314,12 +314,11 @@ class PurchaseReceipt(BuyingController):
|
||||
def get_asset_gl_entry(self, gl_entries):
|
||||
for d in self.get("items"):
|
||||
if d.is_fixed_asset:
|
||||
asset_accounts = self.get_company_default(["capital_work_in_progress_account",
|
||||
"asset_received_but_not_billed"])
|
||||
arbnb_account = self.get_company_default("asset_received_but_not_billed")
|
||||
|
||||
# CWIP entry
|
||||
cwip_account = get_asset_category_account(d.asset,
|
||||
'capital_work_in_progress_account') or asset_accounts[0]
|
||||
cwip_account = get_asset_account("capital_work_in_progress_account", d.asset,
|
||||
company = self.company)
|
||||
|
||||
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)
|
||||
@ -327,7 +326,7 @@ class PurchaseReceipt(BuyingController):
|
||||
cwip_account_currency = get_account_currency(cwip_account)
|
||||
gl_entries.append(self.get_gl_dict({
|
||||
"account": cwip_account,
|
||||
"against": asset_accounts[1],
|
||||
"against": arbnb_account,
|
||||
"cost_center": d.cost_center,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
|
||||
"debit": base_asset_amount,
|
||||
@ -336,10 +335,10 @@ class PurchaseReceipt(BuyingController):
|
||||
}))
|
||||
|
||||
# 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({
|
||||
"account": asset_accounts[1],
|
||||
"against": asset_accounts[0],
|
||||
"account": arbnb_account,
|
||||
"against": cwip_account,
|
||||
"cost_center": d.cost_center,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
|
||||
"credit": base_asset_amount,
|
||||
|
@ -306,6 +306,7 @@ def auto_make_serial_nos(args):
|
||||
sr.via_stock_ledger = True
|
||||
sr.item_code = args.get('item_code')
|
||||
sr.warehouse = args.get('warehouse') if args.get('actual_qty', 0) > 0 else None
|
||||
sr.location = args.get('location')
|
||||
sr.save(ignore_permissions=True)
|
||||
elif args.get('actual_qty', 0) > 0:
|
||||
make_serial_no(serial_no, args)
|
||||
@ -330,6 +331,7 @@ def make_serial_no(serial_no, args):
|
||||
sr.company = args.get('company')
|
||||
sr.via_stock_ledger = args.get('via_stock_ledger') or True
|
||||
sr.asset = args.get('asset')
|
||||
sr.location = args.get('location')
|
||||
|
||||
if args.get('purchase_document_type'):
|
||||
sr.purchase_document_type = args.get('purchase_document_type')
|
||||
|
Loading…
x
Reference in New Issue
Block a user