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
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
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)
def work(): frappe.set_user(frappe.db.get_global('demo_accounts_user')) if random.random() <= 0.6: 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"]))[:random.randint(1, 5)]: try: si = frappe.get_doc(make_sales_invoice(so)) si.posting_date = frappe.flags.current_date for d in si.get("items"): if not d.income_account: d.income_account = "Sales - {}".format( frappe.get_cached_value('Company', si.company, 'abbr')) si.insert() si.submit() frappe.db.commit() except frappe.ValidationError: pass if random.random() <= 0.6: 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"]))[:random.randint(1, 5)]: try: pi = frappe.get_doc(make_purchase_invoice(pr)) pi.posting_date = frappe.flags.current_date pi.bill_no = random_string(6) pi.insert() pi.submit() frappe.db.commit() except frappe.ValidationError: pass if random.random() < 0.5: make_payment_entries("Sales Invoice", "Accounts Receivable") if random.random() < 0.5: make_payment_entries("Purchase Invoice", "Accounts Payable") if random.random() < 0.4: # make payment request against sales invoice sales_invoice_name = get_random( "Sales Invoice", filters={"docstatus": 1}) if sales_invoice_name: si = frappe.get_doc("Sales Invoice", sales_invoice_name) if si.outstanding_amount > 0: payment_request = make_payment_request(dt="Sales Invoice", dn=si.name, recipient_id=si.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) payment_entry = frappe.get_doc( make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit() make_pos_invoice()
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()
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()
def work(): frappe.set_user(frappe.db.get_global('demo_accounts_user')) if random.random() <= 0.6: 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"]))[:random.randint(1, 5)]: try: si = frappe.get_doc(make_sales_invoice(so)) si.posting_date = frappe.flags.current_date for d in si.get("items"): if not d.income_account: d.income_account = "Sales - {}".format(frappe.db.get_value('Company', si.company, 'abbr')) si.insert() si.submit() frappe.db.commit() except frappe.ValidationError: pass if random.random() <= 0.6: 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"]))[:random.randint(1, 5)]: try: pi = frappe.get_doc(make_purchase_invoice(pr)) pi.posting_date = frappe.flags.current_date pi.bill_no = random_string(6) pi.insert() pi.submit() frappe.db.commit() except frappe.ValidationError: pass if random.random() < 0.5: make_payment_entries("Sales Invoice", "Accounts Receivable") if random.random() < 0.5: make_payment_entries("Purchase Invoice", "Accounts Payable") if random.random() < 0.1: #make payment request against sales invoice sales_invoice_name = get_random("Sales Invoice", filters={"docstatus": 1}) if sales_invoice_name: si = frappe.get_doc("Sales Invoice", sales_invoice_name) if si.outstanding_amount > 0: payment_request = make_payment_request(dt="Sales Invoice", dn=si.name, recipient_id=si.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit() make_pos_invoice()
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)
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() 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()
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 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()
def make_delivery_note(): # make purchase requests # make delivery notes (if possible) if random.random() < 0.6: 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" ]))[:random.randint(1, 3)]: dn = frappe.get_doc(make_delivery_note(so)) dn.posting_date = frappe.flags.current_date for d in dn.get("items"): if not d.expense_account: d.expense_account = ("Cost of Goods Sold - {0}".format( frappe.get_cached_value('Company', dn.company, 'abbr'))) try: dn.insert() dn.submit() frappe.db.commit() except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError, UnableToSelectBatchError): frappe.db.rollback()
def make_payment_entries(ref_doctype, report): outstanding_invoices = list( set([ r[3] for r in query_report.run( report, {"report_date": frappe.flags.current_date})["result"] if r[2] == ref_doctype ])) # make Payment Entry for inv in outstanding_invoices[:random.randint(1, 2)]: pe = get_payment_entry(ref_doctype, inv) pe.posting_date = frappe.flags.current_date pe.reference_no = random_string(6) pe.reference_date = frappe.flags.current_date pe.insert() pe.submit() frappe.db.commit() outstanding_invoices.remove(inv) # make payment via JV for inv in outstanding_invoices[:1]: jv = frappe.get_doc(get_payment_entry_against_invoice( ref_doctype, inv)) jv.posting_date = frappe.flags.current_date jv.cheque_no = random_string(6) jv.cheque_date = frappe.flags.current_date jv.insert() jv.submit() frappe.db.commit()
def test_report_with_custom_column(self): reset_customization('User') response = run('Permitted Documents For User', filters={ 'user': '******', 'doctype': 'User' }, custom_columns=[{ 'fieldname': 'email', 'fieldtype': 'Data', 'label': 'Email', 'insert_after_index': 0, 'link_field': 'name', 'doctype': 'User', 'options': 'Email', 'width': 100, 'id': 'email', 'name': 'Email' }]) result = response.get('result') columns = response.get('columns') self.assertListEqual(['name', 'email', 'user_type'], [column.get('fieldname') for column in columns]) admin_dict = frappe.core.utils.find( result, lambda d: d['name'] == 'Administrator') self.assertDictEqual( { 'name': 'Administrator', 'user_type': 'System User', 'email': '*****@*****.**' }, admin_dict)
def test_report_with_custom_column(self): reset_customization("User") response = run( "Permitted Documents For User", filters={ "user": "******", "doctype": "User" }, custom_columns=[{ "fieldname": "email", "fieldtype": "Data", "label": "Email", "insert_after_index": 0, "link_field": "name", "doctype": "User", "options": "Email", "width": 100, "id": "email", "name": "Email", }], ) result = response.get("result") columns = response.get("columns") self.assertListEqual(["name", "email", "user_type"], [column.get("fieldname") for column in columns]) admin_dict = frappe.core.utils.find( result, lambda d: d["name"] == "Administrator") self.assertDictEqual( { "name": "Administrator", "user_type": "System User", "email": "*****@*****.**" }, admin_dict)
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
def export_query(): """export from query reports""" data = frappe._dict(frappe.local.form_dict) del data["cmd"] if "csrf_token" in data: del data["csrf_token"] if isinstance(data.get("filters"), string_types): filters = json.loads(data["filters"]) if isinstance(data.get("report_name"), string_types): report_name = data["report_name"] if isinstance(data.get("file_format_type"), string_types): file_format_type = data["file_format_type"] if isinstance(data.get("visible_idx"), string_types): visible_idx = json.loads(data.get("visible_idx")) else: visible_idx = None if file_format_type == "Excel": data = run(report_name, filters) data = frappe._dict(data) columns = get_columns_dict(data.columns) result = [[]] # add column headings for idx in range(len(data.columns)): result[0].append(columns[idx]["label"]) # build table from dict if isinstance(data.result[0], dict): for i, row in enumerate(data.result): # only rows which are visible in the report if row and (i + 1 in visible_idx): row_list = [] for idx in range(len(data.columns)): row_list.append(row.get(columns[idx]["fieldname"], "")) result.append(row_list) elif not row: result.append([]) else: result = result + [ d for i, d in enumerate(data.result) if (i + 1 in visible_idx) ] #from frappe.utils.xlsxutils import make_xlsx xlsx_file = make_xlsx(result, report_name) frappe.response['filename'] = report_name + '.xlsx' frappe.response['filecontent'] = xlsx_file.getvalue() frappe.response['type'] = 'binary'
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)
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()
def wrapper(data): report_name = data.get('report_name') include_indentation = data.get('include_indentation') filters = json.loads(data.get('filters')) visible_idx = json.loads(data.get('visible_idx')) report_data = frappe._dict(run(report_name, filters)) columns = get_columns_dict(report_data.columns) xlsx_data = build_xlsx_data(columns, report_data, visible_idx, include_indentation) row_length = len(xlsx_data[0]) build = partial(build_xlsx, report_name, xlsx_data) return func(build, filters, row_length)
def make_purchase_receipt(): if random.random() < 0.6: 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'"]))[:random.randint(1, 10)] for po in po_list: pr = frappe.get_doc(make_purchase_receipt(po)) if pr.is_subcontracted=="Yes": pr.supplier_warehouse = "Supplier - WPL" pr.posting_date = frappe.flags.current_date pr.insert() try: pr.submit() except NegativeStockError: pass frappe.db.commit()
def make_purchase_receipt(): if random.random() < 0.6: 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'"]))[:random.randint(1, 10)] for po in po_list: pr = frappe.get_doc(make_purchase_receipt(po)) if pr.is_subcontracted=="Yes": pr.supplier_warehouse = "Supplier - WPL" pr.posting_date = frappe.flags.current_date pr.insert() try: pr.submit() except NegativeStockError: print 'Negative stock for {0}'.format(po) pass frappe.db.commit()
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()
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()
def export_my_query(filters, ws=None, wb=None): data = frappe._dict(frappe.local.form_dict) del data["cmd"] if "csrf_token" in data: del data["csrf_token"] if isinstance(data.get("report_name"), string_types): report_name = data["report_name"] data = run("Employee Yearly Summary", filters) data = frappe._dict(data) columns = get_columns_dict(data.columns) result = [[]] # add column headings for idx in range(len(data.columns)): result[0].append(columns[idx]["label"]) # build table from dict if isinstance(data.result[0], dict): for i, row in enumerate(data.result): # only rows which are visible in the report if row: row_list = [] for idx in range(len(data.columns)): row_list.append(row.get(columns[idx]["fieldname"], "")) result.append(row_list) elif not row: result.append([]) else: result = result + [d for i, d in enumerate(data.result)] from frappe.utils.xlsxutils import make_xlsx if ws is None: ws = "Query Report" xlsx_file = make_xlsx(result, ws, wb) frappe.response['filename'] = report_name + '.xlsx' frappe.response['filecontent'] = xlsx_file.getvalue() frappe.response['type'] = 'binary'
def make_delivery_note(): # make purchase requests # make delivery notes (if possible) if random.random() < 0.3: 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'"]))[:random.randint(1, 3)]: dn = frappe.get_doc(make_delivery_note(so)) dn.posting_date = frappe.flags.current_date for d in dn.get("items"): if not d.expense_account: d.expense_account = ("Cost of Goods Sold - {0}".format( frappe.db.get_value('Company', dn.company, 'abbr'))) dn.insert() try: dn.submit() frappe.db.commit() except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError): frappe.db.rollback()
def export_query(): """export from query reports""" data = frappe._dict(frappe.local.form_dict) del data["cmd"] if "csrf_token" in data: del data["csrf_token"] if isinstance(data.get("filters"), string_types): filters = json.loads(data["filters"]) if isinstance(data.get("report_name"), string_types): report_name = data["report_name"] frappe.permissions.can_export(frappe.get_cached_value( 'Report', report_name, 'ref_doctype'), raise_exception=True) if isinstance(data.get("file_format_type"), string_types): file_format_type = data["file_format_type"] if isinstance(data.get("visible_idx"), string_types): visible_idx = json.loads(data.get("visible_idx")) else: visible_idx = None # add filter this customer party = get_party() filters["customer"] = party.name or "" if file_format_type == "Excel": data = run(report_name, filters) data = frappe._dict(data) columns = get_columns_dict(data.columns) from frappe.utils.xlsxutils import make_xlsx xlsx_data = build_xlsx_data(columns, data) xlsx_file = make_xlsx(xlsx_data, "Query Report") frappe.response['filename'] = report_name + '.xlsx' frappe.response['filecontent'] = xlsx_file.getvalue() frappe.response['type'] = 'binary'
def make_payment_entries(ref_doctype, report): outstanding_invoices = list(set([r[3] for r in query_report.run(report, {"report_date": frappe.flags.current_date })["result"] if r[2]==ref_doctype])) # make Payment Entry for inv in outstanding_invoices[:random.randint(1, 2)]: pe = get_payment_entry(ref_doctype, inv) pe.posting_date = frappe.flags.current_date pe.reference_no = random_string(6) pe.reference_date = frappe.flags.current_date pe.insert() pe.submit() frappe.db.commit() outstanding_invoices.remove(inv) # make payment via JV for inv in outstanding_invoices[:1]: jv = frappe.get_doc(get_payment_entry_against_invoice(ref_doctype, inv)) jv.posting_date = frappe.flags.current_date jv.cheque_no = random_string(6) jv.cheque_date = frappe.flags.current_date jv.insert() jv.submit() frappe.db.commit()
def work(): frappe.set_user(frappe.db.get_global('demo_accounts_user')) if random.random() < 0.5: 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" ]))[:random.randint(1, 5)]: si = frappe.get_doc(make_sales_invoice(so)) si.posting_date = frappe.flags.current_date for d in si.get("items"): if not d.income_account: d.income_account = "Sales - {}".format( frappe.db.get_value('Company', si.company, 'abbr')) si.insert() si.submit() frappe.db.commit() if random.random() < 0.5: 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" ]))[:random.randint(1, 5)]: pi = frappe.get_doc(make_purchase_invoice(pr)) pi.posting_date = frappe.flags.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 random.random() < 0.5: report = "Accounts Receivable" for si in list( set([ r[3] for r in query_report.run( report, {"report_date": frappe.flags.current_date}) ["result"] if r[2] == "Sales Invoice" ]))[:random.randint(1, 5)]: jv = frappe.get_doc( get_payment_entry_against_invoice("Sales Invoice", si)) jv.posting_date = frappe.flags.current_date jv.cheque_no = random_string(6) jv.cheque_date = frappe.flags.current_date jv.insert() jv.submit() frappe.db.commit() if random.random() < 0.5: report = "Accounts Payable" for pi in list( set([ r[3] for r in query_report.run( report, {"report_date": frappe.flags.current_date}) ["result"] if r[2] == "Purchase Invoice" ]))[:random.randint(1, 5)]: jv = frappe.get_doc( get_payment_entry_against_invoice("Purchase Invoice", pi)) jv.posting_date = frappe.flags.current_date jv.cheque_no = random_string(6) jv.cheque_date = frappe.flags.current_date jv.insert() jv.submit() frappe.db.commit()
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)
def patched_run(*args, **kwargs): return run(*args, **kwargs)
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()
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()