Skip to content

Instantly share code, notes, and snippets.

@tinogis
Last active January 21, 2019 18:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tinogis/cec4596ca6a846f16b39 to your computer and use it in GitHub Desktop.
Save tinogis/cec4596ca6a846f16b39 to your computer and use it in GitHub Desktop.
Get and view an erp5 pdf report from command line
from erppeek import Client
import sys
import base64
from subprocess import call
import time
#report = 'giscedata.facturacio.factura'
#ids = [1513047, 1513049, 1513057, 1513042]
#ids = [1513042]
report = 'account.general.ledger.cumulative'
ids = [1703] # 572000000002
start_date = '2018-01-01'
end_date = '2018-07-24'
fiscal_year = 10 # '2018'
state = 'none' # 'none' tots , 'bydate': per dates
params = {
'report_type': 'pdf',
'form': {
'sortbydate': 'sort_date',
'periods': [[6, 0, []]],
'date_to': end_date,
'landscape': False,
'initial_balance': False,
'date_from': start_date,
'company_id': 1,
'state': state,
'context': {
'lang': 'ca_ES',
'active_ids': [158],
'tz': 'Europe/Madrid',
'active_id': 158
},
'amount_currency': False,
'display_account': 'bal_mouvement',
'fiscalyear': 2},
'model': 'account.account',
'report_id': False,
'id': ids[0]
}
O = Client('http://localhost:8069', 'database','user','pass')
#report_id = O.report(report, ids)
report_id = O.report(report, ids, params, {'lang': 'ca_ES', 'tz': 'Europe/Madrid'})
sys.stdout.write("Waiting")
res = {'state': False}
while not res['state']:
res = O.report_get(report_id)
sys.stdout.write(".")
time.sleep(0.2)
sys.stdout.flush()
sys.stdout.write("\n")
with open('report.pdf','w') as f:
f.write(base64.b64decode(res['result']))
call(['evince', 'report.pdf'])
from erppeek import Client
import sys
import base64
from subprocess import call
import time
#report = 'giscedata.facturacio.factura'
#ids = [1513047, 1513049, 1513057, 1513042]
#ids = [1513042]
report = 'account.balance.full'
ids = account_list = [1703] # 572000000002
start_date = '2018-01-01'
end_date = '2018-01-31'
fiscal_year = 10 # '2018'
state = 'none' # 'none' tots , 'bydate': per dates
level = 0
params = {
'report_type': 'pdf',
'form': {
'company_id': 1,
'account_list': [[6,0,account_list]],
'state': state,
'fiscalyear': fiscal_year,
'periods': [[6, 0, []]],
'display_account': 'bal_mouvement',
'display_account_level': level,
'date_from': start_date,
'date_to': end_date,
'context': {
'lang': 'ca_ES',
'active_ids': [158],
'tz': 'Europe/Madrid',
'active_id': 158
},
},
'model': 'account.account',
'report_id': False,
'id': ids[0]
}
O = Client('http://localhost:8069', 'database','user','pass')
#report_id = O.report(report, ids)
report_id = O.report(report, ids, params, {'lang': 'ca_ES', 'tz': 'Europe/Madrid'})
sys.stdout.write("Waiting")
res = {'state': False}
while not res['state']:
res = O.report_get(report_id)
sys.stdout.write(".")
time.sleep(0.2)
sys.stdout.flush()
sys.stdout.write("\n")
with open('report.pdf','w') as f:
f.write(base64.b64decode(res['result']))
call(['evince', 'report.pdf'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment