From 74edfff0a7ab5af8615583ad7676d2f0a816095e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 21 Jul 2016 11:39:46 +0530 Subject: [PATCH] Demo data for Budget --- erpnext/demo/setup_data.py | 22 ++++++++++++++++++++++ erpnext/demo/user/hr.py | 8 ++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/erpnext/demo/setup_data.py b/erpnext/demo/setup_data.py index f5c4eb3a13..5aac9e02da 100644 --- a/erpnext/demo/setup_data.py +++ b/erpnext/demo/setup_data.py @@ -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') diff --git a/erpnext/demo/user/hr.py b/erpnext/demo/user/hr.py index 50f15bb1be..219fa20fc6 100644 --- a/erpnext/demo/user/hr.py +++ b/erpnext/demo/user/hr.py @@ -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() \ No newline at end of file