Beispiel #1
0
def run_manufacturing(current_date):
    from erpnext.stock.stock_ledger import NegativeStockError
    from erpnext.stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError

    ppt = frappe.get_doc("Production Planning Tool",
                         "Production Planning Tool")
    ppt.company = company
    ppt.use_multi_level_bom = 1
    ppt.purchase_request_for_warehouse = "物料 - {}".format(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 = "在制品 - 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",
                                      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/Repack",
                                      current_date)

    # try posting older drafts (if exists)
    for st in frappe.db.get_values("Stock Entry", {"docstatus": 0}, "name"):
        try:
            frappe.get_doc("Stock Entry", st[0]).submit()
            frappe.db.commit()
        except NegativeStockError:
            pass
        except IncorrectValuationRateError:
            pass
        except DuplicateEntryForProductionOrderError:
            pass
Beispiel #2
0
def run_stock(current_date):
    # make purchase requests
    if can_make("Purchase Receipt"):
        from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
        from erpnext.stock.stock_ledger import NegativeStockError
        report = "Purchase Order Items To Be Received"
        for po in list(
                set([
                    r[0] for r in query_report.run(report)["result"]
                    if r[0] != "Total"
                ]))[:how_many("Purchase Receipt")]:
            pr = frappe.get_doc(make_purchase_receipt(po))
            pr.posting_date = current_date
            pr.fiscal_year = cstr(current_date.year)
            pr.insert()
            try:
                pr.submit()
                frappe.db.commit()
            except NegativeStockError:
                pass

    # make delivery notes (if possible)
    if can_make("Delivery Note"):
        from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
        from erpnext.stock.stock_ledger import NegativeStockError
        from erpnext.stock.doctype.serial_no.serial_no import SerialNoRequiredError, SerialNoQtyError
        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("delivery_note_details"):
                if not d.expense_account:
                    d.expense_account = "销货成本 - {}".format(company_abbr)

            dn.insert()
            try:
                dn.submit()
                frappe.db.commit()
            except NegativeStockError:
                pass
            except SerialNoRequiredError:
                pass
            except SerialNoQtyError:
                pass

    # try submitting existing
    for dn in frappe.db.get_values("Delivery Note", {"docstatus": 0}, "name"):
        b = frappe.get_doc("Delivery Note", dn[0])
        b.submit()
        frappe.db.commit()
Beispiel #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("entries"):
				if not d.income_account:
					d.income_account = "Sales - {}".format(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_voucher.journal_voucher import get_payment_entry_from_sales_invoice
		report = "Accounts Receivable"
		for si in list(set([r[4] for r in query_report.run(report, {"report_date": current_date })["result"] if r[3]=="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.fiscal_year = cstr(current_date.year)
			jv.insert()
			jv.submit()
			frappe.db.commit()
			
	if can_make("Payment Made"):
		from erpnext.accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
		report = "Accounts Payable"
		for pi in list(set([r[4] for r in query_report.run(report, {"report_date": current_date })["result"] if r[3]=="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.fiscal_year = cstr(current_date.year)
			jv.insert()
			jv.submit()
			frappe.db.commit()
Beispiel #4
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")]:
            mr = frappe.new_doc("Material Request")
            mr.material_request_type = "Purchase"
            mr.transaction_date = current_date
            mr.fiscal_year = cstr(current_date.year)
            mr.append(
                "indent_details", {
                    "doctype": "Material Request Item",
                    "schedule_date": frappe.utils.add_days(current_date, 7),
                    "item_code": row[0],
                    "qty": -row[-1]
                })
            mr.insert()
            mr.submit()

    # 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.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.transaction_date = current_date
                po.fiscal_year = cstr(current_date.year)
                po.insert()
                po.submit()
                frappe.db.commit()
Beispiel #5
0
def run_manufacturing(current_date):
	from erpnext.stock.stock_ledger import NegativeStockError
	from erpnext.stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError

	ppt = frappe.get_doc("Production Planning Tool", "Production Planning Tool")
	ppt.company = company
	ppt.use_multi_level_bom = 1
	ppt.purchase_request_for_warehouse = "Stores - {}".format(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", 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/Repack", current_date)

	# try posting older drafts (if exists)
	for st in frappe.db.get_values("Stock Entry", {"docstatus":0}, "name"):
		try:
			frappe.get_doc("Stock Entry", st[0]).submit()
			frappe.db.commit()
		except NegativeStockError: pass
		except IncorrectValuationRateError: pass
		except DuplicateEntryForProductionOrderError: pass
Beispiel #6
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")]:
			mr = frappe.new_bean("Material Request")
			mr.material_request_type = "Purchase"
			mr.transaction_date = current_date
			mr.fiscal_year = cstr(current_date.year)
			mr.append("indent_details", {
				"doctype": "Material Request Item",
				"schedule_date": frappe.utils.add_days(current_date, 7),
				"item_code": row[0],
				"qty": -row[-1]
			})
			mr.insert()
			mr.submit()
	
	# 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.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.transaction_date = current_date
				po.fiscal_year = cstr(current_date.year)
				po.insert()
				po.submit()
				frappe.db.commit()
Beispiel #7
0
def run_stock(current_date):
	# make purchase requests
	if can_make("Purchase Receipt"):
		from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
		from erpnext.stock.stock_ledger import NegativeStockError
		report = "Purchase Order Items To Be Received"
		for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]:
			pr = frappe.get_doc(make_purchase_receipt(po))
			pr.posting_date = current_date
			pr.fiscal_year = cstr(current_date.year)
			pr.insert()
			try:
				pr.submit()
				frappe.db.commit()
			except NegativeStockError: pass
	
	# make delivery notes (if possible)
	if can_make("Delivery Note"):
		from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
		from erpnext.stock.stock_ledger import NegativeStockError
		from erpnext.stock.doctype.serial_no.serial_no import SerialNoRequiredError, SerialNoQtyError
		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("delivery_note_details"):
				if not d.expense_account:
					d.expense_account = "Cost of Goods Sold - {}".format(company_abbr)
				
			dn.insert()
			try:
				dn.submit()
				frappe.db.commit()
			except NegativeStockError: pass
			except SerialNoRequiredError: pass
			except SerialNoQtyError: pass
	
	# try submitting existing
	for dn in frappe.db.get_values("Delivery Note", {"docstatus": 0}, "name"):
		b = frappe.get_doc("Delivery Note", dn[0])
		b.submit()
		frappe.db.commit()
Beispiel #8
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("entries"):
                if not d.income_account:
                    d.income_account = "Sales - {}".format(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_voucher.journal_voucher import get_payment_entry_from_sales_invoice
        report = "Accounts Receivable"
        for si in list(
                set([
                    r[4] for r in query_report.run(
                        report, {"report_date": current_date})["result"]
                    if r[3] == "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.fiscal_year = cstr(current_date.year)
            jv.insert()
            jv.submit()
            frappe.db.commit()

    if can_make("Payment Made"):
        from erpnext.accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
        report = "Accounts Payable"
        for pi in list(
                set([
                    r[4] for r in query_report.run(
                        report, {"report_date": current_date})["result"]
                    if r[3] == "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.fiscal_year = cstr(current_date.year)
            jv.insert()
            jv.submit()
            frappe.db.commit()