Esempio n. 1
0
def run_manufacturing(current_date):
    from erpnext.projects.doctype.time_log.time_log import NotSubmittedError, OverlapError

    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")
    ppt.run_method("raise_production_orders")
    ppt.run_method("raise_material_requests")
    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,
                "production_order": ("!=", ""),
                "to_time": ("<", current_date)
            }):
        time_log = frappe.get_doc("Time Log", time_log.name)
        try:
            time_log.submit()
            frappe.db.commit()
        except OverlapError:
            pass
Esempio n. 2
0
def work():
	frappe.set_user(frappe.db.get_global('demo_manufacturing_user'))

	from erpnext.projects.doctype.timesheet.timesheet import OverlapError

	ppt = frappe.get_doc("Production Planning Tool", "Production Planning Tool")
	ppt.company = erpnext.get_default_company()
	ppt.use_multi_level_bom = 1
	ppt.get_items_from = "Sales Order"
	ppt.purchase_request_for_warehouse = "Stores - WPL"
	ppt.run_method("get_open_sales_orders")
	ppt.run_method("get_items")
	ppt.run_method("raise_production_orders")
	ppt.run_method("raise_material_requests")
	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 - WPL"
		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 random.random() < 0.3:
		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")

	# wip -> fg
	if random.random() < 0.3:
		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")

	for bom in frappe.get_all('BOM', fields=['item'], filters = {'with_operations': 1}):
		pro_order = make_prod_order_test_record(item=bom.item, qty=2,
			source_warehouse="Stores - WPL", wip_warehouse = "Work in Progress - WPL",
			fg_warehouse = "Stores - WPL", company = erpnext.get_default_company(),
			stock_uom = frappe.db.get_value('Item', bom.item, 'stock_uom'),
			planned_start_date = frappe.flags.current_date)

	# submit time logs
	for timesheet in frappe.get_all("Timesheet", ["name"], {"docstatus": 0,
		"production_order": ("!=", ""), "to_time": ("<", frappe.flags.current_date)}):
		timesheet = frappe.get_doc("Timesheet", timesheet.name)
		try:
			timesheet.submit()
			frappe.db.commit()
		except OverlapError:
			pass
		except WorkstationHolidayError:
			pass
Esempio n. 3
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])

    # 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)
Esempio n. 4
0
def work():
	if random.random() < 0.3: return

	frappe.set_user(frappe.db.get_global('demo_manufacturing_user'))
	if not frappe.get_all('Sales Order'): return

	from erpbee.projects.doctype.timesheet.timesheet import OverlapError

	ppt = frappe.new_doc("Production Plan")
	ppt.company = erpbee.get_default_company()
	# ppt.use_multi_level_bom = 1 #refactored
	ppt.get_items_from = "Sales Order"
	# ppt.purchase_request_for_warehouse = "Stores - WPL" # refactored
	ppt.run_method("get_open_sales_orders")
	if not ppt.get("sales_orders"): return
	ppt.run_method("get_items")
	ppt.run_method("raise_material_requests")
	ppt.save()
	ppt.submit()
	ppt.run_method("raise_work_orders")
	frappe.db.commit()

	# submit work orders
	for pro in frappe.db.get_values("Work Order", {"docstatus": 0}, "name"):
		b = frappe.get_doc("Work Order", pro[0])
		b.wip_warehouse = "Work in Progress - WPL"
		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 random.random() < 0.4:
		for pro in query_report.run("Open Work Orders")["result"][:how_many("Stock Entry for WIP")]:
			make_stock_entry_from_pro(pro[0], "Material Transfer for Manufacture")

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

	for bom in frappe.get_all('BOM', fields=['item'], filters = {'with_operations': 1}):
		pro_order = make_wo_order_test_record(item=bom.item, qty=2,
			source_warehouse="Stores - WPL", wip_warehouse = "Work in Progress - WPL",
			fg_warehouse = "Stores - WPL", company = erpbee.get_default_company(),
			stock_uom = frappe.db.get_value('Item', bom.item, 'stock_uom'),
			planned_start_date = frappe.flags.current_date)

	# submit job card
	if random.random() < 0.4:
		submit_job_cards()
