Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

wizard report error __new__() takes exactly 1 argument (2 given)

By
gpkarthick
on 5/8/13, 7:30 AM 3,085 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"/>

Which version of OpenERP are you using?

Sudhir Arya (SA)
on 5/8/13, 8:41 AM

openerp 7.0

gpkarthick
on 5/8/13, 8:44 AM
1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 5/8/13, 8:51 AM

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.

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')}, }

gpkarthick
on 5/8/13, 9:41 AM

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)

gpkarthick
on 5/8/13, 9:43 AM

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

gpkarthick
on 5/8/13, 9:44 AM

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

Sudhir Arya (SA)
on 5/8/13, 9:46 AM

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

gpkarthick
on 5/9/13, 7:42 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/8/13, 7:30 AM
Seen: 3085 times
Last updated: 3/16/15, 8:10 AM