Merge pull request #5812 from nabinhait/budget_demo

Demo data for Budget
This commit is contained in:
Nabin Hait 2016-07-21 18:32:56 +05:30 committed by GitHub
commit 6889d294ae
2 changed files with 24 additions and 6 deletions

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
import random, json
from frappe.utils.make_random import add_random_children, get_random
from erpnext.demo.domains import data
import frappe, erpnext
from frappe.utils import flt, now_datetime, cstr, nowdate, add_days
@ -33,6 +34,7 @@ def setup_data():
setup_salary_structure_for_timesheet()
setup_account_to_expense_type()
setup_user_roles()
setup_budget()
frappe.db.commit()
frappe.clear_cache()
@ -339,6 +341,26 @@ def setup_account_to_expense_type():
})
doc.save(ignore_permissions=True)
def setup_budget():
fiscal_years = frappe.get_all("Fiscal Year", order_by="year_start_date")[-2:]
for fy in fiscal_years:
budget = frappe.new_doc("Budget")
budget.cost_center = get_random("Cost Center")
budget.fiscal_year = fy.name
budget.action_if_annual_budget_exceeded = "Warn"
expense_ledger_count = frappe.db.count("Account", {"is_group": "0", "root_type": "Expense"})
add_random_children(budget, "accounts", rows=random.randint(10, expense_ledger_count), randomize = { "account": ("Account", {"is_group": "0", "root_type": "Expense"})
}, unique="account")
for d in budget.accounts:
d.budget_amount = random.randint(5, 100) * 10000
budget.save()
budget.submit()
def setup_user_roles():
if not frappe.db.get_global('demo_hr_user'):
user = frappe.get_doc('User', 'CharmaineGaudreau@example.com')

View File

@ -113,15 +113,11 @@ def make_sales_invoice_for_timesheet(name):
sales_invoice = make_sales_invoice(name)
sales_invoice.customer = get_random("Customer")
sales_invoice.append('items', {
'item_code': get_random_item(),
'item_code': get_random("Item", {"has_variants": 0, "is_stock_item": 0, "is_fixed_asset": 0}),
'qty': 1,
'rate': 1000
})
sales_invoice.set_missing_values()
sales_invoice.calculate_taxes_and_totals()
sales_invoice.insert()
sales_invoice.submit()
def get_random_item():
return frappe.db.sql_list(""" select name from `tabItem` where
has_variants=0 and is_stock_item=0 and is_fixed_asset=0 order by rand() limit 1""")[0]
sales_invoice.submit()