Esempio n. 5
0
def work():
	if random.random() < 0.3: return

	frappe.set_user(frappe.db.get_global('demo_manufacturing_user'))
	if not frappe.get_all('Sales Order'): return

	from erpnext.projects.doctype.timesheet.timesheet import OverlapError

	ppt = frappe.new_doc("Production Plan")
	ppt.company = erpnext.get_default_company()
	# ppt.use_multi_level_bom = 1 #refactored
	ppt.get_items_from = "Sales Order"
	# ppt.purchase_request_for_warehouse = "Stores - WPL" # refactored
	ppt.run_method("get_open_sales_orders")
	if not ppt.get("sales_orders"): return
	ppt.run_method("get_items")
	ppt.run_method("raise_material_requests")
	ppt.save()
	ppt.submit()
	ppt.run_method("raise_work_orders")
	frappe.db.commit()

	# submit work orders
	for pro in frappe.db.get_values("Work Order", {"docstatus": 0}, "name"):
		b = frappe.get_doc("Work Order", pro[0])
		b.wip_warehouse = "Work in Progress - WPL"
		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 random.random() < 0.4:
		for pro in query_report.run("Open Work Orders")["result"][:how_many("Stock Entry for WIP")]:
			make_stock_entry_from_pro(pro[0], "Material Transfer for Manufacture")

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

	for bom in frappe.get_all('BOM', fields=['item'], filters = {'with_operations': 1}):
		pro_order = make_wo_order_test_record(item=bom.item, qty=2,
			source_warehouse="Stores - WPL", wip_warehouse = "Work in Progress - WPL",
			fg_warehouse = "Stores - WPL", company = erpnext.get_default_company(),
			stock_uom = frappe.db.get_value('Item', bom.item, 'stock_uom'),
			planned_start_date = frappe.flags.current_date)

	# submit job card
	if random.random() < 0.4:
		submit_job_cards()
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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])

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

    company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
    party_account_currency = frappe.db.get_value("Supplier", supplier, "party_account_currency")
    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.fiscal_year = cstr(current_date.year)
                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.fiscal_year = cstr(current_date.year)
                po.insert()
                po.submit()
                frappe.db.commit()

    if can_make("Subcontract"):
        make_subcontract(current_date)
Esempio n. 9
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
            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()
Esempio n. 10
0
def run_manufacturing(current_date):
	from erpnext.projects.doctype.time_log.time_log import NotSubmittedError, OverlapError

	ppt = frappe.get_doc("Production Planning Tool", "Production Planning Tool")
	ppt.company = settings.company
	ppt.use_multi_level_bom = 1
	ppt.get_items_from = "Sales Order"
	ppt.purchase_request_for_warehouse = "Stores - {}".format(settings.company_abbr)
	ppt.run_method("get_open_sales_orders")
	ppt.run_method("get_items")
	ppt.run_method("raise_production_orders")
	ppt.run_method("raise_material_requests")
	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,
		"production_order": ("!=", ""), "to_time": ("<", current_date)}):
		time_log = frappe.get_doc("Time Log", time_log.name)
		try:
			time_log.submit()
			frappe.db.commit()
		except OverlapError:
			pass
Esempio n. 11
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)
Esempio n. 12
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.insert()
            try:
                pr.submit()
                frappe.db.commit()
            except (NegativeStockError, SerialNoRequiredError,
                    SerialNoQtyError):
                frappe.db.rollback()
Esempio n. 13
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()
Esempio n. 14
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()
Esempio n. 15
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()
Esempio n. 16
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)
Esempio n. 17
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()
Esempio n. 18
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
			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.bill_no = random_string(6)
			pi.insert()
			pi.submit()
			frappe.db.commit()

	from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice

	if can_make("Payment Received"):
		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_against_invoice("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"):
		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_against_invoice("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()
Esempio n. 19
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()