Пример #1
0
def work():
	frappe.set_user(frappe.db.get_global('demo_purchase_user'))

	if random.random() < 0.3:
		report = "Items To Be Requested"
		for row in query_report.run(report)["result"][:random.randint(1, 5)]:
			item_code, qty = row[0], abs(row[-1])

			mr = make_material_request(item_code, qty)

	if random.random() < 0.3:
		for mr in frappe.get_all('Material Request',
			filters={'material_request_type': 'Purchase', 'status': 'Open'},
			limit=random.randint(1,6)):
			if not frappe.get_all('Request for Quotation',
				filters={'material_request': mr.name}, limit=1):
				rfq = make_request_for_quotation(mr.name)
				rfq.transaction_date = frappe.flags.current_date
				add_suppliers(rfq)
				rfq.save()
				rfq.submit()

	# Make suppier quotation from RFQ against each supplier.
	if random.random() < 0.3:
		for rfq in frappe.get_all('Request for Quotation',
			filters={'status': 'Open'}, limit=random.randint(1, 6)):
			if not frappe.get_all('Supplier Quotation',
				filters={'request_for_quotation': rfq.name}, limit=1):
				rfq = frappe.get_doc('Request for Quotation', rfq.name)

				for supplier in rfq.suppliers:
					supplier_quotation = make_quotation_from_rfq(rfq.name, supplier.supplier)
					supplier_quotation.save()
					supplier_quotation.submit()

	# get supplier details
	supplier = get_random("Supplier")

	company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
	party_account_currency = get_party_account_currency("Supplier", supplier, "Wind Power LLC")
	if company_currency == party_account_currency:
		exchange_rate = 1
	else:
		exchange_rate = get_exchange_rate(party_account_currency, company_currency)

	# make supplier quotations
	if random.random() < 0.2:
		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"][:random.randint(1, 3)]:
			if row[0] != "'Total'":
				sq = frappe.get_doc(make_supplier_quotation(row[0]))
				sq.transaction_date = frappe.flags.current_date
				sq.supplier = supplier
				sq.currency = party_account_currency or company_currency
				sq.conversion_rate = exchange_rate
				sq.insert()
				sq.submit()
				frappe.db.commit()

	# make purchase orders
	if random.random() < 0.5:
		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 = supplier
				po.currency = party_account_currency or company_currency
				po.conversion_rate = exchange_rate
				po.transaction_date = frappe.flags.current_date
				po.insert()
				po.submit()
				frappe.db.commit()

	if random.random() < 0.2:
		make_subcontract()
Пример #2
0
def run():
	frappe.set_user("*****@*****.**")
	frappe.set_user_lang("fr")

	if random.random() < 0.6:
		report = "Items To Be Requested"
		for row in query_report.run(report)["result"][:random.randint(1, 5)]:
			item_code, qty = row[0], abs(row[-1])

			mr = make_material_request(item_code, qty)

	if random.random() < 0.6:
		for mr in frappe.get_all('Material Request',
			filters={'material_request_type': 'Purchase', 'status': 'Open'},
			limit=random.randint(1,6)):
			if not frappe.get_all('Request for Quotation',
				filters={'material_request': mr.name}, limit=1):
				rfq = make_request_for_quotation(mr.name)
				rfq.transaction_date = frappe.flags.current_date
				add_suppliers(rfq)
				rfq.save()
				rfq.submit()

	# Make suppier quotation from RFQ against each supplier.
	if random.random() < 0.6:
		for rfq in frappe.get_all('Request for Quotation',
			filters={'status': 'Open'}, limit=random.randint(1, 6)):
			if not frappe.get_all('Supplier Quotation',
				filters={'request_for_quotation': rfq.name}, limit=1):
				rfq = frappe.get_doc('Request for Quotation', rfq.name)

				for supplier in rfq.suppliers:
					supplier_quotation = make_quotation_from_rfq(rfq.name, supplier.supplier)
					supplier_quotation.save()
					supplier_quotation.submit()

	# get supplier details
	supplier = get_random("Supplier")

	company_currency = frappe.get_cached_value('Company', erpnext.get_default_company(), "default_currency")
	party_account_currency = get_party_account_currency("Supplier", supplier, erpnext.get_default_company())
	if company_currency == party_account_currency:
		exchange_rate = 1
	else:
		exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_buying")

	# make supplier quotations
	if random.random() < 0.5:
		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"][:random.randint(1, 3)]:
			if row[0] != "Total":
				sq = frappe.get_doc(make_supplier_quotation(row[0]))
				sq.transaction_date = frappe.flags.current_date
				sq.supplier = supplier
				sq.currency = party_account_currency or company_currency
				sq.conversion_rate = exchange_rate
				sq.insert()
				sq.submit()
				frappe.db.commit()

	# make purchase orders
	if random.random() < 0.5:
		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":
				try:
					po = frappe.get_doc(make_purchase_order(row[0]))
					po.supplier = supplier
					po.currency = party_account_currency or company_currency
					po.conversion_rate = exchange_rate
					po.transaction_date = frappe.flags.current_date
					po.insert()
					po.submit()
				except Exception:
					pass
				else:
					frappe.db.commit()

	if random.random() < 0.5:
		make_subcontract()
Пример #3
0
def run_purchase(current_date):

	if can_make("Material Request"):
		report = "Items To Be Requested"
		for row in query_report.run(report)["result"][:how_many("Material Request")]:
			mr = make_material_request(current_date, row[0], -row[-1])

			if mr and can_make("Request for Quotation"):
				rfq = make_request_for_quotation(mr.name)
				rfq.transaction_date = current_date
				rfq.status = "Draft"
				rfq.company = 'Wind Power LLC'
				add_suppliers(rfq)
				rfq.message_for_supplier = 'Please supply the specified items at the best possible rates.'
				rfq.save()
				rfq.submit()

				# Make suppier quotation from RFQ against each supplier.

				for supplier in rfq.suppliers:
					supplier_quotation = make_quotation_from_rfq(rfq.name, supplier.supplier)
					supplier_quotation.save()
					supplier_quotation.submit()

	# get supplier details
	supplier = get_random("Supplier")

	company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
	party_account_currency = get_party_account_currency("Supplier", supplier, "Wind Power LLC")
	if company_currency == party_account_currency:
		exchange_rate = 1
	else:
		exchange_rate = get_exchange_rate(party_account_currency, company_currency)

	# 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.supplier = supplier
				sq.currency = party_account_currency or company_currency
				sq.conversion_rate = exchange_rate
				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 = supplier
				po.currency = party_account_currency or company_currency
				po.conversion_rate = exchange_rate
				po.transaction_date = current_date
				po.insert()
				po.submit()
				frappe.db.commit()

	if can_make("Subcontract"):
		make_subcontract(current_date)