def process_master_data(self): self.set_status("Processing Master Data") frappe.enqueue_doc(self.doctype, self.name, "_process_master_data", queue="long", timeout=3600)
def import_master_data(self): self.set_status("Importing Master Data") frappe.enqueue_doc(self.doctype, self.name, "_import_master_data", queue="long", timeout=3600)
def process_day_book_data(self): self.set_status("Processing Day Book Data") frappe.enqueue_doc(self.doctype, self.name, "_process_day_book_data", queue="long", timeout=3600)
def import_day_book_data(self): self.set_status("Importing Day Book Data") frappe.enqueue_doc(self.doctype, self.name, "_import_day_book_data", queue="long", timeout=3600)
def process_file_data(self): self.db_set("status", "Processing File Data", notify=True, commit=True) frappe.enqueue_doc(self.doctype, self.name, "import_xml_data", queue="long", timeout=3600)
def process_file_data(self): self.status = "Processing File Data" self.save() frappe.enqueue_doc(self.doctype, self.name, "import_xml_data", queue="long", timeout=3600)
def import_tasks(self, tasks_to_import, comments_to_import): frappe.enqueue_doc(self.doctype, self.name, "_import_tasks", queue="long", timeout=3600, tasks_to_import=tasks_to_import, comments_to_import=comments_to_import)
def refresh_scorecards(): scorecards = frappe.db.sql(""" SELECT sc.name FROM `tabSupplier Scorecard` sc""", {}, as_dict=1) for sc in scorecards: frappe.enqueue_doc("Supplier Scorecard", sc.name, "make_all_scorecards", queue="long", timeout=3600)
def after_insert(self): personal_data = get_user_data(self.user) frappe.enqueue_doc(self.doctype, self.name, 'generate_file_and_send_mail', queue='short', personal_data=personal_data, now=frappe.flags.in_test)
def run_task(self): if self.status in ["Error", "Finished", "Partial", "Running"]: return device_list = self.get("device_list") for device in device_list: frappe.enqueue_doc('IOT Batch TaskDevice', device.name, 'run_batch_script') frappe.db.set_value("IOT Batch Task", self.name, "status", "Running")
def _import_day_book_data(self): def create_fiscal_years(vouchers): from frappe.utils.data import add_years, getdate earliest_date = getdate(min(voucher["posting_date"] for voucher in vouchers)) oldest_year = frappe.get_all("Fiscal Year", fields=["year_start_date", "year_end_date"], order_by="year_start_date")[0] while earliest_date < oldest_year.year_start_date: new_year = frappe.get_doc({"doctype": "Fiscal Year"}) new_year.year_start_date = add_years(oldest_year.year_start_date, -1) new_year.year_end_date = add_years(oldest_year.year_end_date, -1) if new_year.year_start_date.year == new_year.year_end_date.year: new_year.year = new_year.year_start_date.year else: new_year.year = "{}-{}".format(new_year.year_start_date.year, new_year.year_end_date.year) new_year.save() oldest_year = new_year def create_custom_fields(doctypes): for doctype in doctypes: df = { "fieldtype": "Data", "fieldname": "tally_guid", "read_only": 1, "label": "Tally GUID" } create_custom_field(doctype, df) def create_price_list(): frappe.get_doc({ "doctype": "Price List", "price_list_name": "Tally Price List", "selling": 1, "buying": 1, "enabled": 1, "currency": "INR" }).insert() frappe.db.set_value("Account", encode_company_abbr(self.tally_creditors_account, self.erpnext_company), "account_type", "Payable") frappe.db.set_value("Account", encode_company_abbr(self.tally_debtors_account, self.erpnext_company), "account_type", "Receivable") frappe.db.set_value("Company", self.erpnext_company, "round_off_account", self.round_off_account) vouchers_file = frappe.get_doc("File", {"file_url": self.vouchers}) vouchers = json.loads(vouchers_file.get_content()) create_fiscal_years(vouchers) create_price_list() create_custom_fields(["Journal Entry", "Purchase Invoice", "Sales Invoice"]) total = len(vouchers) is_last = False for index in range(0, total, VOUCHER_CHUNK_SIZE): if index + VOUCHER_CHUNK_SIZE >= total: is_last = True frappe.enqueue_doc(self.doctype, self.name, "_import_vouchers", queue="long", timeout=3600, start=index+1, total=total, is_last=is_last)
def enqueue_next_mapping(self): next_mapping_name = self.get_next_mapping_name() if next_mapping_name: next_mapping = self.get_mapping(next_mapping_name) self.db_set(dict( current_mapping = next_mapping.name, current_mapping_start = 0, current_mapping_delete_start = 0, current_mapping_action = 'Insert' ), notify=True, commit=True) frappe.enqueue_doc(self.doctype, self.name, 'run_current_mapping', now=frappe.flags.in_test) else: self.complete()
def enqueue_next_page(self): mapping = self.get_mapping(self.current_mapping) fields = dict( percent_complete = self.percent_complete + (100.0 / self.total_pages) ) if self.current_mapping_action == 'Insert': start = self.current_mapping_start + mapping.page_length fields['current_mapping_start'] = start elif self.current_mapping_action == 'Delete': delete_start = self.current_mapping_delete_start + mapping.page_length fields['current_mapping_delete_start'] = delete_start self.db_set(fields, notify=True, commit=True) frappe.enqueue_doc(self.doctype, self.name, 'run_current_mapping', now=frappe.flags.in_test)
def anonymize_data(self): return frappe.enqueue_doc( self.doctype, self.name, "_anonymize_data", queue="long", timeout=3000, now=frappe.flags.in_test, )
def enqueue_next_page(self): mapping = self.get_mapping(self.current_mapping) percent_complete = self.percent_complete + (100.0 / self.total_pages) fields = dict( percent_complete = percent_complete ) if self.current_mapping_action == 'Insert': start = self.current_mapping_start + mapping.page_length fields['current_mapping_start'] = start elif self.current_mapping_action == 'Delete': delete_start = self.current_mapping_delete_start + mapping.page_length fields['current_mapping_delete_start'] = delete_start self.db_set(fields, notify=True, commit=True) if(percent_complete < 100): frappe.publish_realtime(self.trigger_name, {"progress_percent": percent_complete}, user=frappe.session.user) frappe.enqueue_doc(self.doctype, self.name, 'run_current_mapping', now=frappe.flags.in_test)
def migrate(self): frappe.enqueue_doc("QuickBooks Migrator", "QuickBooks Migrator", "_migrate", queue="long")
def deploy(context): context = json.loads(context) if 'issue' in context and 'pull_request' in context.get( 'issue') and context.get('issue', {}).get( 'state') == 'open' and context.get('action') != "deleted": comment = context.get('comment', {}).get('body') user = context.get('comment', {}).get('user', {}).get('login') deployer_config = frappe.get_single("Deployer Config") allowed_requesters = deployer_config.allowed_requesters.split('\n') bot_username = deployer_config.bot_username if user in allowed_requesters: repository = context.get('repository', {}).get('name') repository_fullname = context.get('repository', {}).get('full_name') pull_request = context.get('issue', {}).get('number') if "@{} create instance".format(bot_username) in comment: if not frappe.db.exists( "Deployer Instance", { 'application_being_tested': repository, 'pull_request_number': pull_request, 'is_active': True }): parameters = get_additional_params(comment) repository_name = context.get('repository', {}).get('full_name') deployer_instance = frappe.get_doc({ 'doctype': 'Deployer Instance', 'application_being_tested': repository, 'instance_requested_by': user, 'pull_request_number': pull_request }) deployer_instance.is_active = True deployer_instance.save(ignore_permissions=True) frappe.enqueue_doc(deployer_instance.doctype, deployer_instance.name, "initialize", timeout=1000, repository_fullname=repository_fullname, parameters=parameters, deployer_config=deployer_config) elif "@{} destroy instance".format(bot_username) in comment: stop_instance(pull_request, repository_fullname) elif context.get('action') == "synchronize": try: deployer_instance = frappe.get_doc( "Deployer Instance", { 'application_being_tested': context.get('repository', {}).get('name'), 'pull_request_number': context.get('number'), 'is_active': True }) frappe.enqueue_doc(deployer_instance.doctype, deployer_instance.name, "update_instance", timeout=1000, repository_fullname=context.get( "repository", {}).get('full_name')) return except frappe.DoesNotExistError: pass try: deployer_instance = frappe.get_doc( "Deployer Instance", { 'depends_on': "#".join([ context.get('repository', {}).get('name'), context.get('number') ]), 'is_active': True }) frappe.enqueue_doc(deployer_instance.doctype, deployer_instance.name, "update_instance", timeout=1000, repository_fullname=context.get( "repository", {}).get('full_name')) except frappe.DoesNotExistError: pass elif context.get('action') == "closed": stop_instance(context.get('number'), context.get('base', {}).get('repo', {}).get('name'))
def on_submit(self): frappe.enqueue_doc('IOT Batch Task', self.name, 'run_task', enqueue_after_commit=True)