Merge pull request #5804 from nabinhait/demo1

Demo data for fixed asset depreciation
This commit is contained in:
Nabin Hait 2016-07-21 10:05:00 +05:30 committed by GitHub
commit 89d0b1b9a5
9 changed files with 214 additions and 9 deletions

View File

@ -63,10 +63,10 @@ def make_depreciation_entry(asset_name, date=None):
d.db_set("journal_entry", je.name)
asset.value_after_depreciation -= d.depreciation_amount
asset.db_set("value_after_depreciation", asset.value_after_depreciation)
asset.set_status()
return asset
asset.db_set("value_after_depreciation", asset.value_after_depreciation)
asset.set_status()
return asset
def get_depreciation_accounts(asset):
fixed_asset_account = accumulated_depreciation_account = depreciation_expense_account = None

View File

@ -0,0 +1,37 @@
[
{
"asset_name": "Macbook Pro - 1",
"item_code": "Computer",
"gross_purchase_amount": 100000
},
{
"asset_name": "Macbook Air - 1",
"item_code": "Computer",
"gross_purchase_amount": 60000
},
{
"asset_name": "Conferrence Table",
"item_code": "Table",
"gross_purchase_amount": 30000
},
{
"asset_name": "Lunch Table",
"item_code": "Table",
"gross_purchase_amount": 20000
},
{
"asset_name": "ERPNext",
"item_code": "ERP",
"gross_purchase_amount": 100000
},
{
"asset_name": "Chair 1",
"item_code": "Chair",
"gross_purchase_amount": 10000
},
{
"asset_name": "Chair 2",
"item_code": "Chair",
"gross_purchase_amount": 10000
}
]

View File

@ -0,0 +1,38 @@
[
{
"asset_category_name": "Furnitures",
"depreciation_method": "Straight Line",
"total_number_of_depreciations": 5,
"frequency_of_depreciation": 12,
"accounts": [{
"company_name": "Wind Power LLC",
"fixed_asset_account": "Furnitures and Fixtures - WPL",
"accumulated_depreciation_account": "Accumulated Depreciation - WPL",
"depreciation_expense_account": "Depreciation - WPL"
}]
},
{
"asset_category_name": "Electronic Equipments",
"depreciation_method": "Double Declining Balance",
"total_number_of_depreciations": 10,
"frequency_of_depreciation": 6,
"accounts": [{
"company_name": "Wind Power LLC",
"fixed_asset_account": "Electronic Equipments - WPL",
"accumulated_depreciation_account": "Accumulated Depreciation - WPL",
"depreciation_expense_account": "Depreciation - WPL"
}]
},
{
"asset_category_name": "Softwares",
"depreciation_method": "Straight Line",
"total_number_of_depreciations": 10,
"frequency_of_depreciation": 12,
"accounts": [{
"company_name": "Wind Power LLC",
"fixed_asset_account": "Softwares - WPL",
"accumulated_depreciation_account": "Accumulated Depreciation - WPL",
"depreciation_expense_account": "Depreciation - WPL"
}]
}
]

View File

@ -221,5 +221,59 @@
"item_code": "Base Plate Un Painted",
"item_group": "Raw Material",
"item_name": "Base Plate Un Painted"
},
{
"is_fixed_asset": 1,
"asset_category": "Furnitures",
"is_stock_item": 0,
"description": "Table",
"item_code": "Table",
"item_name": "Table",
"item_group": "Products"
},
{
"is_fixed_asset": 1,
"asset_category": "Furnitures",
"is_stock_item": 0,
"description": "Chair",
"item_code": "Chair",
"item_name": "Chair",
"item_group": "Products"
},
{
"is_fixed_asset": 1,
"asset_category": "Electronic Equipments",
"is_stock_item": 0,
"description": "Computer",
"item_code": "Computer",
"item_name": "Computer",
"item_group": "Products"
},
{
"is_fixed_asset": 1,
"asset_category": "Electronic Equipments",
"is_stock_item": 0,
"description": "Mobile",
"item_code": "Mobile",
"item_name": "Mobile",
"item_group": "Products"
},
{
"is_fixed_asset": 1,
"asset_category": "Softwares",
"is_stock_item": 0,
"description": "ERP",
"item_code": "ERP",
"item_name": "ERP",
"item_group": "All Item Groups"
},
{
"is_fixed_asset": 1,
"asset_category": "Softwares",
"is_stock_item": 0,
"description": "Autocad",
"item_code": "Autocad",
"item_name": "Autocad",
"item_group": "All Item Groups"
}
]

