Skip to Content
Menu
This question has been flagged
1 Reply
7858 Views

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"/>

Avatar
Discard

Which version of OpenERP are you using?

Author

openerp 7.0

Best Answer

This won't work. This style was used for `wizard.interface` in prior version. But version 7 does not support it. You should convert it into wizard (osv_memory or TransientModel).

How to convert interface into wizard in this link I have given then steps to convert interface into wizard.

Avatar
Discard
Author

my_form = '''<?xml version="1.0"?> <form string="Category Summary"> <group colspan="4"> <button name="check" type="object"/> </group> </form>''' my_fields = { 'date': {'string':'From Date', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')}, }

Author

class wizard_report(osv.TransientModel): _columns = { 'date': fields.date('Date'), } states = { 'init': { 'actions': [], 'result': {'type':'form', 'arch':my_form, 'fields':my_fields, 'state':[('check','Print'),('end','Cancel')]} },
'report': { 'actions': [], 'result': {'type':'print', 'report':'crm_target_report', 'state':'end'} } } wizard_report('crm_target_report')

if i use your code ---> wizard_report('crm_target_report') TypeError: __new__() takes exactly 1 argument (2 given)

Author

send your email id i will send my code you can view easier my Email ID is gpkopenerp@gmail.com

I have already review your code and I explained you what to do. Just follow the steps to convert wizard.

Author

I have table fields are Employee Name, Target, duration.. in that table all the employee name(the person who is from sale department) from the he.employee table should automatically come to my field Employee name how to do that advance thanks....

and how to use this from default_get function and i am trying menu print wizard report but still i did not get any correct output