Thursday, 23 June 2016

Get currency exchange rate in python

Using below code, you can get currency exchange rate.

>>> import requests
>>> response = requests.get("http://api.fixer.io/latest", params={
...     "base": "USD",
...     "symbols": "INR"
... })
>>> value = response.json()
>>> print value
{u'date': u'2016-06-22', u'base': u'USD', u'rates': {u'INR': 67.496}}
>>> 

Connecting to mysql using python

Connecting to mysql using python

In [1]:  import MySQLdb


#MySQLdb.connect("localhost","username","password","dbname")
In [2]: db = MySQLdb.connect("localhost","root","hPMkXT1vU7rh","erpdatabase")

In [3]:  cursor = db.cursor()

In [4]: cursor.execute("SELECT VERSION()")
Out[4]: 1L

In [5]: data = cursor.fetchone()

In [6]:

In [6]: print data
('10.0.25-MariaDB-1~trusty',)

In [7]: cursor.execute("SELECT name from tabItem")
Out[7]: 8L

In [8]: data = cursor.fetchall()

In [9]: print data
(('chemical',), ('Furan',), ('i',), ('T Meter',), ('Water Content Test IS 1001',), ('Water Content Test IS 9001',), ('Water Content Test IS 91',), ('Water Content Test IS91',))

In [10]: print list(data)
[('chemical',), ('Furan',), ('i',), ('T Meter',), ('Water Content Test IS 1001',), ('Water Content Test IS 9001',), ('Water Content Test IS 91',), ('Water Content Test IS91',)]


//print in list
In [14]: a=data

In [15]: print a
(('chemical',), ('Furan',), ('i',), ('T Meter',), ('Water Content Test IS 1001',), ('Water Content Test IS 9001',), ('Water Content Test IS 91',), ('Water Content Test IS91',))

In [16]:  [element for tupl in a for element in tupl]
Out[16]:
['chemical',
 'Furan',
 'i',
 'T Meter',
 'Water Content Test IS 1001',
 'Water Content Test IS 9001',
 'Water Content Test IS 91',
 'Water Content Test IS91']

 #print in list

In [23]: abc = [e[0] for e in a]

In [24]: abc
Out[24]:
['chemical',
 'Furan',
 'i',
 'T Meter',
 'Water Content Test IS 1001',
 'Water Content Test IS 9001',
 'Water Content Test IS 91',
 'Water Content Test IS91']

Friday, 10 June 2016

[ERPNext] How to set property of field in child table?

How to set property of field in child table?

Ans: We can set property of doc fields using following syntax.

cur_frm.set_df_property(FIELDNAME, Property, Value);

e.g.

cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Entry");

We can also set property of fields in child table, which is the main reason for this post.

Syntax:

var df = frappe.meta.get_docfield("TABLE NAME","FIELDNAME", cur_frm.doc.name);
df.read_only = 1;



e.g.
var df = frappe.meta.get_docfield("Employer Project Details","company_name", cur_frm.doc.name);
df.options = ["Tech M", "Wipro", "TCS"];


Using above code, we have generated dynamic dropdown in child table field of Select type.


  


Please comment if you like this post or need any help.

Thanks,
Sambhaji Kolate