View File

@ -4,7 +4,7 @@ import frappe, sys
import erpnext
import frappe.utils
from erpnext.demo.setup_data import setup_data
from erpnext.demo.user import hr, sales, purchase, manufacturing, stock, accounts, projects
from erpnext.demo.user import hr, sales, purchase, manufacturing, stock, accounts, projects, fixed_asset
"""
Make a demo
@ -53,6 +53,8 @@ def simulate():
if not runs_for:
runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date)
# runs_for = 100
fixed_asset.work()
for i in xrange(runs_for):
sys.stdout.write("\rSimulating {0}".format(current_date.strftime("%Y-%m-%d")))

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import random, json
from erpnext.demo.domains import data
import frappe, erpnext
from frappe.utils import cint, flt, now_datetime, cstr
from frappe.utils import flt, now_datetime, cstr, nowdate, add_days
from frappe import _
def setup_data():
@ -14,8 +14,10 @@ def setup_data():
setup_holiday_list()
setup_customer()
setup_supplier()
import_json("Asset Category")
setup_item()
setup_warehouse()
setup_asset()
import_json('Address')
import_json('Contact')
setup_workstation()
@ -158,6 +160,20 @@ def setup_warehouse():
w = frappe.new_doc('Warehouse')
w.warehouse_name = 'Supplier'
w.insert()
def setup_asset():
assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read())
for d in assets:
asset = frappe.new_doc('Asset')
asset.update(d)
asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500))
asset.next_depreciation_date = add_days(asset.purchase_date, 30)
asset.warehouse = "Stores - WPL"
asset.set_missing_values()
asset.make_depreciation_schedule()
asset.flags.ignore_validate = True
asset.save()
asset.submit()
def setup_currency_exchange():
frappe.get_doc({

View File

@ -0,0 +1,59 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils.make_random import get_random
from erpnext.accounts.doctype.asset.asset import make_purchase_invoice, make_sales_invoice
from erpnext.accounts.doctype.asset.depreciation import post_depreciation_entries, scrap_asset
def work():
frappe.set_user(frappe.db.get_global('demo_accounts_user'))
asset_list = make_asset_purchase_entry()
if not asset_list:
# fixed_asset.work() already run
return
# post depreciation entries as on today
post_depreciation_entries()
# scrap a random asset
frappe.db.set_value("Company", "Wind Power LLC", "disposal_account", "Gain/Loss on Asset Disposal - WPL")
asset = get_random_asset()
scrap_asset(asset.name)
# Sell a random asset
sell_an_asset()
def make_asset_purchase_entry():
asset_list = frappe.get_all("Asset", filters={"purchase_invoice": ["in", ("", None)]},
fields=["name", "item_code", "gross_purchase_amount", "company", "purchase_date"])
# make purchase invoice
for asset in asset_list:
pi = make_purchase_invoice(asset.name, asset.item_code, asset.gross_purchase_amount,
asset.company, asset.purchase_date)
pi.supplier = get_random("Supplier")
pi.save()
pi.submit()
return asset_list
def sell_an_asset():
asset = get_random_asset()
si = make_sales_invoice(asset.name, asset.item_code, "Wind Power LLC")
si.customer = get_random("Customer")
si.get("items")[0].rate = asset.value_after_depreciation * 0.8 \
if asset.value_after_depreciation else asset.gross_purchase_amount * 0.9
si.save()
si.submit()
def get_random_asset():
return frappe.db.sql(""" select name, item_code, value_after_depreciation, gross_purchase_amount
from `tabAsset`
where docstatus=1 and status not in ("Scrapped", "Sold") order by rand() limit 1""", as_dict=1)[0]

View File

@ -124,4 +124,4 @@ def make_sales_invoice_for_timesheet(name):
def get_random_item():
return frappe.db.sql_list(""" select name from `tabItem` where
has_variants = 0 order by rand() limit 1""")[0]
has_variants=0 and is_stock_item=0 and is_fixed_asset=0 order by rand() limit 1""")[0]

View File

@ -344,10 +344,9 @@ class update_entries_after(object):
def raise_exceptions(self):
deficiency = min(e["diff"] for e in self.exceptions)
if ((self.exceptions[0]["voucher_type"], self.exceptions[0]["voucher_no"]) in
frappe.local.flags.currently_saving):
msg = _("{0} units of {1} needed in {2} to complete this transaction.").format(
abs(deficiency), frappe.get_desk_link('Item', self.item_code),
frappe.get_desk_link('Warehouse', self.warehouse))