Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

Report report error,help



  • http://www.openerp.com/forum/topic21552.html<br /><br />I need to print a report,below is the code,but Run Error<br />error(debug_rpc):<br />[2010-12-27 22:51:03,375][?] Level 9:service:'report'<br />[2010-12-27 22:51:03,375][?] Level 9:method:'report'<br />[2010-12-27 22:51:03,375][?] Level 9:params:[01]: ('retail_demo',<br />[2010-12-27 22:51:03,375][?] Level 9:params:[02]: 1,<br />[2010-12-27 22:51:03,375][?] Level 9:params:[03]: 'admin',<br />[2010-12-27 22:51:03,375][?] Level 9:params:[04]: u'report.sale.order.product.2',<br />[2010-12-27 22:51:03,390][?] Level 9:params:[05]: [1, 2, 3, 4, 99999999],<br />[2010-12-27 22:51:03,390][?] Level 9:params:[06]: {'context': {},<br />[2010-12-27 22:51:03,390][?] Level 9:params:[07]: 'id': 1,<br />[2010-12-27 22:51:03,390][?] Level 9:params:[08]: 'model': 'report.sale.order.product.2',<br />[2010-12-27 22:51:03,390][?] Level 9:params:[09]: 'report_type': 'pdf'},<br />[2010-12-27 22:51:03,390][?] Level 9:params:[10]: {'client': 'web', 'lang': u'zh_CN', 'tz': False})<br />[2010-12-27 22:51:03,390][?] Level 9:result:2<br />[2010-12-27 22:51:03,390][?] Level 9:service:'report'<br />[2010-12-27 22:51:03,390][?] Level 9:method:'report_get'<br />[2010-12-27 22:51:03,390][?] Level 9:params:('retail_demo', 1, 'admin', 2)<br />[2010-12-27 22:51:03,390][?] Level 9:result:{'state': False}<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[01]:<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[02]: Environment Information :<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[03]: System : Windows-XP-5.1.2600-SP3<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[04]: OS Name : nt<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[05]: Operating System Release : XP<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[06]: Operating System Version : 5.1.2600<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[07]: Operating System Architecture : 32bit<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[08]: Operating System Locale : zh_CN.cp936<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[09]: Python Version : 2.5.2<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[10]: OpenERP-Server Version : 5.0.15<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[11]: Last revision No. & ID :<br />[2010-12-27 22:51:03,562][retail_demo] ERROR:module:[12]: This service does not exists: u'report.report.sale.order.product.2'<br />[2010-12-27 22:51:03,703][retail_demo] ERROR:web-services:[01]:<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[02]: Environment Information :<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[03]: System : Windows-XP-5.1.2600-SP3<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[04]: OS Name : nt<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[05]: Operating System Release : XP<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[06]: Operating System Version : 5.1.2600<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[07]: Operating System Architecture : 32bit<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[08]: Operating System Locale : zh_CN.cp936<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[09]: Python Version : 2.5.2<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[10]: OpenERP-Server Version : 5.0.15<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[11]: Last revision No. & ID :<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[12]: Exception: u'report.report.sale.order.product.2'<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[13]: Traceback (most recent call last):<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[14]: File "service\web_services.pyo", line 682, in go<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[15]: File "netsvc.pyo", line 70, in init<br />[2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[16]: KeyError: u'report.report.sale.order.product.2'<br /><br />error code web_service.py<br /><br />def go(id, uid, ids, datas, context):<br />cr = pooler.get_db(db).cursor()<br />import traceback<br />import sys<br />try:<br />obj = netsvc.LocalService('report.'+object)<br /><br /><br />code:<br />model,<br /><br />import string<br />import sys<br />import netsvc<br /><br />from osv import fields,osv<br /><br />class report_report_sale_order_product_2(osv.osv):<br />_name = "report.report.sale.order.product.2"<br />_description = "Sales Orders by Products"<br />_auto = True<br />_columns = {<br />'memo': fields.char(u'说明', size=64,readonly=True),<br />'month': fields.date('月份', readonly=True),<br />'product_name':fields.char(u'产品名称',size=128, readonly=True),<br />'quantity': fields.float('销售数量', readonly=True),<br />'price_total': fields.float('销售金额', readonly=True),<br />'price_average': fields.float('平均售价', readonly=True)<br />}<br />report_report_sale_order_product_2()<br /><br />class report_sale_order_product_2(osv.osv):<br />_name = "report.sale.order.product.2"<br />_description = "Sales Orders by Products"<br />_auto = False<br />_columns = {<br />'memo': fields.char(u'说明', size=64,readonly=True),<br />'month': fields.date('月份', readonly=True),<br />'product_name':fields.char(u'产品名称',size=128, readonly=True),<br />'quantity': fields.float('销售数量', readonly=True),<br />'price_total': fields.float('销售金额', readonly=True),<br />'price_average': fields.float('平均售价', readonly=True)<br />}<br />_order = 'id,month desc,product_name'<br />def init(self, cr):<br />cr.execute("""<br />create or replace view report_sale_order_product_2 as (<br />select<br />min(b.id) as id,<br />' ' as memo,<br />to_char(a.date_order, 'YYYY-MM-01') as month,<br />e.name as product_name,<br />sum(b.product_uom_qtyu.factor) as quantity,<br />sum(b.product_uom_qtyb.price_unit) as price_total,<br />(sum(b.product_uom_qtyb.price_unit)/sum(b.product_uom_qtyu.factor))::decimal(16,2) as price_average<br />from sale_order a right join sale_order_line b on (a.id=b.order_id)<br />left join product_uom u on (u.id=b.product_uom)<br />left join product_product d on (b.product_id=d.id)<br />left join product_template e on (d.product_tmpl_id=e.id)<br />group by to_char(a.date_order, 'YYYY-MM-01'),product_name ) """<br />)<br /><br />def search(self, cr, user, args, offset=0, limit=None, order=None,<br />context=None, count=False):<br />if not context:<br />context = {}<br /><br />filter=""<br />logger = netsvc.Logger()<br />logger.notifyChannel('app', netsvc.LOG_ERROR, args)<br />firstflag=True<br />for arg in args:<br />afield=arg[0]<br />if arg[0]=="product_name":<br />afield="e.name"<br />if arg[0]=="month":<br />afield="to_char(a.date_order, 'YYYY-MM-01')"<br /><br />if firstflag:<br />filter+=afield+" "+arg[1]+" '"+str(arg[2])+"' "<br />firstflag=False<br />else:<br />filter+=" and "+afield+" "+arg[1]+" '"+str(arg[2])+"' "<br />if len(filter)>0:<br />wherestr=" where "<br />else:<br />wherestr=" "<br />try:<br />cr.execute("""drop view report_sale_order_product_2 """)<br />except TypeError :<br />pass<br /><br />sql="create or replace view report_sale_order_product_2 as ( <br />select <br />min(b.id) as id, <br />' ' as memo, <br />to_char(a.date_order, 'YYYY-MM-01') as month,<br />e.name as product_name,<br />sum(b.product_uom_qtyu.factor) as quantity, <br />sum(b.product_uom_qtyb.price_unit) as price_total, <br />(sum(b.product_uom_qtyb.price_unit)/sum(b.product_uom_qtyu.factor))::decimal(16,2) as price_average <br />from sale_order a right join sale_order_line b on (a.id=b.order_id) <br />left join product_uom u on (u.id=b.product_uom) <br />left join product_product d on (b.product_id=d.id) <br />left join product_template e on (d.product_tmpl_id=e.id) "<br />+wherestr+filter +" group by to_char(a.date_order, 'YYYY-MM-01'),product_name <br />union all <br />select <br />99999999 as id, <br />'合计' as memo,<br />min(to_char(a.date_order, 'YYYY-MM-01')) as month,<br />' ' as product_name,<br />sum(b.product_uom_qtyu.factor) as quantity, <br />sum(b.product_uom_qtyb.price_unit) as price_total, <br />(sum(b.product_uom_qtyb.price_unit)/sum(b.product_uom_qtyu.factor))::decimal(16,2) as price_average <br />from sale_order a right join sale_order_line b on (a.id=b.order_id) <br />left join product_uom u on (u.id=b.product_uom) <br />left join product_product d on (b.product_id=d.id) <br />left join product_template e on (d.product_tmpl_id=e.id) "<br />+wherestr + filter + " ) "<br /><br /><br />logger.notifyChannel('app', netsvc.LOG_ERROR, sql)<br />print sql<br />cr.execute(sql)<br /><br />cr.execute("""<br />select * from report_sale_order_product_2 order by id,month desc,product_name<br />""")<br /><br />res = cr.fetchall()<br /><br />return [x[0] for x in res]<br /><br />report_sale_order_product_2()<br /><br />report:<br /><br />import pooler<br />import time<br />from report import report_sxw<br /><br /><br />class glass_saleorder_product_2(report_sxw.rml_parse):<br /><br />def init(self, cr, uid, name, context):<br />super(glass_saleorder_product_2, self).init(cr, uid, name, context)<br />self.ret_list = []<br /><br />self.localcontext.update({<br />'time': time,<br />'rpt_datas':self.create_sum_data<br />})<br /><br />def create_sum_data(self):<br /><br />cr=pooler.get_db(self.cr.dbname).cursor()<br />cr.execute(<br />"select * from report_sale_order_product_2 " )<br /><br />sum_lines = cr.dictfetchall()<br /><br />for line in sum_lines:<br />ret_dict={<br />'memo':line['memo'],<br />'month':line['month'],<br />'product_name':line['product_name'],<br />'quantity':line['quantity'],<br />'price_total':line['price_total'],<br />'price_average':line['price_average']<br />}<br />self.ret_list.append(ret_dict)<br /><br />return self.ret_list<br /><br /><br />report_sxw.report_sxw('report.report.sale.order.product.2', 'report.sale.order.product.2',<br />'addons/report_sale_xlscan/report/rpt_sale_product_2.rml',<br />parser=glass_saleorder_product_2, header=False)<br /><br /><br />report xml:<br /><br /><?xml version="1.0" encoding="utf-8"?><br /><openerp><br /><data><br /><report auto="False" id="report_report_sale_order_product_2" model="report.sale.order.product.2" name="report.sale.order.product.2" rml="report_sale_xlscan/report/rpt_sale_product_2.rml" string="打印报表" header="False"/><br /></data><br /></openerp<br /><br /><br />Please Help me.<br />



  • 看看你的 模块里, 有没有 import 你的 report<br /><br />模块_init_.py<br /><br />中<br /><br />添加<br />import report<br /><br /><br />然后 你的 <br />模块\report_init_.py 中, 引用你的 report python script.


  • 管理员

    [quote author=chengwenge link=topic=2260.msg7296#msg7296 date=1293502754]<br /> http://www.openerp.com/forum/topic21552.html <br /><br /><br />report_sxw.report_sxw('[color=#ff0000]report.report.sale.order.product.2[/color]', 'report.sale.order.product.2',<br />'addons/report_sale_xlscan/report/rpt_sale_product_2.rml',<br />parser=glass_saleorder_product_2, header=False)<br /><br /><br />report xml:<br /><br /><?xml version="1.0" encoding="utf-8"?><br /><openerp><br /><data><br /><report auto="False" id="report_report_sale_order_product_2" model="report.sale.order.product.2" name="[color=#ff0000]report.sale.order.product.2[/color]" rml="report_sale_xlscan/report/rpt_sale_product_2.rml" string="打印报表" header="False"/><br /></data><br /></openerp<br /><br /><br />Please Help me.<br />[/quote]<br /><br /><br />红色标记的地方使用的名称不一致,将xml中改成'report.report.sale.order.product.2'试试



  • xml 中的 name 好象不需要 "report." 前缀的. <br /><br />例如:<br />

    <br />addons\account\report\general_ledger.py<br />...<br />report_sxw.report_sxw(&#039;report.account.general.ledger&#039;, &#039;account.account&#039;, &#039;addons/account/report/general_ledger.rml&#039;, parser=general_ledger, header=False)<br />...<br /><br />addons\account\account_report.xml<br /><br />...<br /><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;report auto=&quot;False&quot; id=&quot;account_general_ledger&quot; menu=&quot;False&quot; model=&quot;account.account&quot; name=&quot;account.general.ledger&quot; rml=&quot;account/report/general_ledger.rml&quot; string=&quot;General Ledger&quot;/&gt;<br /><br />...<br /><br />
    


  • 我做成功过好几个报表,不过都是单据。<br />我这次实行的是对报表的打印,报表的模型不是自动建立,通过视图实现的模式。<br /><br />跟踪了下,还是不知道如何解决。我看了代码,系统会自动增加 report.object<br /><br />web_service.py<br /><br />        def go(id, uid, ids, datas, context):<br />            cr = pooler.get_db(db).cursor()<br />            import traceback<br />            import sys<br />            try:<br />                obj = netsvc.LocalService('report.'+object)<br /><br /><br />



  • 不太理解. 我觉得你可以先化繁为简, 先做一个 test 的报表, 然后 一点点儿地向上加东西.<br /><br />你也可以把源码打个包发上来大家看一下.



  • mrshelly 二楼回答是正解。<br /><br />我在 report/init.py  不正确,需要 import report目录下的所有 py文件。<br />靠,确实走了弯路,谢谢大家。<br /><br />


  • 管理员

    感谢Mrshelly, 纠正了我一个错误,report标签确实不需要再添加report前缀了