def test_fee_validity(self): patient = get_random("Patient") physician = get_random("Physician") if not patient: patient = frappe.new_doc("Patient") patient.patient_name = "Test Patient" patient.sex = "Male" patient.save(ignore_permissions = True) patient = patient.name if not physician: physician = frappe.new_doc("Physician") physician.first_name= "Amit Jain" physician.save(ignore_permissions = True) physician = physician.name frappe.db.set_value("Healthcare Settings", None, "max_visit", 2) frappe.db.set_value("Healthcare Settings", None, "valid_days", 7) appointment = create_appointment(patient, physician, nowdate()) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None) create_invoice(frappe.defaults.get_global_default("company"), physician, patient, appointment.name, appointment.appointment_date) appointment = create_appointment(patient, physician, add_days(nowdate(), 4)) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertTrue(invoice) appointment = create_appointment(patient, physician, add_days(nowdate(), 5)) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None) appointment = create_appointment(patient, physician, add_days(nowdate(), 10)) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None)
def test_fee_validity(self): patient = get_random("Patient") physician = get_random("Physician") if not patient: patient = frappe.new_doc("Patient") patient.patient_name = "Test Patient" patient.sex = "Male" patient.save(ignore_permissions=True) patient = patient.name if not physician: physician = frappe.new_doc("Physician") physician.first_name = "Amit Jain" physician.save(ignore_permissions=True) physician = physician.name frappe.db.set_value("Healthcare Settings", None, "max_visit", 2) frappe.db.set_value("Healthcare Settings", None, "valid_days", 7) appointment = create_appointment(patient, physician, nowdate()) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None) create_invoice(frappe.defaults.get_global_default("company"), physician, patient, appointment.name, appointment.appointment_date) appointment = create_appointment(patient, physician, add_days(nowdate(), 4)) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertTrue(invoice) appointment = create_appointment(patient, physician, add_days(nowdate(), 5)) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None) appointment = create_appointment(patient, physician, add_days(nowdate(), 10)) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None)
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": 1}), "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 create_test_timesheets(cls): timesheet1 = frappe.new_doc("Timesheet") timesheet1.employee = cls.test_emp1 timesheet1.company = '_Test Company' timesheet1.append( "time_logs", { "activity_type": get_random("Activity Type"), "hours": 5, "is_billable": 1, "from_time": '2021-04-01 13:30:00.000000', "to_time": '2021-04-01 18:30:00.000000' }) timesheet1.save() timesheet1.submit() timesheet2 = frappe.new_doc("Timesheet") timesheet2.employee = cls.test_emp2 timesheet2.company = '_Test Company' timesheet2.append( "time_logs", { "activity_type": get_random("Activity Type"), "hours": 10, "is_billable": 0, "from_time": '2021-04-01 13:30:00.000000', "to_time": '2021-04-01 23:30:00.000000', "project": cls.test_project.name }) timesheet2.save() timesheet2.submit()
def work(): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) if random.random() < 0.5: for i in xrange(random.randint(1, 7)): make_opportunity() if random.random() < 0.5: for i in xrange(random.randint(1, 3)): make_quotation() # lost quotations / inquiries if random.random() < 0.3: for i in xrange(random.randint(1, 3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in xrange(random.randint(1, 3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') if random.random() < 0.3: for i in xrange(random.randint(1, 3)): make_sales_order()
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": 1, "ifnull(has_variants,0)": "0"}) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def work(): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) if random.random() < 0.5: for i in xrange(random.randint(1,7)): make_opportunity() if random.random() < 0.5: for i in xrange(random.randint(1,3)): make_quotation() # lost quotations / inquiries if random.random() < 0.3: for i in xrange(random.randint(1,3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in xrange(random.randint(1,3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') if random.random() < 0.3: for i in xrange(random.randint(1,3)): make_sales_order()
def make_subcontract(): from erpnext.buying.doctype.purchase_order.purchase_order import make_stock_entry item_code = get_random("Item", {"is_sub_contracted_item": 1}) if item_code: # make sub-contract PO po = frappe.new_doc("Purchase Order") po.is_subcontracted = "Yes" po.supplier = get_random("Supplier") item_code = get_random("Item", {"is_sub_contracted_item": 1}) po.append("items", { "item_code": item_code, "schedule_date": frappe.utils.add_days(frappe.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 stock_entry = frappe.get_doc(make_stock_entry(po.name, po.items[0].item_code)) stock_entry.from_warehouse = "Stores - WPL" stock_entry.to_warehouse = "Supplier - WPL" stock_entry.insert()
def make_subcontract(): from erpnext.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 = frappe.new_doc("Purchase Order") po.is_subcontracted = "Yes" po.supplier = get_random("Supplier") po.transaction_date = frappe.flags.current_date # added po.schedule_date = frappe.utils.add_days(frappe.flags.current_date, 7) item_code = get_random("Item", {"is_sub_contracted_item": 1}) po.append("items", { "item_code": item_code, "schedule_date": frappe.utils.add_days(frappe.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 = frappe.get_doc(make_rm_stock_entry(po.name, json.dumps([rm_items]))) stock_entry.from_warehouse = _("Stores") + " - WP" stock_entry.to_warehouse = _("Supplier") + " - WP" stock_entry.insert()
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": 1}), "schedule_date": frappe.utils.add_days(current_date, 7), "qty": 20 }) po.set_missing_values() try: po.insert() except InvalidCurrency: return 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 work(domain="Manufacturing"): frappe.set_user(frappe.db.get_global("demo_sales_user_2")) for i in range(random.randint(1, 7)): if random.random() < 0.5: make_opportunity(domain) for i in range(random.randint(1, 3)): if random.random() < 0.5: make_quotation(domain) try: lost_reason = frappe.get_doc({ "doctype": "Opportunity Lost Reason", "lost_reason": "Did not ask" }) lost_reason.save(ignore_permissions=True) except frappe.exceptions.DuplicateEntryError: pass # lost quotations / inquiries if random.random() < 0.3: for i in range(random.randint(1, 3)): quotation = get_random("Quotation", doc=True) if quotation and quotation.status == "Submitted": quotation.declare_order_lost([{"lost_reason": "Did not ask"}]) for i in range(random.randint(1, 3)): opportunity = get_random("Opportunity", doc=True) if opportunity and opportunity.status in ("Open", "Replied"): opportunity.declare_enquiry_lost([{ "lost_reason": "Did not ask" }]) for i in range(random.randint(1, 3)): if random.random() < 0.6: make_sales_order() if random.random() < 0.5: # make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) try: if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.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() except Exception: pass
def make_quotation(domain): # get open opportunites opportunity = get_random("Opportunity", { "status": "Open", "with_items": 1 }) 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 # get customer, currency and exchange_rate customer = get_random("Customer") company_currency = frappe.get_cached_value( 'Company', erpnext.get_default_company(), "default_currency") party_account_currency = get_party_account_currency( "Customer", customer, 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_selling") qtn = frappe.get_doc({ "creation": frappe.flags.current_date, "doctype": "Quotation", "quotation_to": "Customer", "party_name": customer, "currency": party_account_currency or company_currency, "conversion_rate": exchange_rate, "order_type": "Sales", "transaction_date": frappe.flags.current_date, }) add_random_children(qtn, "items", rows=3, randomize={ "qty": (1, 5), "item_code": ("Item", { "has_variants": "0", "is_fixed_asset": 0, "domain": domain }) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def make_consulation(): for i in range(3): practitioner = get_random("Healthcare Practitioner") department = frappe.get_value("Healthcare Practitioner", practitioner, "department") patient = get_random("Patient") patient_sex = frappe.get_value("Patient", patient, "sex") encounter = set_encounter(patient, patient_sex, practitioner, department, getdate(), i) encounter.save(ignore_permissions=True)
def make_consulation(): for i in xrange(3): physician = get_random("Physician") department = frappe.get_value("Physician", physician, "department") patient = get_random("Patient") patient_sex = frappe.get_value("Patient", patient, "sex") consultation = set_consultation(patient, patient_sex, physician, department, getdate(), i) consultation.save(ignore_permissions=True)
def make_timesheet_for_projects(current_date ): for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}): employee = get_random("Employee") ts = make_timesheet(employee, simulate = True, billable = 1, company = erpnext.get_default_company(), activity_type=get_random("Activity Type"), project=data.project, task =data.name) if flt(ts.total_billable_amount) > 0.0: make_sales_invoice_for_timesheet(ts.name) frappe.db.commit()
def make_assessment_plan(date): for d in range(1,4): random_group = get_random("Student Group", {"group_based_on": "Course"}, True) doc = frappe.new_doc("Assessment Plan") doc.student_group = random_group.name doc.course = random_group.course doc.assessment_group = get_random("Assessment Group", {"is_group": 0, "parent": "2017-18 (Semester 2)"}) doc.grading_scale = get_random("Grading Scale") doc.maximum_assessment_score = 100
def make_timesheet_for_projects(current_date ): for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}): employee = get_random("Employee") if frappe.db.get_value('Salary Structure', {'employee': employee}, 'salary_slip_based_on_timesheet'): ts = make_timesheet(employee, simulate = True, billable = 1, activity_type=get_random("Activity Type"), project=data.project, task =data.name) if flt(ts.total_billing_amount) > 0.0: make_sales_invoice_for_timesheet(ts.name) frappe.db.commit()
def enroll_random_student(current_date): 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.save() enrollment.submit() assign_student_group(enrollment.student, enrollment.program)
def test_fee_validity(self): frappe.db.sql("""delete from `tabPatient Appointment`""") frappe.db.sql("""delete from `tabFee Validity`""") patient = get_random("Patient") practitioner = get_random("Healthcare Practitioner") department = get_random("Medical Department") if not patient: patient = frappe.new_doc("Patient") patient.patient_name = "_Test Patient" patient.sex = "Male" patient.save(ignore_permissions=True) patient = patient.name if not department: medical_department = frappe.new_doc("Medical Department") medical_department.department = "_Test Medical Department" medical_department.save(ignore_permissions=True) department = medical_department.name if not practitioner: practitioner = frappe.new_doc("Healthcare Practitioner") practitioner.first_name = "_Test Healthcare Practitioner" practitioner.department = department practitioner.save(ignore_permissions=True) practitioner = practitioner.name frappe.db.set_value("Healthcare Settings", None, "max_visit", 2) frappe.db.set_value("Healthcare Settings", None, "valid_days", 7) appointment = create_appointment(patient, practitioner, nowdate(), department) invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertEqual(invoiced, 0) invoice_appointment(appointment) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4), department) invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertTrue(invoiced) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 5), department) invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertEqual(invoiced, 0) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 10), department) invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertEqual(invoiced, 0)
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 # get customer, currency and exchange_rate customer = get_random("Customer") company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency") party_account_currency = get_party_account_currency( "Customer", customer, "Wind Power LLC") if company_currency == party_account_currency: exchange_rate = 1 else: exchange_rate = get_exchange_rate(party_account_currency, company_currency) qtn = frappe.get_doc({ "creation": current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": customer, "currency": party_account_currency or company_currency, "conversion_rate": exchange_rate, "order_type": "Sales", "transaction_date": current_date, }) add_random_children(qtn, "items", rows=3, randomize={ "qty": (1, 5), "item_code": ("Item", { "is_sales_item": 1, "has_variants": "0" }) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def append_drug_rx(encounter): i = 1 while i <= 3: drug = get_random("Item", filters={"item_group":"Drug"}) drug = frappe.get_doc("Item", drug) drug_rx = encounter.append("drug_prescription") drug_rx.drug_code = drug.item_code drug_rx.drug_name = drug.item_name drug_rx.dosage = get_random("Prescription Dosage") drug_rx.period = get_random("Prescription Duration") i += 1 return encounter
def enroll_random_student(current_date): 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 fee_schedule = get_fee_schedule(enrollment.program) for fee in fee_schedule: enrollment.append("fees", fee) enrollment.submit() frappe.db.commit() assign_student_group(enrollment.student, enrollment.program)
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() frappe.db.commit()
def make_timesheet_for_projects(current_date): for data in frappe.get_all("Task", ["name", "project"], { "status": "Open", "exp_end_date": ("<", current_date) }): employee = get_random("Employee") if frappe.db.get_value('Salary Structure', {'employee': employee}, 'salary_slip_based_on_timesheet'): make_timesheet(employee, simulate=True, billable=1, activity_type=get_random("Activity Type"), project=data.project, task=data.name)
def make_quotation(): # get open opportunites opportunity = get_random("Opportunity", {"status": "Open", "with_items": 1}) 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 # get customer, currency and exchange_rate customer = get_random("Customer") company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency") party_account_currency = get_party_account_currency("Customer", customer, "Wind Power LLC") if company_currency == party_account_currency: exchange_rate = 1 else: exchange_rate = get_exchange_rate(party_account_currency, company_currency) qtn = frappe.get_doc( { "creation": frappe.flags.current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": customer, "currency": party_account_currency or company_currency, "conversion_rate": exchange_rate, "order_type": "Sales", "transaction_date": frappe.flags.current_date, } ) add_random_children( qtn, "items", rows=3, randomize={"qty": (1, 5), "item_code": ("Item", {"has_variants": "0", "is_fixed_asset": 0})}, unique="item_code", ) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def test_fee_validity(self): patient = get_random("Patient") physician = get_random("Physician") department = get_random("Medical Department") if not patient: patient = frappe.new_doc("Patient") patient.patient_name = "Test Patient" patient.sex = "Male" patient.save(ignore_permissions=True) patient = patient.name if not department: medical_department = frappe.new_doc("Medical Department") medical_department.department = "Test Medical Department" medical_department.save(ignore_permissions=True) department = medical_department.name if not physician: physician = frappe.new_doc("Physician") physician.first_name = "Amit Jain" physician.department = department physician.save(ignore_permissions=True) physician = physician.name frappe.db.set_value("Healthcare Settings", None, "max_visit", 2) frappe.db.set_value("Healthcare Settings", None, "valid_days", 7) appointment = create_appointment(patient, physician, nowdate(), department) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None) invoice_appointment(appointment) appointment = create_appointment(patient, physician, add_days(nowdate(), 4), department) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertTrue(invoice) appointment = create_appointment(patient, physician, add_days(nowdate(), 5), department) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None) appointment = create_appointment(patient, physician, add_days(nowdate(), 10), department) invoice = frappe.db.get_value("Patient Appointment", appointment.name, "sales_invoice") self.assertEqual(invoice, None)
def work(domain="Manufacturing"): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) for i in range(random.randint(1, 7)): if random.random() < 0.5: make_opportunity(domain) for i in range(random.randint(1, 3)): if random.random() < 0.5: make_quotation(domain) # lost quotations / inquiries if random.random() < 0.3: for i in range(random.randint(1, 3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in range(random.randint(1, 3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') for i in range(random.randint(1, 3)): if random.random() < 0.6: make_sales_order() if random.random() < 0.5: #make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) try: if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.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() except Exception: pass
def append_test_rx(encounter): i = 1 while i <= 2: test_rx = encounter.append("test_prescription") test_rx.test_code = get_random("Lab Test Template") i += 1 return encounter
def get_healthcare_service_unit(): service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1}) if not service_unit: service_unit = frappe.new_doc("Healthcare Service Unit") service_unit.healthcare_service_unit_name = "Test Service Unit Ip Occupancy" service_unit.service_unit_type = get_service_unit_type() service_unit.inpatient_occupancy = 1 service_unit.occupancy_status = "Vacant" service_unit.is_group = 0 service_unit_parent_name = frappe.db.exists({ "doctype": "Healthcare Service Unit", "healthcare_service_unit_name": "All Healthcare Service Units", "is_group": 1 }) if not service_unit_parent_name: parent_service_unit = frappe.new_doc("Healthcare Service Unit") parent_service_unit.healthcare_service_unit_name = "All Healthcare Service Units" parent_service_unit.is_group = 1 parent_service_unit.save(ignore_permissions=True) service_unit.parent_healthcare_service_unit = parent_service_unit.name else: service_unit.parent_healthcare_service_unit = service_unit_parent_name[ 0][0] service_unit.save(ignore_permissions=True) return service_unit.name return service_unit
def append_test_rx(consultation): i = 1 while i <= 2: test_rx = consultation.append("test_prescription") test_rx.test_code = get_random("Lab Test Template") i += 1 return consultation
def work(): frappe.set_user(frappe.db.get_global('demo_hr_user')) year, month = frappe.flags.current_date.strftime("%Y-%m").split("-") mark_attendance() make_leave_application() # payroll entry if not frappe.db.sql('select name from `tabSalary Slip` where month(adddate(start_date, interval 1 month))=month(curdate())'): # process payroll for previous month payroll_entry = frappe.new_doc("Payroll Entry") payroll_entry.company = frappe.flags.company payroll_entry.payroll_frequency = 'Monthly' # select a posting date from the previous month payroll_entry.posting_date = get_last_day(getdate(frappe.flags.current_date) - datetime.timedelta(days=10)) payroll_entry.payment_account = frappe.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name") payroll_entry.set_start_end_dates() # based on frequency payroll_entry.salary_slip_based_on_timesheet = 0 payroll_entry.create_salary_slips() payroll_entry.submit_salary_slips() payroll_entry.make_accrual_jv_entry() # payroll_entry.make_journal_entry(reference_date=frappe.flags.current_date, # reference_number=random_string(10)) payroll_entry.salary_slip_based_on_timesheet = 1 payroll_entry.create_salary_slips() payroll_entry.submit_salary_slips() payroll_entry.make_accrual_jv_entry() # payroll_entry.make_journal_entry(reference_date=frappe.flags.current_date, # reference_number=random_string(10)) if frappe.db.get_global('demo_hr_user'): make_timesheet_records() #expense claim expense_claim = frappe.new_doc("Expense Claim") expense_claim.extend('expenses', get_expenses()) expense_claim.employee = get_random("Employee") expense_claim.company = frappe.flags.company expense_claim.payable_account = get_payable_account(expense_claim.company) expense_claim.posting_date = frappe.flags.current_date expense_claim.insert() rand = random.random() if rand < 0.4: update_sanctioned_amount(expense_claim) expense_claim.submit() if random.randint(0, 1): #make journal entry against expense claim je = frappe.get_doc(make_bank_entry("Expense Claim", expense_claim.name)) je.posting_date = frappe.flags.current_date je.cheque_no = random_string(10) je.cheque_date = frappe.flags.current_date je.flags.ignore_permissions = 1 je.submit()
def consulation_on_appointment(): for i in range(3): appointment = get_random("Patient Appointment") appointment = frappe.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 work(): frappe.set_user(frappe.db.get_global('demo_hr_user')) frappe.set_user_lang(frappe.db.get_global('demo_hr_user')) year, month = frappe.flags.current_date.strftime("%Y-%m").split("-") setup_department_approvers() mark_attendance() make_leave_application() # payroll entry if not frappe.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=frappe.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=frappe.flags.current_date, # reference_number=random_string(10)) if frappe.db.get_global('demo_hr_user'): make_timesheet_records() #expense claim expense_claim = frappe.new_doc("Expense Claim") expense_claim.extend('expenses', get_expenses()) expense_claim.employee = get_random("Employee") expense_claim.company = frappe.flags.company expense_claim.payable_account = get_payable_account(expense_claim.company) expense_claim.posting_date = frappe.flags.current_date expense_claim.expense_approver = frappe.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 = frappe.get_doc(make_bank_entry("Expense Claim", expense_claim.name)) je.posting_date = frappe.flags.current_date je.cheque_no = random_string(10) je.cheque_date = frappe.flags.current_date je.flags.ignore_permissions = 1 je.submit()
def consulation_on_appointment(): for i in xrange(3): appointment = get_random("Patient Appointment") appointment = frappe.get_doc("Patient Appointment",appointment) consultation = set_consultation(appointment.patient, appointment.patient_sex, appointment.physician, appointment.department, appointment.appointment_date, i) consultation.appointment = appointment.name consultation.save(ignore_permissions=True)
def setup_budget(): fiscal_years = frappe.get_all("Fiscal Year", order_by="year_start_date")[-2:] for fy in fiscal_years: budget = frappe.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 = frappe.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 approve_random_student_applicant(): random_student = get_random("Student Applicant", {"application_status": "Applied"}) if random_student: student_application = frappe.get_doc("Student Applicant", random_student) status = ["Approved", "Rejected"] student_application.application_status = status[weighted_choice([9,3])] student_application.save()
def make_salary_structure(salary_structure, payroll_frequency, employee=None, dont_submit=False, other_details=None, test_tax=False, company=None): if test_tax: frappe.db.sql("""delete from `tabSalary Structure` where name=%s""",(salary_structure)) if not frappe.db.exists('Salary Structure', salary_structure): details = { "doctype": "Salary Structure", "name": salary_structure, "company": company or erpnext.get_default_company(), "earnings": make_earning_salary_component(test_tax=test_tax, company_list=["_Test Company"]), "deductions": make_deduction_salary_component(test_tax=test_tax, company_list=["_Test Company"]), "payroll_frequency": payroll_frequency, "payment_account": get_random("Account") } if other_details and isinstance(other_details, dict): details.update(other_details) salary_structure_doc = frappe.get_doc(details) salary_structure_doc.insert() if not dont_submit: salary_structure_doc.submit() else: salary_structure_doc = frappe.get_doc("Salary Structure", salary_structure) if employee and not frappe.db.get_value("Salary Structure Assignment", {'employee':employee, 'docstatus': 1}) and salary_structure_doc.docstatus==1: create_salary_structure_assignment(employee, salary_structure, company=company) return salary_structure_doc
def make_course_schedule(start_date, end_date): for d in frappe.db.get_list("Student Group"): cs = frappe.new_doc("Scheduling Tool") cs.student_group = d.name cs.room = get_random("Room") cs.instructor = get_random("Instructor") cs.course_start_date = cstr(start_date) cs.course_end_date = cstr(end_date) day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] for x in xrange(3): random_day = random.choice(day) cs.day = random_day cs.from_time = timedelta(hours=(random.randrange(7, 17,1))) cs.to_time = cs.from_time + timedelta(hours=1) cs.schedule_course() day.remove(random_day)
def get_healthcare_service_unit(): service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1}) if not service_unit: service_unit = frappe.new_doc("Healthcare Service Unit") service_unit.healthcare_service_unit_name = "Test Service Unit Ip Occupancy" service_unit.service_unit_type = get_service_unit_type() service_unit.inpatient_occupancy = 1 service_unit.occupancy_status = "Vacant" service_unit.is_group = 0 service_unit_parent_name = frappe.db.exists({ "doctype": "Healthcare Service Unit", "healthcare_service_unit_name": "All Healthcare Service Units", "is_group": 1 }) if not service_unit_parent_name: parent_service_unit = frappe.new_doc("Healthcare Service Unit") parent_service_unit.healthcare_service_unit_name = "All Healthcare Service Units" parent_service_unit.is_group = 1 parent_service_unit.save(ignore_permissions = True) service_unit.parent_healthcare_service_unit = parent_service_unit.name else: service_unit.parent_healthcare_service_unit = service_unit_parent_name[0][0] service_unit.save(ignore_permissions = True) return service_unit.name return service_unit
def make_salary_structure(salary_structure, payroll_frequency, employee=None, dont_submit=False, other_details=None, test_tax=False): if test_tax: frappe.db.sql("""delete from `tabSalary Structure` where name=%s""",(salary_structure)) if not frappe.db.exists('Salary Structure', salary_structure): details = { "doctype": "Salary Structure", "name": salary_structure, "company": erpnext.get_default_company(), "earnings": make_earning_salary_component(test_tax=test_tax), "deductions": make_deduction_salary_component(test_tax=test_tax), "payroll_frequency": payroll_frequency, "payment_account": get_random("Account") } if other_details and isinstance(other_details, dict): details.update(other_details) salary_structure_doc = frappe.get_doc(details).insert() if not dont_submit: salary_structure_doc.submit() else: salary_structure_doc = frappe.get_doc("Salary Structure", salary_structure) if employee and not frappe.db.get_value("Salary Structure Assignment", {'employee':employee, 'docstatus': 1}) and salary_structure_doc.docstatus==1: create_salary_structure_assignment(employee, salary_structure) return salary_structure_doc
def make_opportunity(domain): b = frappe.get_doc({ "doctype": "Opportunity", "opportunity_from": "Customer", "customer": get_random("Customer"), "opportunity_type": "Sales", "with_items": 1, "transaction_date": frappe.flags.current_date, }) add_random_children(b, "items", rows=4, randomize={ "qty": (1, 5), "item_code": ("Item", { "has_variants": 0, "is_fixed_asset": 0, "domain": domain }) }, unique="item_code") b.insert() frappe.db.commit()
def lab_test_on_encounter(): i = 1 while i <= 2: test_rx = get_random("Lab Prescription", filters={'test_created': 0}) test_rx = frappe.get_doc("Lab Prescription", test_rx) encounter = frappe.get_doc("Patient Encounter", test_rx.parent) set_lab_test(encounter.patient, encounter.patient_sex, encounter.practitioner, test_rx.test_code, test_rx.name) i += 1
def sell_an_asset(): asset = get_random_asset() si = make_sales_invoice(asset.name, asset.item_code, "Wind Power LLC") si.customer = get_random("Customer") si.get("items")[0].rate = asset.value_after_depreciation * 0.8 \ if asset.value_after_depreciation else asset.gross_purchase_amount * 0.9 si.save() si.submit()
def lab_test_on_consultation(): i = 1 while i <= 2: test_rx = get_random("Lab Prescription", filters={'test_created': 0}) test_rx = frappe.get_doc("Lab Prescription", test_rx) consultation = frappe.get_doc("Consultation", test_rx.parent) set_lab_test(consultation.patient, consultation.patient_sex, consultation.physician, test_rx.test_code, test_rx.name) i += 1
def get_patient(): patient = get_random("Patient") if not patient: patient = frappe.new_doc("Patient") patient.patient_name = "Test Patient" patient.sex = "Male" patient.save(ignore_permissions=True) return patient.name return patient
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() frappe.db.commit() assign_student_group(enrollment.student, enrollment.student_name, enrollment.program, enrolled_courses, enrollment.student_batch_name)
def work(): frappe.set_user(frappe.db.get_global("demo_sales_user_2")) if random.random() < 0.5: for i in xrange(random.randint(1, 7)): make_opportunity() if random.random() < 0.5: for i in xrange(random.randint(1, 3)): make_quotation() # lost quotations / inquiries if random.random() < 0.3: for i in xrange(random.randint(1, 3)): quotation = get_random("Quotation", doc=True) if quotation and quotation.status == "Submitted": quotation.declare_order_lost("Did not ask") for i in xrange(random.randint(1, 3)): opportunity = get_random("Opportunity", doc=True) if opportunity and opportunity.status in ("Open", "Replied"): opportunity.declare_enquiry_lost("Did not ask") if random.random() < 0.3: for i in xrange(random.randint(1, 3)): make_sales_order() if random.random() < 0.1: # make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.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()
def work(): frappe.set_user(frappe.db.get_global('demo_hr_user')) year, month = frappe.flags.current_date.strftime("%Y-%m").split("-") mark_attendance() make_leave_application() # process payroll if not frappe.db.get_value("Salary Slip", {"month": month, "fiscal_year": year}): process_payroll = frappe.get_doc("Process Payroll", "Process Payroll") process_payroll.company = frappe.flags.company process_payroll.month = month process_payroll.fiscal_year = year process_payroll.create_sal_slip() process_payroll.submit_salary_slip() r = process_payroll.make_journal_entry(frappe.get_value('Account', {'account_name': 'Salary'})) journal_entry = frappe.get_doc(r) journal_entry.cheque_no = random_string(10) journal_entry.cheque_date = frappe.flags.current_date journal_entry.posting_date = frappe.flags.current_date journal_entry.insert() journal_entry.submit() if frappe.db.get_global('demo_hr_user'): make_timesheet_records() #expense claim expense_claim = frappe.new_doc("Expense Claim") expense_claim.extend('expenses', get_expenses()) expense_claim.employee = get_random("Employee") expense_claim.company = frappe.flags.company expense_claim.posting_date = frappe.flags.current_date expense_claim.exp_approver = filter((lambda x: x[0] != 'Administrator'), get_expense_approver(None, '', None, 0, 20, None))[0][0] expense_claim.insert() rand = random.random() if rand < 0.4: expense_claim.approval_status = "Approved" update_sanctioned_amount(expense_claim) expense_claim.submit() if random.randint(0, 1): #make journal entry against expense claim je = frappe.get_doc(make_bank_entry(expense_claim.name)) je.posting_date = frappe.flags.current_date je.cheque_no = random_string(10) je.cheque_date = frappe.flags.current_date je.flags.ignore_permissions = 1 je.submit() elif rand < 0.2: expense_claim.approval_status = "Rejected" expense_claim.submit()