-
Notifications
You must be signed in to change notification settings - Fork 141
/
example2.py
115 lines (107 loc) · 2.11 KB
/
example2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#-*- coding: utf-8 -*-
from frappeclient import FrappeClient as Client
import os
files = {
'CRM': [
'Customer',
'Address',
'Contact',
'Customer Group',
'Territory',
'Sales Person',
'Terms and Conditions',
'Target Detail',
'Sales Partner',
'Opportunity',
'Lead'
],
'Manufacturing': [
'Production Order',
'Workstation',
'Operation',
'BOM'
],
'Selling': [
'Quotation',
'Sales Order',
'Sales Taxes and Charges',
'Installation Note',
'Product Bundle',
],
'Stock': [
'Purchase Receipt',
'Bin',
'Item',
'Delivery Note',
'Material Request',
'Item Variant',
'Item Attribute Value',
'Serial No',
'Warehouse',
'Stock Entry',
'Price List',
'Item Price',
'Batch',
'Landed Cost Voucher'
],
'Setup': [
'UOM',
'Print Heading',
'Currency Exchange',
'Authorization Rule',
'Authorization Control'
],
'Support': [
'Issue',
'Warranty Claim',
'Maintenance Visit'
],
'HR': [
'Employee',
'Job Applicant',
'Offer Letter',
'Salary Structure',
'Leave Application',
'Expense Claim',
'Expense Claim Type',
'Appraisal',
'Salary Slip',
'Holiday',
'Attendance',
'Leave Type',
'Job Opening',
'Designation',
'Department',
'Earning Type',
'Deduction Type',
'Branch'
]
}
def get_path(*args):
path = os.path.abspath(os.path.join(
os.path.dirname(__file__), 'ERPNext',
*args
))
if not os.path.exists(path):
os.makedirs(path)
return path
def download():
c = Client('http://localhost:8000', 'Administrator', 'admin')
for k,v in list(files.items()):
for dt in v:
for s, ext, method in (('Schemes', 'pdf', 'get_pdf'), ('Upload Templates', 'csv', 'get_upload_template')):
base_path = get_path(k, s)
with open(os.path.join(base_path, '.'.join([dt, ext])), 'wb') as handler:
fn = getattr(c, method)
if ext == 'pdf':
content = fn('DocType', dt, 'Standard')
else:
try:
content = fn(dt)
except Exception as e:
print('Failed to Download: ' + dt)
continue
handler.write(content.getvalue())
print('Downloaded: `{0}` of {1}'.format(ext, dt))
if __name__ == '__main__':
download()