Skip to content

Instantly share code, notes, and snippets.

View nathando's full-sized avatar
🎯
Focusing

Do Le Bao Nguyen nathando

🎯
Focusing
View GitHub Profile
@nathando
nathando / concat-certs.sh
Created April 12, 2017 10:13
Concat cert into ovpn profile
#!/bin/bash
client=$1
(echo '<ca>'; cat ca.crt; echo '</ca>';) >> $client.ovpn
(echo '<cert>'; cat $client.crt; echo '</cert>';) >> $client.ovpn
(echo '<key>'; cat $client.key; echo '</key>';) >> $client.ovpn
@nathando
nathando / copy-crts.sh
Created April 12, 2017 10:11
Generate and copy client certs from OpenVPN server
#!/bin/bash
server="xxx.xxx.xxx.xxx"
client=$1
ssh root@$server client=$client 'bash -s' <<'ENDSSH'
cd /etc/openvpn/easy-rsa
. ./vars
./build-key --batch $client
ENDSSH
scp root@$server:/etc/openvpn/easy-rsa/keys/$client.crt .
scp root@$server:/etc/openvpn/easy-rsa/keys/$client.key .
@nathando
nathando / meta.js
Created November 27, 2014 09:10
Inconsistency in get_field_precision logic
get_field_precision: function(df, doc) {
var precision = cint(frappe.defaults.get_default("float_precision")) || 3;
// Here if the precision exists, it should return directly,
// Therefore, it always can overwrite number format -> 5,6,7,8 ...
if (df && cint(df.precision)) {
precision = cint(df.precision);
} else if(df && df.fieldtype === "Currency") {
var currency = this.get_field_currency(df, doc);
var number_format = get_number_format(currency);
var number_format_info = get_number_format_info(number_format);
@nathando
nathando / sales_order_amt.js
Created November 7, 2014 08:33
Change the way Amount is calculated in ERPNext Selling
// Replace with new calculation of item value
cur_frm.cscript.calculate_item_values = function() {
var me = this;
if (!this.discount_amount_applied) {
$.each(this.frm.item_doclist, function(i, item) {
frappe.model.round_floats_in(item);
item.rate = flt(item.amount / item.qty, precision("rate", item));
me._set_in_company_currency(item, "price_list_rate", "base_price_list_rate");
me._set_in_company_currency(item, "rate", "base_rate");
@nathando
nathando / sales_order_amt.js
Created November 5, 2014 10:18
Sales Order - Amount Fixed
// Replace with new calculation of item value
cur_frm.cscript.calculate_item_values = function() {
var me = this;
if (!this.discount_amount_applied) {
$.each(this.frm.item_doclist, function(i, item) {
frappe.model.round_floats_in(item);
if (!cur_frm.fixed_amt) {
item.amount = flt(item.rate * item.qty, precision("amount", item));
}
@nathando
nathando / employee.py
Created November 5, 2014 07:13
Employee Update for User Permission
def update_user_permissions(self):
for l in self.get("employee_leave_approvers")[:]:
frappe.permissions.add_user_permission("User", l.leave_approver, self.user_id)
frappe.permissions.add_user_permission("Employee", self.name, self.user_id)
frappe.permissions.set_user_permission_if_allowed("Company", self.company, self.user_id)
@nathando
nathando / test_api.py
Created August 13, 2014 10:07
Test for ERPNext API
import frappe
import frappe.defaults
import unittest
import bioplastics_api as api
from frappe.auth import LoginManager, HTTPRequest, CookieManager
# load test records and dependencies
test_records = frappe.get_test_records('po')
class MockRequest():
def __init__(self):
@nathando
nathando / custom_api.py
Last active August 29, 2015 14:04
Custome API
from frappe.widgets.form.utils import get_linked_docs
@frappe.whitelist(allow_guest=False)
def received_po_item():
po_name = frappe.local.form_dict.get('po_name')
pr_name = frappe.local.form_dict.get('pr_name')
item_code = frappe.local.form_dict.get('item_code')
qty = float(frappe.local.form_dict.get('qty', 0))
if po_name:
try:
@nathando
nathando / leave_application.js
Last active August 29, 2015 14:04
Leave Application Email
set_notified = function(doc, dt, dn) {
frappe.call({
method:"frappe.client.set_value",
args: {
doctype: dt,
name: dn,
fieldname: 'notified_by_email',
value: 1
},
callback: function() {
@nathando
nathando / salary_slip.js
Last active August 29, 2015 14:04
Ajax client test
cur_frm.cscript.employee = function(doc,dt,dn){
return $c_obj(doc, 'get_emp_and_leave_details','',function(r, rt) {
console.log("default=====");
var doc = locals[dt][dn];
cur_frm.refresh(); // Once this called, the changes made using customize script are reverted
calculate_all(doc, dt, dn);
});
}