def make_demo_user(): from webnotes.auth import _update_password roles = ["Accounts Manager", "Analytics", "Expense Approver", "Accounts User", "Leave Approver", "Blogger", "Customer", "Sales Manager", "Employee", "Support Manager", "HR Manager", "HR User", "Maintenance Manager", "Maintenance User", "Material Manager", "Material Master Manager", "Material User", "Manufacturing Manager", "Manufacturing User", "Projects User", "Purchase Manager", "Purchase Master Manager", "Purchase User", "Quality Manager", "Report Manager", "Sales Master Manager", "Sales User", "Supplier", "Support Team"] def add_roles(bean): for role in roles: p.doclist.append({ "doctype": "UserRole", "parentfield": "user_roles", "role": role }) # make demo user if webnotes.conn.exists("Profile", "*****@*****.**"): webnotes.delete_doc("Profile", "*****@*****.**") p = webnotes.new_bean("Profile") p.doc.email = "*****@*****.**" p.doc.first_name = "Demo" p.doc.last_name = "User" p.doc.enabled = 1 p.doc.user_type = "ERPNino Demo" p.insert() add_roles(p) p.save() _update_password("*****@*****.**", "demo") # make system manager user if webnotes.conn.exists("Profile", "*****@*****.**"): webnotes.delete_doc("Profile", "*****@*****.**") p = webnotes.new_bean("Profile") p.doc.email = "*****@*****.**" p.doc.first_name = "Admin" p.doc.last_name = "User" p.doc.enabled = 1 p.doc.user_type = "System User" p.insert() roles.append("System Manager") add_roles(p) p.save() _update_password("*****@*****.**", "admin010123") # only read for newsletter webnotes.conn.sql("""update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0 where parent='Newsletter'""") webnotes.conn.sql("""update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0 where parent='Profile' and role='All'""") webnotes.conn.commit()
def make_demo_login_page(): webnotes.conn.set_value("Website Settings", None, "home_page", "") webnotes.conn.sql("""delete from `tabWeb Page` where name='demo-login'""") p = webnotes.new_bean("Web Page") p.doc.title = "Demo Login" p.doc.published = 1 p.doc.description = "ERPNext Demo Login" with open(os.path.join(os.path.dirname(__file__), "demo-login.html"), "r") as dfile: p.doc.main_section = dfile.read() p.doc.insert_code = 1 with open(os.path.join(os.path.dirname(__file__), "demo-login.js"), "r") as dfile: p.doc.javascript = dfile.read() p.doc.insert_style = 1 with open(os.path.join(os.path.dirname(__file__), "demo-login.css"), "r") as dfile: p.doc.css = dfile.read() p.insert() webnotes.conn.set_value("Website Settings", None, "home_page", "demo-login") webnotes.conn.commit()
def create_email_digest(): from webnotes.profile import get_system_managers system_managers = get_system_managers(only_name=True) if not system_managers: return for company in webnotes.conn.sql_list("select name FROM `tabCompany`"): if not webnotes.conn.exists("Email Digest", "Default Weekly Digest - " + company): edigest = webnotes.bean({ "doctype": "Email Digest", "name": "Default Weekly Digest - " + company, "company": company, "frequency": "Weekly", "recipient_list": "\n".join(system_managers) }) for fieldname in edigest.meta.get_fieldnames({"fieldtype": "Check"}): if fieldname != "scheduler_errors": edigest.doc.fields[fieldname] = 1 edigest.insert() # scheduler errors digest edigest = webnotes.new_bean("Email Digest") edigest.doc.fields.update({ "name": "Scheduler Errors", "company": webnotes.conn.get_default("company"), "frequency": "Daily", "recipient_list": "\n".join(system_managers), "scheduler_errors": 1, "enabled": 1 }) edigest.insert()
def execute(): webnotes.reload_doc("setup", "doctype", "email_digest") from webnotes.profile import get_system_managers system_managers = get_system_managers(only_name=True) if not system_managers: return # no default company company = webnotes.conn.get_default("company") if not company: company = webnotes.conn.sql_list("select name from `tabCompany`") if company: company = company[0] if not company: return # scheduler errors digest edigest = webnotes.new_bean("Email Digest") edigest.doc.fields.update({ "name": "Scheduler Errors", "company": company, "frequency": "Daily", "enabled": 1, "recipient_list": "\n".join(system_managers), "scheduler_errors": 1 }) edigest.insert()
def make_demo_user(): if webnotes.conn.exists("Profile", "*****@*****.**"): webnotes.delete_doc("Profile", "*****@*****.**") p = webnotes.new_bean("Profile") p.doc.email = "*****@*****.**" p.doc.first_name = "Demo" p.doc.last_name = "User" p.doc.enabled = 1 p.doc.user_type = "ERPNext Demo" p.doc.send_invite_email = 0 p.doc.new_password = "******" p.insert() for role in ("Accounts Manager", "Analytics", "Expense Approver", "Accounts User", "Leave Approver", "Blogger", "Customer", "Sales Manager", "Employee", "Support Manager", "HR Manager", "HR User", "Maintenance Manager", "Maintenance User", "Material Manager", "Material Master Manager", "Material User", "Partner", "Manufacturing Manager", "Manufacturing User", "Projects User", "Purchase Manager", "Purchase Master Manager", "Purchase User", "Quality Manager", "Report Manager", "Sales Master Manager", "Sales User", "Supplier", "Support Team"): p.doclist.append({ "doctype": "UserRole", "parentfield": "user_roles", "role": role }) p.save() # only read for newsletter webnotes.conn.sql("""update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0 where parent='Newsletter'""") webnotes.conn.commit()
def execute(): webnotes.reload_doc("setup", "doctype", "email_digest") from webnotes.profile import get_system_managers system_managers = get_system_managers(only_name=True) if not system_managers: return # no default company company = webnotes.conn.sql_list("select name from `tabCompany`") if company: company = company[0] if not company: return # scheduler errors digest edigest = webnotes.new_bean("Email Digest") edigest.doc.fields.update({ "name": "Scheduler Errors", "company": company, "frequency": "Daily", "enabled": 1, "recipient_list": "\n".join(system_managers), "scheduler_errors": 1 }) edigest.insert()
def create_email_digest(): from webnotes.profile import get_system_managers system_managers = get_system_managers(only_name=True) if not system_managers: return companies = webnotes.conn.sql_list("select name FROM `tabCompany`") for company in companies: if not webnotes.conn.exists("Email Digest", "Default Weekly Digest - " + company): edigest = webnotes.bean({ "doctype": "Email Digest", "name": "Default Weekly Digest - " + company, "company": company, "frequency": "Weekly", "recipient_list": "\n".join(system_managers) }) for fieldname in edigest.meta.get_fieldnames({"fieldtype": "Check"}): if fieldname != "scheduler_errors": edigest.doc.fields[fieldname] = 1 edigest.insert() # scheduler errors digest if companies: edigest = webnotes.new_bean("Email Digest") edigest.doc.fields.update({ "name": "Scheduler Errors", "company": companies[0], "frequency": "Daily", "recipient_list": "\n".join(system_managers), "scheduler_errors": 1, "enabled": 1 }) edigest.insert()
def make_stock_entry(production_order_id, purpose): production_order = webnotes.bean("Production Order", production_order_id) # validate already existing ste = webnotes.conn.get_value("Stock Entry", { "production_order":production_order_id, "purpose": purpose }, "name") stock_entry = webnotes.new_bean("Stock Entry") stock_entry.doc.purpose = purpose stock_entry.doc.production_order = production_order_id stock_entry.doc.company = production_order.doc.company stock_entry.doc.bom_no = production_order.doc.bom_no stock_entry.doc.use_multi_level_bom = production_order.doc.use_multi_level_bom stock_entry.doc.fg_completed_qty = flt(production_order.doc.qty) - flt(production_order.doc.produced_qty) if purpose=="Material Transfer": stock_entry.doc.to_warehouse = production_order.doc.wip_warehouse else: stock_entry.doc.from_warehouse = production_order.doc.wip_warehouse stock_entry.doc.to_warehouse = production_order.doc.fg_warehouse stock_entry.run_method("get_items") return [d.fields for d in stock_entry.doclist]
def make( doctype=None, name=None, content=None, subject=None, sent_or_received="Sent", sender=None, recipients=None, communication_medium="Email", send_email=False, print_html=None, attachments="[]", send_me_a_copy=False, set_lead=True, date=None, ): # add to Communication sent_via = None # since we are using fullname and email, # if the fullname has any incompatible characters,formataddr can deal with it try: import json sender = json.loads(sender) except ValueError: pass if isinstance(sender, (tuple, list)) and len(sender) == 2: from email.utils import formataddr sender = formataddr(sender) comm = webnotes.new_bean("Communication") d = comm.doc d.subject = subject d.content = content d.sent_or_received = sent_or_received d.sender = sender or webnotes.conn.get_value("Profile", webnotes.session.user, "email") d.recipients = recipients # add as child sent_via = webnotes.get_obj(doctype, name) d.parent = name d.parenttype = doctype d.parentfield = "communications" if date: d.communication_date = date d.communication_medium = communication_medium if send_email: send_comm_email(d, name, sent_via, print_html, attachments, send_me_a_copy) comm.ignore_permissions = True comm.insert()
def make(doctype=None, name=None, content=None, subject=None, sent_or_received="Sent", sender=None, recipients=None, communication_medium="Email", send_email=False, print_html=None, attachments='[]', send_me_a_copy=False, set_lead=True, date=None): # add to Communication sent_via = None # since we are using fullname and email, # if the fullname has any incompatible characters,formataddr can deal with it try: import json sender = json.loads(sender) except ValueError: pass if isinstance(sender, (tuple, list)) and len(sender) == 2: from email.utils import formataddr sender = formataddr(sender) comm = webnotes.new_bean('Communication') d = comm.doc d.subject = subject d.content = content d.sent_or_received = sent_or_received d.sender = sender or webnotes.conn.get_value( "Profile", webnotes.session.user, "email") d.recipients = recipients # add as child sent_via = webnotes.get_obj(doctype, name) d.parent = name d.parenttype = doctype d.parentfield = "communications" if date: d.communication_date = date d.communication_medium = communication_medium comm.ignore_permissions = True comm.insert() if send_email: d = comm.doc send_comm_email(d, name, sent_via, print_html, attachments, send_me_a_copy)
def add_to_sitemap(options): bean = webnotes.new_bean("Website Sitemap") for key in sitemap_fields: bean.doc.fields[key] = options.get(key) if not bean.doc.page_name: bean.doc.page_name = options.link_name bean.doc.website_sitemap_config = options.link_name bean.insert(ignore_permissions=True)
def make_demo_on_login_script(): webnotes.conn.sql("""delete from `tabCustom Script` where dt='Control Panel'""") s = webnotes.new_bean("Custom Script") s.doc.dt = "Control Panel" s.doc.script_type = "Server" with open(os.path.join(os.path.dirname(__file__), "demo_control_panel.py"), "r") as dfile: s.doc.script = dfile.read() s.insert() webnotes.conn.commit()
def make_serial_no(serial_no, sle): sr = webnotes.new_bean("Serial No") sr.doc.serial_no = serial_no sr.doc.item_code = sle.item_code sr.make_controller().via_stock_ledger = True sr.insert() sr.doc.warehouse = sle.warehouse sr.doc.status = "Available" sr.save() webnotes.msgprint(_("Serial No created") + ": " + sr.doc.name) return sr.doc.name
def create_subscription(args): d = webnotes.new_bean('Campaign Subscriber') d.doc.fields.update({ 'subscriber_name': args.get('name'), 'phone': args.get('phone'), 'email': args.get('email'), 'territory': args.get('territory'), 'parent': 'IPVA 2014', 'parenttype': 'Campaign', 'parentfield': 'subscribers_list' }) d.save()
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")]: mr = webnotes.new_bean("Material Request") mr.doc.material_request_type = "Purchase" mr.doc.transaction_date = current_date mr.doc.fiscal_year = current_date.year mr.doclist.append({ "doctype": "Material Request Item", "parentfield": "indent_details", "schedule_date": webnotes.utils.add_days(current_date, 7), "item_code": row[0], "qty": -row[-1] }) mr.insert() mr.submit() # make supplier quotations if can_make("Supplier Quotation"): from 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 = webnotes.bean(make_supplier_quotation(row[0])) sq.doc.transaction_date = current_date sq.doc.fiscal_year = current_date.year sq.insert() sq.submit() webnotes.conn.commit() # make purchase orders if can_make("Purchase Order"): from 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 = webnotes.bean(make_purchase_order(row[0])) po.doc.transaction_date = current_date po.doc.fiscal_year = current_date.year po.insert() po.submit() webnotes.conn.commit()
def test_cannot_create_direct(self): sr = webnotes.new_bean("Serial No") sr.doc.item_code = "_Test Serialized Item" sr.doc.warehouse = "_Test Warehouse - _TC" sr.doc.serial_no = "_TCSER0001" sr.doc.purchase_rate = 10 self.assertRaises(SerialNoCannotCreateDirectError, sr.insert) sr.doc.warehouse = None sr.insert() self.assertTrue(sr.doc.name) sr.doc.warehouse = "_Test Warehouse - _TC" self.assertTrue(SerialNoCannotCannotChangeError, sr.doc.save)
def make_demo_on_login_script(): webnotes.conn.sql("""delete from `tabCustom Script` where dt='Control Panel'""") s = webnotes.new_bean("Custom Script") s.doc.dt = "Control Panel" s.doc.script_type = "Server" with open(os.path.join(os.path.dirname(__file__), "demo_control_panel.py"), "r") as dfile: s.doc.script = dfile.read() s.insert() cp = webnotes.bean("Control Panel") cp.doc.custom_startup_code = """wn.ui.toolbar.show_banner('You are using ERPNext Demo. To start your own ERPNext Trial, <a href="https://erpnext.com/pricing-and-signup" target="_blank">click here</a>')""" cp.save() webnotes.conn.commit()
def add_system_manager(email, first_name=None, last_name=None): # add profile profile = webnotes.new_bean("Profile") profile.doc.fields.update({ "name": email, "email": email, "enabled": 1, "first_name": first_name or email, "last_name": last_name }) profile.insert() # add roles roles = webnotes.conn.sql_list("""select name from `tabRole` where name not in ("Administrator", "Guest", "All")""") profile.make_controller().add_roles(*roles)
def make_demo_on_login_script(): webnotes.conn.sql( """delete from `tabCustom Script` where dt='Control Panel'""") s = webnotes.new_bean("Custom Script") s.doc.dt = "Control Panel" s.doc.script_type = "Server" with open(os.path.join(os.path.dirname(__file__), "demo_control_panel.py"), "r") as dfile: s.doc.script = dfile.read() s.insert() cp = webnotes.bean("Control Panel") cp.doc.custom_startup_code = """wn.ui.toolbar.show_banner('You are using ERPNext Demo. To start your own ERPNext Trial, <a href="https://erpnext.com/pricing-and-signup" target="_blank">click here</a>')""" cp.save() webnotes.conn.commit()
def execute(): from webnotes.profile import get_system_managers system_managers = get_system_managers(only_name=True) if not system_managers: return # scheduler errors digest edigest = webnotes.new_bean("Email Digest") edigest.doc.fields.update({ "name": "Scheduler Errors", "company": webnotes.conn.get_default("company"), "frequency": "Daily", "enabled": 1, "recipient_list": "\n".join(system_managers), "scheduler_errors": 1 }) edigest.insert()
def create_production_order(self, items): """Create production order. Called from Production Planning Tool""" from manufacturing.doctype.production_order.production_order import OverProductionError pro_list = [] for key in items: pro = webnotes.new_bean("Production Order") pro.doc.fields.update(items[key]) webnotes.mute_messages = True try: pro.insert() pro_list.append(pro.doc.name) except OverProductionError, e: pass webnotes.mute_messages = False
def create_production_order(self, items): """Create production order. Called from Production Planning Tool""" from manufacturing.doctype.production_order.production_order import OverProductionError pro_list = [] for key in items: pro = webnotes.new_bean("Production Order") pro.doc.fields.update(items[key]) webnotes.flags.mute_messages = True try: pro.insert() pro_list.append(pro.doc.name) except OverProductionError, e: pass webnotes.flags.mute_messages = False
def edit(arg=None): import markdown2 args = webnotes.local.form_dict if args.name: b = webnotes.bean("ToDo", args.name) else: b = webnotes.new_bean("ToDo") for key in ("description", "date", "priority", "checked"): b.doc.fields[key] = args.get(key) b.insert_or_update() if args.name and args.checked: notify_assignment(d) return b.doc.name
def make_serial_no(self, serial_no): sr = webnotes.new_bean("Serial No") sr.doc.serial_no = serial_no sr.doc.item_code = self.doc.item_code sr.doc.purchase_rate = self.doc.incoming_rate sr.doc.purchase_document_type = self.doc.voucher_type sr.doc.purchase_document_no = self.doc.voucher_no sr.doc.purchase_date = self.doc.posting_date sr.doc.purchase_time = self.doc.posting_time sr.make_controller().via_stock_ledger = True sr.insert() # set warehouse sr.doc.warehouse = self.doc.warehouse sr.doc.status = "Available" sr.save() webnotes.msgprint(_("Serial No created") + ": " + sr.doc.name) return sr.doc.name
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")]: mr = webnotes.new_bean("Material Request") mr.doc.material_request_type = "Purchase" mr.doc.transaction_date = current_date mr.doc.fiscal_year = "2013" mr.doclist.append({ "doctype": "Material Request Item", "parentfield": "indent_details", "schedule_date": webnotes.utils.add_days(current_date, 7), "item_code": row[0], "qty": -row[-1] }) mr.insert() mr.submit() # make supplier quotations if can_make("Supplier Quotation"): from 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 = webnotes.bean(make_supplier_quotation(row[0])) sq.doc.transaction_date = current_date sq.doc.fiscal_year = "2013" sq.insert() sq.submit() webnotes.conn.commit() # make purchase orders if can_make("Purchase Order"): from 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 = webnotes.bean(make_purchase_order(row[0])) po.doc.transaction_date = current_date po.doc.fiscal_year = "2013" po.insert() po.submit() webnotes.conn.commit()
def make_serial_no(self,serial_no): sr = webnotes.new_bean("Serial No") sr.doc.serial_no = serial_no sr.doc.item_code = self.doc.item sr.make_controller().via_stock_ledger = True sr.insert() sr.doc.warehouse = 'Finished Goods - P' sr.doc.status = "Available" sr.doc.purchase_document_type = 'Packing Items' sr.doc.purchase_document_no = self.doc.name sr.doc.purchase_date = self.doc.creation sr.save() qr="select warranty_period from tabItem where name='"+self.doc.item+"'" res=webnotes.conn.sql(qr) if res: exdt=add_months(cstr(nowdate()),cint(res[0][0])) qr1="update `tabSerial No` set warranty_expiry_date='"+cstr(exdt)+"' where name='"+sr.doc.name+"'" webnotes.conn.sql(qr1) webnotes.msgprint(_("Serial No created") + ": " + sr.doc.name) return sr.doc.name
def make_serial_no(self, serial_no): sr = webnotes.new_bean("Serial No") sr.doc.serial_no = serial_no sr.doc.item_code = self.doc.item sr.make_controller().via_stock_ledger = True sr.insert() sr.doc.warehouse = 'Finished Goods - P' sr.doc.status = "Available" sr.doc.purchase_document_type = 'Packing Items' sr.doc.purchase_document_no = self.doc.name sr.doc.purchase_date = self.doc.creation sr.save() qr = "select warranty_period from tabItem where name='" + self.doc.item + "'" res = webnotes.conn.sql(qr) if res: exdt = add_months(cstr(nowdate()), cint(res[0][0])) qr1 = "update `tabSerial No` set warranty_expiry_date='" + cstr( exdt) + "' where name='" + sr.doc.name + "'" webnotes.conn.sql(qr1) webnotes.msgprint(_("Serial No created") + ": " + sr.doc.name) return sr.doc.name
def get_payment_entry(doc): bank_account = get_default_bank_cash_account(doc.company, "Bank Voucher") jv = webnotes.new_bean('Journal Voucher') jv.doc.voucher_type = 'Bank Voucher' jv.doc.company = doc.company jv.doc.fiscal_year = doc.fiscal_year jv.doclist.append({ "doctype": "Journal Voucher Detail", "parentfield": "entries" }) jv.doclist.append({ "doctype": "Journal Voucher Detail", "parentfield": "entries" }) if bank_account: jv.doclist[2].account = bank_account["account"] jv.doclist[2].balance = bank_account["balance"] return jv
def make_demo_user(): from webnotes.auth import _update_password roles = [ "Accounts Manager", "Analytics", "Expense Approver", "Accounts User", "Leave Approver", "Blogger", "Customer", "Sales Manager", "Employee", "Support Manager", "HR Manager", "HR User", "Maintenance Manager", "Maintenance User", "Material Manager", "Material Master Manager", "Material User", "Manufacturing Manager", "Manufacturing User", "Projects User", "Purchase Manager", "Purchase Master Manager", "Purchase User", "Quality Manager", "Report Manager", "Sales Master Manager", "Sales User", "Supplier", "Support Team" ] def add_roles(bean): for role in roles: p.doclist.append({ "doctype": "UserRole", "parentfield": "user_roles", "role": role }) # make demo user if webnotes.conn.exists("Profile", "*****@*****.**"): webnotes.delete_doc("Profile", "*****@*****.**") p = webnotes.new_bean("Profile") p.doc.email = "*****@*****.**" p.doc.first_name = "Demo" p.doc.last_name = "User" p.doc.enabled = 1 p.doc.user_type = "ERPNext Demo" p.insert() add_roles(p) p.save() _update_password("*****@*****.**", "demo") # make system manager user if webnotes.conn.exists("Profile", "*****@*****.**"): webnotes.delete_doc("Profile", "*****@*****.**") p = webnotes.new_bean("Profile") p.doc.email = "*****@*****.**" p.doc.first_name = "Admin" p.doc.last_name = "User" p.doc.enabled = 1 p.doc.user_type = "System User" p.insert() roles.append("System Manager") add_roles(p) p.save() _update_password("*****@*****.**", "admin010123") # only read for newsletter webnotes.conn.sql( """update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0 where parent='Newsletter'""") webnotes.conn.sql( """update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0 where parent='Profile' and role='All'""") webnotes.conn.commit()