Skip to content

Instantly share code, notes, and snippets.

View rmehta's full-sized avatar

Rushabh Mehta rmehta

View GitHub Profile

Concept Note for wnframework2

html/css is fast evolving and covering gaps in building of complex web apps. The key gaps that remain are

  1. persistent datastore for objects / content
  2. partial loading of code (require pattern) / ajax
  3. built-in app / site structure and navigation
  4. built-in authoring of structured content
  5. user authentication and session management
@rmehta
rmehta / erpnext-sample-validation-script.js
Created September 24, 2012 04:53
Sample Custom Script for Validation
// this function is called by erpnext
// in the browser before saving
cur_frm.cscript.custom_validate = function(doc) {
if(user=="user1@example.com" && doc.purpose!="Material Receipt") {
msgprint("You are only allowed Material Receipt");
validated = false;
}
}
@rmehta
rmehta / gist:3866677
Created October 10, 2012 16:20
client event trigger example
// add a trigger on field "custom_field1"
cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {
// update a new field "custom_field3"
doc.custom_field3 = flt(doc.custom_field1)*flt(doc.custom_field2)/1000;
// refresh in form
refresh_field('custom_field3');
}
@rmehta
rmehta / sample-print-format.html
Created October 25, 2012 16:32
ERPNext Print Format sample with additional column
<!--
Sample Print Format for ERPNext
Please use at your own discretion
For suggestions and contributions:
https://github.com/webnotes/erpnext-print-templates
Freely usable under MIT license
-->
<!-- Style Settings -->
@rmehta
rmehta / sales_order.json
Created December 6, 2012 04:06
Sample Sales Order
[
{
"doctype":"Sales Order",
"__islocal": 1,
"customer": "Customer 1",
"posting_date": "2012-02-20"
..
},
{
"doctype": "Sales Order Item",
@rmehta
rmehta / get_shade.js
Created December 18, 2012 06:49
Get a lighter / darker shade
var get_hex = function(i) {
i = Math.round(i);
if(i>255) return 'ff';
if(i<0) return '00';
i =i .toString(16);
if(i.length==1) i = '0'+i;
return i;
}
var get_shade = function(color, factor) {
@rmehta
rmehta / generate_locale_info.py
Created January 17, 2013 11:10
Script to scrape country, currency, timezone info from various sources
# all country info
from __future__ import unicode_literals
time_zones = {
'Afghanistan': ['Asia/Kabul'],
'Albania': ['Europe/Tirane'],
'Algeria': ['Africa/Algiers'],
'Andorra': ['Europe/Andorra'],
'Angola': ['Africa/Luanda'],
'Antigua and Barbuda': ['America/Antigua'],
@rmehta
rmehta / update_doctype_permissions.py
Created January 21, 2013 08:49
Script to read txt doctypes and update report permissions to 1
# add report permission
from webnotes.modules.utils import peval_doclist, pprint_doclist
import os
def do():
for path, folders, files in os.walk('app/'):
if (os.path.basename(os.path.dirname(path)) in "doctype"):
for f in files:
if f.endswith(".txt"):
@rmehta
rmehta / update_doctypes.py
Created January 22, 2013 09:38
Update multiple doctypes (for cleanup)
import webnotes
def do():
webnotes.connect()
for name in webnotes.conn.sql("""select name from tabDocType"""):
doctype = webnotes.model_wrapper("DocType", name[0])
changed = False
if doctype.doclist.get({"doctype":"DocPerm", "permlevel":1}):
doctype.doclist.remove_items({"doctype":"DocPerm", "permlevel":1})
print doctype.doc.name
import webnotes
def do():
webnotes.connect()
for dt in webnotes.conn.sql("""select distinct parent from tabDocField
where fieldtype="Currency" """):
doctype = webnotes.model_wrapper("DocType", dt[0])
changed = False