def make_subcontract(current_date): from erpnext.buying.doctype.purchase_order.purchase_order import make_stock_entry # make sub-contract PO po = frappe.new_doc("Purchase Order") po.is_subcontracted = "Yes" po.supplier = get_random("Supplier") po.append("items", { "item_code": get_random("Item", {"is_sub_contracted_item": "Yes"}), "schedule_date": frappe.utils.add_days(current_date, 7), "qty": 20 }) po.set_missing_values() po.insert() po.submit() # make material request for make_material_request(current_date, po.items[0].item_code, po.items[0].qty) # transfer material for sub-contract stock_entry = frappe.get_doc(make_stock_entry(po.name, po.items[0].item_code)) stock_entry.from_warehouse = "Stores - WP" stock_entry.to_warehouse = "Supplier - WP" stock_entry.insert()
def make_quotation(current_date): # get open opportunites opportunity = get_random("Opportunity", {"status": "Open"}) if opportunity: from erpnext.crm.doctype.opportunity.opportunity import make_quotation qtn = frappe.get_doc(make_quotation(opportunity)) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit() else: # make new directly qtn = frappe.get_doc({ "creation": current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": get_random("Customer"), "order_type": "Sales", "transaction_date": current_date, "fiscal_year": cstr(current_date.year) }) add_random_children(qtn, "items", rows=3, randomize = { "qty": (1, 5), "item_code": ("Item", {"is_sales_item": "Yes", "ifnull(has_variants,0)": "0"}) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def make_sales_order(current_date): q = get_random("Quotation", {"status": "Submitted"}) if q: from erpnext.selling.doctype.quotation.quotation import make_sales_order so = frappe.get_doc(make_sales_order(q)) so.transaction_date = current_date so.delivery_date = frappe.utils.add_days(current_date, 10) so.fiscal_year = cstr(current_date.year) so.insert() frappe.db.commit() so.submit() frappe.db.commit()
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_opportunity(current_date): b = frappe.get_doc({ "creation": current_date, "doctype": "Opportunity", "enquiry_from": "Customer", "customer": get_random("Customer"), "enquiry_type": "Sales", "transaction_date": current_date, "fiscal_year": cstr(current_date.year) }) add_random_children(b, "items", rows=4, randomize = { "qty": (1, 5), "item_code": ("Item", {"is_sales_item": "Yes", "ifnull(has_variants,0)": "0"}) }, unique="item_code") b.insert() frappe.db.commit()
def make_message(current_date): from_user = ["*****@*****.**", "Administrator"][random.randint(0, 1)] to_user = get_random("User") comments = [ "Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name.", "Birds taught me to sing, when they took me to their king, first I had to fly, in the sky so high so high, so high so high so high, so - if you want to sing this way, think of what you'd like to say, add a tune and you will see, just how easy it can be.", "Children of the sun, see your time has just begun, searching for your ways, through adventures every day. ", "Every day and night, with the condor in flight, with all your friends in tow, you search for the Cities of Gold.", "80 days around the world, we'll find a pot of gold just sitting where the rainbow's ending. ", "Time - we'll fight against the time, and we'll fly on the white wings of the wind. ", "Knight Rider, a shadowy flight into the dangerous world of a man who does not exist. Michael Knight, a young loner on a crusade to champion the cause of the innocent, the helpless in a world of criminals who operate above the law.", "Ulysses, Ulysses - Soaring through all the galaxies. In search of Earth, flying in to the night. Ulysses, Ulysses - Fighting evil and tyranny, with all his power, and with all of his might. Ulysses - no-one else can do the things you do. Ulysses - like a bolt of thunder from the blue. Ulysses - always fighting all the evil forces bringing peace and justice to all.", "One for all and all for one, Muskehounds are always ready. One for all and all for one, helping everybody. One for all and all for one, it's a pretty story. " ] d = frappe.new_doc('Comment') d.owner = from_user d.comment_docname = to_user d.comment_doctype = 'Message' d.comment = comments[random.randint(0, len(comments) - 1)] d.insert(ignore_permissions=True)