示例#1
0
def run_projects(current_date):
	if can_make("Project"):
		make_project(current_date)
		frappe.db.commit()

	if can_make("Task"):
		close_tasks(current_date)
		frappe.db.commit()
示例#2
0
def run_sales(current_date):
	if can_make("Opportunity"):
		for i in xrange(how_many("Opportunity")):
			make_opportunity(current_date)

	if can_make("Quotation"):
		for i in xrange(how_many("Quotation")):
			make_quotation(current_date)

	if can_make("Sales Order"):
		for i in xrange(how_many("Sales Order")):
			make_sales_order(current_date)
示例#3
0
def run_accounts(current_date):
	if can_make("Sales Invoice"):
		from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
		report = "Ordered Items to be Billed"
		for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
			si = frappe.get_doc(make_sales_invoice(so))
			si.posting_date = current_date
			si.fiscal_year = cstr(current_date.year)
			for d in si.get("items"):
				if not d.income_account:
					d.income_account = "Sales - {}".format(settings.company_abbr)
			si.insert()
			si.submit()
			frappe.db.commit()

	if can_make("Purchase Invoice"):
		from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
		report = "Received Items to be Billed"
		for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
			pi = frappe.get_doc(make_purchase_invoice(pr))
			pi.posting_date = current_date
			pi.fiscal_year = cstr(current_date.year)
			pi.bill_no = random_string(6)
			pi.insert()
			pi.submit()
			frappe.db.commit()

	if can_make("Payment Received"):
		from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_from_sales_invoice
		report = "Accounts Receivable"
		for si in list(set([r[3] for r in query_report.run(report, {"report_date": current_date })["result"] if r[2]=="Sales Invoice"]))[:how_many("Payment Received")]:
			jv = frappe.get_doc(get_payment_entry_from_sales_invoice(si))
			jv.posting_date = current_date
			jv.cheque_no = random_string(6)
			jv.cheque_date = current_date
			jv.insert()
			jv.submit()
			frappe.db.commit()

	if can_make("Payment Made"):
		from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_from_purchase_invoice
		report = "Accounts Payable"
		for pi in list(set([r[3] for r in query_report.run(report, {"report_date": current_date })["result"] if r[2]=="Purchase Invoice"]))[:how_many("Payment Made")]:
			jv = frappe.get_doc(get_payment_entry_from_purchase_invoice(pi))
			jv.posting_date = current_date
			jv.cheque_no = random_string(6)
			jv.cheque_date = current_date
			jv.insert()
			jv.submit()
			frappe.db.commit()
def run_manufacturing(current_date):
	from erpnext.projects.doctype.time_log.time_log import NotSubmittedError

	ppt = frappe.get_doc("Production Planning Tool", "Production Planning Tool")
	ppt.company = settings.company
	ppt.use_multi_level_bom = 1
	ppt.purchase_request_for_warehouse = "Stores - {}".format(settings.company_abbr)
	ppt.run_method("get_open_sales_orders")
	ppt.run_method("get_items_from_so")
	ppt.run_method("raise_production_order")
	ppt.run_method("raise_purchase_request")
	frappe.db.commit()

	# submit production orders
	for pro in frappe.db.get_values("Production Order", {"docstatus": 0}, "name"):
		b = frappe.get_doc("Production Order", pro[0])
		b.wip_warehouse = "Work in Progress - WP"
		b.submit()
		frappe.db.commit()

	# submit material requests
	for pro in frappe.db.get_values("Material Request", {"docstatus": 0}, "name"):
		b = frappe.get_doc("Material Request", pro[0])
		b.submit()
		frappe.db.commit()

	# stores -> wip
	if can_make("Stock Entry for WIP"):
		for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]:
			make_stock_entry_from_pro(pro[0], "Material Transfer for Manufacture", current_date)

	# wip -> fg
	if can_make("Stock Entry for FG"):
		for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
			make_stock_entry_from_pro(pro[0], "Manufacture", current_date)

	# submit time logs
	for time_log in frappe.get_all("Time Log", ["name"], {"docstatus": 0,
		"for_manufacturing": 1, "to_time": ("<", current_date)}):
		time_log = frappe.get_doc("Time Log", time_log.name)
		time_log.submit()
示例#5
0
def run_purchase(current_date):
	# make material requests for purchase items that have negative projected qtys
	if can_make("Material Request"):
		report = "Items To Be Requested"
		for row in query_report.run(report)["result"][:how_many("Material Request")]:
			make_material_request(current_date, row[0], -row[-1])

	# make supplier quotations
	if can_make("Supplier Quotation"):
		from erpnext.stock.doctype.material_request.material_request import make_supplier_quotation

		report = "Material Requests for which Supplier Quotations are not created"
		for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
			if row[0] != "'Total'":
				sq = frappe.get_doc(make_supplier_quotation(row[0]))
				sq.transaction_date = current_date
				sq.fiscal_year = cstr(current_date.year)
				sq.supplier = get_random("Supplier")
				sq.insert()
				sq.submit()
				frappe.db.commit()

	# make purchase orders
	if can_make("Purchase Order"):
		from erpnext.stock.doctype.material_request.material_request import make_purchase_order
		report = "Requested Items To Be Ordered"
		for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
			if row[0] != "'Total'":
				po = frappe.get_doc(make_purchase_order(row[0]))
				po.supplier = get_random("Supplier")
				po.transaction_date = current_date
				po.fiscal_year = cstr(current_date.year)
				po.insert()
				po.submit()
				frappe.db.commit()

	if can_make("Subcontract"):
		make_subcontract(current_date)
示例#6
0
def make_stock_reconciliation(current_date):
	# random set some items as damaged
	from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import OpeningEntryAccountError

	if can_make("Stock Reconciliation"):
		stock_reco = frappe.new_doc("Stock Reconciliation")
		stock_reco.posting_date = current_date
		stock_reco.get_items_for("Stores - WP")
		for item in stock_reco.items:
			if item.qty:
				item.qty = item.qty - round(random.random())
		try:
			stock_reco.insert()
			stock_reco.submit()
			frappe.db.commit()
		except OpeningEntryAccountError:
			frappe.db.rollback()
示例#7
0
def make_purchase_receipt(current_date):
	if can_make("Purchase Receipt"):
		from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
		report = "Purchase Order Items To Be Received"
		po_list =list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="'Total'"]))[:how_many("Purchase Receipt")]
		for po in po_list:
			pr = frappe.get_doc(make_purchase_receipt(po))

			if pr.is_subcontracted=="Yes":
				pr.supplier_warehouse = "Supplier - WP"

			pr.posting_date = current_date
			pr.fiscal_year = cstr(current_date.year)
			pr.insert()
			try:
				pr.submit()
				frappe.db.commit()
			except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError):
				frappe.db.rollback()
示例#8
0
def make_delivery_note(current_date):
	# make purchase requests

	# make delivery notes (if possible)
	if can_make("Delivery Note"):
		from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
		report = "Ordered Items To Be Delivered"
		for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="'Total'"]))[:how_many("Delivery Note")]:
			dn = frappe.get_doc(make_delivery_note(so))
			dn.posting_date = current_date
			dn.fiscal_year = cstr(current_date.year)
			for d in dn.get("items"):
				if not d.expense_account:
					d.expense_account = "Cost of Goods Sold - {}".format(settings.company_abbr)

			dn.insert()
			try:
				dn.submit()
				frappe.db.commit()
			except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError):
				frappe.db.rollback()
示例#9
0
def run_messages(current_date):
	if can_make("Message"):
		make_message(current_date)