def consulation_on_appointment(): for i in range(3): appointment = get_random("Patient Appointment") appointment = dataent.get_doc("Patient Appointment", appointment) encounter = set_encounter(appointment.patient, appointment.patient_sex, appointment.practitioner, appointment.department, appointment.appointment_date, i) encounter.appointment = appointment.name encounter.save(ignore_permissions=True)
def enroll_random_student(current_date): batch = ["Section-A", "Section-B"] random_student = get_random("Student Applicant", {"application_status": "Approved"}) if random_student: enrollment = enroll_student(random_student) enrollment.academic_year = get_random("Academic Year") enrollment.enrollment_date = current_date enrollment.student_batch_name = batch[weighted_choice([9, 3])] fee_schedule = get_fee_schedule(enrollment.program) for fee in fee_schedule: enrollment.append("fees", fee) enrolled_courses = get_course(enrollment.program) for course in enrolled_courses: enrollment.append("courses", course) enrollment.submit() dataent.db.commit() assign_student_group(enrollment.student, enrollment.student_name, enrollment.program, enrolled_courses, enrollment.student_batch_name)
def work(): dataent.set_user(dataent.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 = dataent.get_doc(make_sales_invoice(so)) si.posting_date = dataent.flags.current_date for d in si.get("items"): if not d.income_account: d.income_account = "Sales - {}".format(dataent.get_cached_value('Company', si.company, 'abbr')) si.insert() si.submit() dataent.db.commit() except dataent.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 = dataent.get_doc(make_purchase_invoice(pr)) pi.posting_date = dataent.flags.current_date pi.bill_no = random_string(6) pi.insert() pi.submit() dataent.db.commit() except dataent.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 = dataent.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 = dataent.get_doc(make_payment_entry(payment_request.name)) payment_entry.posting_date = dataent.flags.current_date payment_entry.submit() make_pos_invoice()
def get_service_unit_type(): service_unit_type = get_random("Healthcare Service Unit Type", filters={"inpatient_occupancy": 1}) if not service_unit_type: service_unit_type = dataent.new_doc("Healthcare Service Unit Type") service_unit_type.service_unit_type = "Test Service Unit Type Ip Occupancy" service_unit_type.inpatient_occupancy = 1 service_unit_type.save(ignore_permissions=True) return service_unit_type.name return service_unit_type
def make_subcontract(): from epaas.buying.doctype.purchase_order.purchase_order import make_rm_stock_entry item_code = get_random("Item", {"is_sub_contracted_item": 1}) if item_code: # make sub-contract PO po = dataent.new_doc("Purchase Order") po.is_subcontracted = "Yes" po.supplier = get_random("Supplier") po.transaction_date = dataent.flags.current_date # added po.schedule_date = dataent.utils.add_days(dataent.flags.current_date, 7) item_code = get_random("Item", {"is_sub_contracted_item": 1}) po.append( "items", { "item_code": item_code, "schedule_date": dataent.utils.add_days(dataent.flags.current_date, 7), "qty": random.randint(10, 30) }) po.set_missing_values() try: po.insert() except InvalidCurrency: return po.submit() # make material request for make_material_request(po.items[0].item_code, po.items[0].qty) # transfer material for sub-contract rm_items = get_rm_item(po.items[0], po.supplied_items[0]) stock_entry = dataent.get_doc( make_rm_stock_entry(po.name, json.dumps([rm_items]))) stock_entry.from_warehouse = "Stores - WPL" stock_entry.to_warehouse = "Supplier - WPL" stock_entry.insert()
def make_sales_order(): q = get_random("Quotation", {"status": "Submitted"}) if q: from epaas.selling.doctype.quotation.quotation import make_sales_order as mso so = dataent.get_doc(mso(q)) so.transaction_date = dataent.flags.current_date so.delivery_date = dataent.utils.add_days(dataent.flags.current_date, 10) so.insert() dataent.db.commit() so.submit() dataent.db.commit()
def make_appointment(): i = 1 while i <= 4: practitioner = get_random("Healthcare Practitioner") department = dataent.get_value("Healthcare Practitioner", practitioner, "department") patient = get_random("Patient") patient_sex = dataent.get_value("Patient", patient, "sex") appointment = dataent.new_doc("Patient Appointment") startDate = datetime.datetime.now() for x in random_date(startDate, 0): appointment_datetime = x appointment.appointment_datetime = appointment_datetime appointment.appointment_time = appointment_datetime appointment.appointment_date = appointment_datetime appointment.patient = patient appointment.patient_sex = patient_sex appointment.practitioner = practitioner appointment.department = department appointment.save(ignore_permissions=True) i += 1
def make_sales_invoice_for_timesheet(name): sales_invoice = make_sales_invoice(name) sales_invoice.customer = get_random("Customer") sales_invoice.append( 'items', { 'item_code': get_random("Item", { "has_variants": 0, "is_stock_item": 0, "is_fixed_asset": 0 }), 'qty': 1, 'rate': 1000 }) sales_invoice.flags.ignore_permissions = 1 sales_invoice.set_missing_values() sales_invoice.calculate_taxes_and_totals() sales_invoice.insert() sales_invoice.submit() dataent.db.commit()
def make_asset_purchase_entry(): asset_list = dataent.get_all("Asset", filters={"purchase_invoice": ["in", ("", None)]}, fields=["name", "item_code", "gross_purchase_amount", "company", "purchase_date"]) # make purchase invoice for asset in asset_list: pi = make_purchase_invoice(asset.name, asset.item_code, asset.gross_purchase_amount, asset.company, asset.purchase_date) pi.supplier = get_random("Supplier") pi.save() pi.submit() return asset_list
def make_student_applicants(): blood_group = ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"] male_names = [] female_names = [] file_path = get_json_path("Random Student Data") with open(file_path, "r") as open_file: random_student_data = json.loads(open_file.read()) count = 1 for d in random_student_data: if d.get('gender') == "Male": male_names.append(d.get('first_name').title()) if d.get('gender') == "Female": female_names.append(d.get('first_name').title()) for idx, d in enumerate(random_student_data): student_applicant = dataent.new_doc("Student Applicant") student_applicant.first_name = d.get('first_name').title() student_applicant.last_name = d.get('last_name').title() student_applicant.image = d.get('image') student_applicant.gender = d.get('gender') student_applicant.program = get_random("Program") student_applicant.blood_group = random.choice(blood_group) year = random.randint(1990, 1998) month = random.randint(1, 12) day = random.randint(1, 28) student_applicant.date_of_birth = datetime(year, month, day) student_applicant.mother_name = random.choice( female_names) + " " + d.get('last_name').title() student_applicant.father_name = random.choice( male_names) + " " + d.get('last_name').title() if student_applicant.gender == "Male": student_applicant.middle_name = random.choice(male_names) else: student_applicant.middle_name = random.choice(female_names) student_applicant.student_email_id = d.get('first_name') + "_" + \ student_applicant.middle_name + "_" + d.get('last_name') + "@example.com" if count < 5: student_applicant.insert() dataent.db.commit() else: student_applicant.submit() dataent.db.commit() count += 1
def make_timesheet_records(): employees = get_timesheet_based_salary_slip_employee() for e in employees: ts = make_timesheet(e.employee, simulate=True, billable=1, activity_type=get_random("Activity Type"), company=dataent.flags.company) dataent.db.commit() rand = random.random() if rand >= 0.3: make_salary_slip_for_timesheet(ts.name) rand = random.random() if rand >= 0.2: make_sales_invoice_for_timesheet(ts.name)
def setup_budget(): fiscal_years = dataent.get_all("Fiscal Year", order_by="year_start_date")[-2:] for fy in fiscal_years: budget = dataent.new_doc("Budget") budget.cost_center = get_random("Cost Center") budget.fiscal_year = fy.name budget.action_if_annual_budget_exceeded = "Warn" expense_ledger_count = dataent.db.count("Account", {"is_group": "0", "root_type": "Expense"}) add_random_children(budget, "accounts", rows=random.randint(10, expense_ledger_count), randomize = { "account": ("Account", {"is_group": "0", "root_type": "Expense"}) }, unique="account") for d in budget.accounts: d.budget_amount = random.randint(5, 100) * 10000 budget.save() budget.submit()
def test_fees(self): student = get_random("Student") fee = dataent.new_doc("Fees") fee.posting_date = nowdate() fee.due_date = nowdate() fee.student = student fee.receivable_account = "_Test Receivable - _TC" fee.income_account = "Sales - _TC" fee.cost_center = "_Test Cost Center - _TC" fee.company = "_Test Company" fee.extend("components", [ { "fees_category": "Tuition Fee", "amount": 40000 }, { "fees_category": "Transportation Fee", "amount": 10000 }]) fee.save() fee.submit() gl_entries = dataent.db.sql(""" select account, posting_date, party_type, party, cost_center, fiscal_year, voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center, company, credit, debit from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", ("Fees", fee.name), as_dict=True) if gl_entries[0].account == "_Test Receivable - _TC": self.assertEqual(gl_entries[0].debit, 50000) self.assertEqual(gl_entries[0].credit, 0) self.assertEqual(gl_entries[1].debit, 0) self.assertEqual(gl_entries[1].credit, 50000) else: self.assertEqual(gl_entries[0].credit, 50000) self.assertEqual(gl_entries[0].debit, 0) self.assertEqual(gl_entries[1].credit, 0) self.assertEqual(gl_entries[1].debit, 50000)
def add_suppliers(rfq): for i in range(2): supplier = get_random("Supplier") if supplier not in [d.supplier for d in rfq.get('suppliers')]: rfq.append("suppliers", {"supplier": supplier})
def make_fees(): for d in range(1, 10): random_fee = get_random("Fees", {"paid_amount": 0}) collect_fees( random_fee, dataent.db.get_value("Fees", random_fee, "outstanding_amount"))
def work(): dataent.set_user(dataent.db.get_global('demo_hr_user')) year, month = dataent.flags.current_date.strftime("%Y-%m").split("-") setup_department_approvers() mark_attendance() make_leave_application() # payroll entry if not dataent.db.sql( 'select name from `tabSalary Slip` where month(adddate(start_date, interval 1 month))=month(curdate())' ): # based on frequency payroll_entry = get_payroll_entry() payroll_entry.salary_slip_based_on_timesheet = 0 payroll_entry.save() payroll_entry.create_salary_slips() payroll_entry.submit_salary_slips() payroll_entry.make_accrual_jv_entry() payroll_entry.submit() # payroll_entry.make_journal_entry(reference_date=dataent.flags.current_date, # reference_number=random_string(10)) # based on timesheet payroll_entry = get_payroll_entry() payroll_entry.salary_slip_based_on_timesheet = 1 payroll_entry.save() payroll_entry.create_salary_slips() payroll_entry.submit_salary_slips() payroll_entry.make_accrual_jv_entry() payroll_entry.submit() # payroll_entry.make_journal_entry(reference_date=dataent.flags.current_date, # reference_number=random_string(10)) if dataent.db.get_global('demo_hr_user'): make_timesheet_records() #expense claim expense_claim = dataent.new_doc("Expense Claim") expense_claim.extend('expenses', get_expenses()) expense_claim.employee = get_random("Employee") expense_claim.company = dataent.flags.company expense_claim.payable_account = get_payable_account( expense_claim.company) expense_claim.posting_date = dataent.flags.current_date expense_claim.expense_approver = dataent.db.get_global('demo_hr_user') expense_claim.save() rand = random.random() if rand < 0.4: update_sanctioned_amount(expense_claim) expense_claim.approval_status = 'Approved' expense_claim.submit() if random.randint(0, 1): #make journal entry against expense claim je = dataent.get_doc( make_bank_entry("Expense Claim", expense_claim.name)) je.posting_date = dataent.flags.current_date je.cheque_no = random_string(10) je.cheque_date = dataent.flags.current_date je.flags.ignore_permissions = 1 je.submit()
def work(): dataent.set_user(dataent.db.get_global('demo_purchase_user')) 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 dataent.get_all('Material Request', filters={ 'material_request_type': 'Purchase', 'status': 'Open' }, limit=random.randint(1, 6)): if not dataent.get_all('Request for Quotation', filters={'material_request': mr.name}, limit=1): rfq = make_request_for_quotation(mr.name) rfq.transaction_date = dataent.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 dataent.get_all('Request for Quotation', filters={'status': 'Open'}, limit=random.randint(1, 6)): if not dataent.get_all('Supplier Quotation', filters={'request_for_quotation': rfq.name}, limit=1): rfq = dataent.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 = dataent.get_cached_value('Company', epaas.get_default_company(), "default_currency") party_account_currency = get_party_account_currency( "Supplier", supplier, epaas.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 epaas.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 = dataent.get_doc(make_supplier_quotation(row[0])) sq.transaction_date = dataent.flags.current_date sq.supplier = supplier sq.currency = party_account_currency or company_currency sq.conversion_rate = exchange_rate sq.insert() sq.submit() dataent.db.commit() # make purchase orders if random.random() < 0.5: from epaas.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 = dataent.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 = dataent.flags.current_date po.insert() po.submit() except Exception: pass else: dataent.db.commit() if random.random() < 0.5: make_subcontract()
def make_lab_test(): practitioner = get_random("Healthcare Practitioner") patient = get_random("Patient") patient_sex = dataent.get_value("Patient", patient, "sex") template = get_random("Lab Test Template") set_lab_test(patient, patient_sex, practitioner, template)