Report ptthon file import time from report import report_sxw from osv import osv import pooler import datetime from operator import itemgetter
class crm_target_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
super(crm_target_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'get_name':self.get_name,
})
def get_name(self,form):
sql="""select he.name_related,
he.lead_target, count(cl.user_id) as achieved, round(((cast(count(cl.user_id) as decimal(2))/he.lead_target)*100)) as val from crm_lead cl, hr_employee he, res_users rs, resource_resource rr where cl.type='opportunity' and rr.id=he.resource_id and rs.id=rr.user_id and rs.id=cl.user_id and date_open>='%s' and date_open<=now() + interval '7 days' group by he.name_related, he.lead_target """ %(form['date']) self.cr.execute(sql) res = self.cr.dictfetchall() #print res return res
report_sxw.report_sxw('report.leadsales_target.weeklytargetreport','crm.lead','addons/leadsales_target/report/crm_target_report.rml',parser=crm_target_report,header="external") wizard Python Fileimport time import datetime import pooler from osv import osv,fields from mx.DateTime import * from tools.translate import _ import StringIO import cStringIO import base64 import csv import pprint
def _calc_dates(self, cr, uid, data, context):
part = (fields.char(data['form']['date'],"%s"))
if part is None:
raise wizard.except_wizard(('No data!'),('Not fill the datas'))
k={}
k={'date':data['form']['date']}
return k
def get_name(cr,uid,form):
partner_obj = pooler.get_pool(cr.dbname).get('product.product')
inv_obj = pooler.get_pool(cr.dbname).get('project.design.worksheet')
sql="""select he.name_related,
he.lead_target,
count(cl.user_id) as achieved,
round(((cast(count(cl.user_id) as decimal(2))/he.lead_target)*100)) as val
from crm_lead cl,
hr_employee he,
res_users rs,
resource_resource rr
where cl.type='opportunity' and rr.id=he.resource_id and
rs.id=rr.user_id and rs.id=cl.user_id and date_open>='%s' and date_open<=now() + interval '7 days'
group by he.name_related, he.lead_target
""" %(form['date'])
#print sql
cr.execute(sql)
#l = self.cr.dictfetchall()
#print type(l),"TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
#aml.partner_id is not null and partner.id=aml.partner_id and
res = cr.dictfetchall()
print res
return res
view_form_finish=""" <form string="Export to Excel Report"> <image name="gtk-dialog-info" colspan="2"/> <group colspan="2" col="4"> <separator string="Export to Excel Report" colspan="4"/> <field name="file_stream" readonly="1" colspan="3" filename="file_name"/> <label string="Save this document to a .XLS file and open it with\n Excel." colspan="4"/> </group> </form>"""
finish_fields={
'file_stream': {'string':'File Stream', 'type':'binary', 'readonly': True,},
'file_name':{'string':'File Name', 'type':'char'}
}
dates_form = '''
<form string="Select period">
<field name="date"/>
</form>'''
dates_fields = {
'date': {'string':'Date', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
class wizard_report(osv.TransientModel):
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('report','Print'),('end','Cancel')]}
},
'next': {
'result': {'type':'form',
'arch':view_form_finish,
'fields':finish_fields,
'state':[('end','Cancel')] }
},
'report': {
'actions': [_calc_dates],
'result': {'type':'print', 'report':'crm_target_report', 'state':'end'}
}
}
wizard_report('leadsales_target.weeklytargetreport')--->Here I got error wizard_report('leadsales_target.weeklytargetreport') TypeError: __new__() takes exactly 1 argument (2 given) Report XML file <wizard id="crm_target_report_wizard_menu" menu="False" model="crm.lead" name="leadsales_target.weeklytargetreport" string="Terget report"/> <menuitem icon="STOCK_PRINT" name="GPK Target" action="crm_target_report_wizard_menu" id="menu_crmleadtarget" parent="base.menu_sales" type="wizard"/>
Which version of OpenERP are you using?
openerp 7.0