跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. Report report error,help

Report report error,help

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
9 帖子 3 发布者 8.0k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • C 离线
    C 离线
    chengwenge
    写于 最后由 编辑
    #1

    http://www.openerp.com/forum/topic21552.html

    I need to print a report,below is the code,but Run Error
    error(debug_rpc):
    [2010-12-27 22:51:03,375][?] Level 9:service:'report'
    [2010-12-27 22:51:03,375][?] Level 9:method:'report'
    [2010-12-27 22:51:03,375][?] Level 9:params:[01]: ('retail_demo',
    [2010-12-27 22:51:03,375][?] Level 9:params:[02]: 1,
    [2010-12-27 22:51:03,375][?] Level 9:params:[03]: 'admin',
    [2010-12-27 22:51:03,375][?] Level 9:params:[04]: u'report.sale.order.product.2',
    [2010-12-27 22:51:03,390][?] Level 9:params:[05]: [1, 2, 3, 4, 99999999],
    [2010-12-27 22:51:03,390][?] Level 9:params:[06]: {'context': {},
    [2010-12-27 22:51:03,390][?] Level 9:params:[07]: 'id': 1,
    [2010-12-27 22:51:03,390][?] Level 9:params:[08]: 'model': 'report.sale.order.product.2',
    [2010-12-27 22:51:03,390][?] Level 9:params:[09]: 'report_type': 'pdf'},
    [2010-12-27 22:51:03,390][?] Level 9:params:[10]: {'client': 'web', 'lang': u'zh_CN', 'tz': False})
    [2010-12-27 22:51:03,390][?] Level 9:result:2
    [2010-12-27 22:51:03,390][?] Level 9:service:'report'
    [2010-12-27 22:51:03,390][?] Level 9:method:'report_get'
    [2010-12-27 22:51:03,390][?] Level 9:params:('retail_demo', 1, 'admin', 2)
    [2010-12-27 22:51:03,390][?] Level 9:result:{'state': False}
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[01]:
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[02]: Environment Information :
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[03]: System : Windows-XP-5.1.2600-SP3
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[04]: OS Name : nt
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[05]: Operating System Release : XP
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[06]: Operating System Version : 5.1.2600
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[07]: Operating System Architecture : 32bit
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[08]: Operating System Locale : zh_CN.cp936
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[09]: Python Version : 2.5.2
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[10]: OpenERP-Server Version : 5.0.15
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[11]: Last revision No. & ID :
    [2010-12-27 22:51:03,562][retail_demo] ERROR:module:[12]: This service does not exists: u'report.report.sale.order.product.2'
    [2010-12-27 22:51:03,703][retail_demo] ERROR:web-services:[01]:
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[02]: Environment Information :
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[03]: System : Windows-XP-5.1.2600-SP3
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[04]: OS Name : nt
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[05]: Operating System Release : XP
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[06]: Operating System Version : 5.1.2600
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[07]: Operating System Architecture : 32bit
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[08]: Operating System Locale : zh_CN.cp936
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[09]: Python Version : 2.5.2
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[10]: OpenERP-Server Version : 5.0.15
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[11]: Last revision No. & ID :
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[12]: Exception: u'report.report.sale.order.product.2'
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[13]: Traceback (most recent call last):
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[14]: File "service\web_services.pyo", line 682, in go
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[15]: File "netsvc.pyo", line 70, in init
    [2010-12-27 22:51:03,717][retail_demo] ERROR:web-services:[16]: KeyError: u'report.report.sale.order.product.2'

    error code web_service.py

    def go(id, uid, ids, datas, context):
    cr = pooler.get_db(db).cursor()
    import traceback
    import sys
    try:
    obj = netsvc.LocalService('report.'+object)


    code:
    model,

    import string
    import sys
    import netsvc

    from osv import fields,osv

    class report_report_sale_order_product_2(osv.osv):
    _name = "report.report.sale.order.product.2"
    _description = "Sales Orders by Products"
    _auto = True
    _columns = {
    'memo': fields.char(u'说明', size=64,readonly=True),
    'month': fields.date('月份', readonly=True),
    'product_name':fields.char(u'产品名称',size=128, readonly=True),
    'quantity': fields.float('销售数量', readonly=True),
    'price_total': fields.float('销售金额', readonly=True),
    'price_average': fields.float('平均售价', readonly=True)
    }
    report_report_sale_order_product_2()

    class report_sale_order_product_2(osv.osv):
    _name = "report.sale.order.product.2"
    _description = "Sales Orders by Products"
    _auto = False
    _columns = {
    'memo': fields.char(u'说明', size=64,readonly=True),
    'month': fields.date('月份', readonly=True),
    'product_name':fields.char(u'产品名称',size=128, readonly=True),
    'quantity': fields.float('销售数量', readonly=True),
    'price_total': fields.float('销售金额', readonly=True),
    'price_average': fields.float('平均售价', readonly=True)
    }
    _order = 'id,month desc,product_name'
    def init(self, cr):
    cr.execute("""
    create or replace view report_sale_order_product_2 as (
    select
    min(b.id) as id,
    ' ' as memo,
    to_char(a.date_order, 'YYYY-MM-01') as month,
    e.name as product_name,
    sum(b.product_uom_qtyu.factor) as quantity,
    sum(b.product_uom_qty
    b.price_unit) as price_total,
    (sum(b.product_uom_qtyb.price_unit)/sum(b.product_uom_qtyu.factor))::decimal(16,2) as price_average
    from sale_order a right join sale_order_line b on (a.id=b.order_id)
    left join product_uom u on (u.id=b.product_uom)
    left join product_product d on (b.product_id=d.id)
    left join product_template e on (d.product_tmpl_id=e.id)
    group by to_char(a.date_order, 'YYYY-MM-01'),product_name ) """
    )

    def search(self, cr, user, args, offset=0, limit=None, order=None,
    context=None, count=False):
    if not context:
    context = {}

    filter=""
    logger = netsvc.Logger()
    logger.notifyChannel('app', netsvc.LOG_ERROR, args)
    firstflag=True
    for arg in args:
    afield=arg[0]
    if arg[0]=="product_name":
    afield="e.name"
    if arg[0]=="month":
    afield="to_char(a.date_order, 'YYYY-MM-01')"

    if firstflag:
    filter+=afield+" "+arg[1]+" '"+str(arg[2])+"' "
    firstflag=False
    else:
    filter+=" and "+afield+" "+arg[1]+" '"+str(arg[2])+"' "
    if len(filter)>0:
    wherestr=" where "
    else:
    wherestr=" "
    try:
    cr.execute("""drop view report_sale_order_product_2 """)
    except TypeError :
    pass

    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 + " ) "


    logger.notifyChannel('app', netsvc.LOG_ERROR, sql)
    print sql
    cr.execute(sql)

    cr.execute("""
    select * from report_sale_order_product_2 order by id,month desc,product_name
    """)

    res = cr.fetchall()

    return [x[0] for x in res]

    report_sale_order_product_2()

    report:

    import pooler
    import time
    from report import report_sxw


    class glass_saleorder_product_2(report_sxw.rml_parse):

    def init(self, cr, uid, name, context):
    super(glass_saleorder_product_2, self).init(cr, uid, name, context)
    self.ret_list = []

    self.localcontext.update({
    'time': time,
    'rpt_datas':self.create_sum_data
    })

    def create_sum_data(self):

    cr=pooler.get_db(self.cr.dbname).cursor()
    cr.execute(
    "select * from report_sale_order_product_2 " )

    sum_lines = cr.dictfetchall()

    for line in sum_lines:
    ret_dict={
    'memo':line['memo'],
    'month':line['month'],
    'product_name':line['product_name'],
    'quantity':line['quantity'],
    'price_total':line['price_total'],
    'price_average':line['price_average']
    }
    self.ret_list.append(ret_dict)

    return self.ret_list


    report_sxw.report_sxw('report.report.sale.order.product.2', 'report.sale.order.product.2',
    'addons/report_sale_xlscan/report/rpt_sale_product_2.rml',
    parser=glass_saleorder_product_2, header=False)


    report xml:

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
    <data>
    <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"/>
    </data>
    </openerp


    Please Help me.

    1 条回复 最后回复
    0
    • mrshellyM 离线
      mrshellyM 离线
      mrshelly
      写于 最后由 编辑
      #2

      看看你的 模块里, 有没有 import 你的 report

      模块_init_.py

      中

      添加
      import report


      然后 你的
      模块\report_init_.py 中, 引用你的 report python script.

      1 条回复 最后回复
      0
      • digitalsatoriD 离线
        digitalsatoriD 离线
        digitalsatori 管理员
        写于 最后由 编辑
        #3

        [quote author=chengwenge link=topic=2260.msg7296#msg7296 date=1293502754]
        http://www.openerp.com/forum/topic21552.html


        report_sxw.report_sxw('[color=#ff0000]report.report.sale.order.product.2[/color]', 'report.sale.order.product.2',
        'addons/report_sale_xlscan/report/rpt_sale_product_2.rml',
        parser=glass_saleorder_product_2, header=False)


        report xml:

        <?xml version="1.0" encoding="utf-8"?>
        <openerp>
        <data>
        <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"/>
        </data>
        </openerp


        Please Help me.
        [/quote]


        红色标记的地方使用的名称不一致,将xml中改成'report.report.sale.order.product.2'试试

        【上海先安科技】(tony AT openerp.cn)

        1 条回复 最后回复
        0
        • mrshellyM 离线
          mrshellyM 离线
          mrshelly
          写于 最后由 编辑
          #4

          xml 中的 name 好象不需要 "report." 前缀的.

          例如:

          <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 />
          
          1 条回复 最后回复
          0
          • C 离线
            C 离线
            chengwenge
            写于 最后由 编辑
            #5

            我做成功过好几个报表,不过都是单据。
            我这次实行的是对报表的打印,报表的模型不是自动建立,通过视图实现的模式。

            跟踪了下,还是不知道如何解决。我看了代码,系统会自动增加 report.object

            web_service.py

                    def go(id, uid, ids, datas, context):
                        cr = pooler.get_db(db).cursor()
                        import traceback
                        import sys
                        try:
                            obj = netsvc.LocalService('report.'+object)


            1 条回复 最后回复
            0
            • mrshellyM 离线
              mrshellyM 离线
              mrshelly
              写于 最后由 编辑
              #6

              不太理解. 我觉得你可以先化繁为简, 先做一个 test 的报表, 然后 一点点儿地向上加东西.

              你也可以把源码打个包发上来大家看一下.

              1 条回复 最后回复
              0
              • C 离线
                C 离线
                chengwenge
                写于 最后由 编辑
                #7

                mrshelly 二楼回答是正解。

                我在 report/init.py  不正确,需要 import report目录下的所有 py文件。
                靠,确实走了弯路,谢谢大家。

                1 条回复 最后回复
                0
                • digitalsatoriD 离线
                  digitalsatoriD 离线
                  digitalsatori 管理员
                  写于 最后由 编辑
                  #8

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

                  【上海先安科技】(tony AT openerp.cn)

                  1 条回复 最后回复
                  0

                  • 登录

                  • 没有帐号? 注册

                  • 登录或注册以进行搜索。
                  • 第一个帖子
                    最后一个帖子
                  0
                  • 版块
                  • 标签
                  • 热门
                  • 用户
                  • 群组