2014-11-05 90 views
0

我正在做一個新的報告,從OpenOffice base_report_designer模塊,在product對象。報告問題在OpenERP v7

一切似乎都不錯,但每次我嘗試打印,它拋出這個錯誤:

Field 'product' does not exist in object 'browse_record(product.product, 12)' 

(<type 'exceptions.AttributeError'>, AttributeError(KeyError("Field 'product' does not exist in object 'browse_record(product.product, 12)'",),), <traceback object at 0xc2801e4>) 

當你真正「拯救」而不是發送到服務器的文檔這通常發生,但我不這樣做,我使用我做的解析器,使用product.product模型,它應該工作,這是我的解析器:

import time 
from openerp.report import report_sxw 
class reporte_locacion(report_sxw.rml_parse): 
def __init__(self, cr, uid, name, context): 
    super(reporte_locacion, self).__init__(cr, uid, name, context=context) 
    self.localcontext.update({ 
     'time': time, 
     'qty_total':self._qty_total 
    }) 

def _qty_total(self, objects): 
    total = 0.0 
    uom = objects[0].product_uom.name 
    for obj in objects: 
     total += obj.product_qty 
    return {'quantity':total,'uom':uom} 


report_sxw.report_sxw(
'report.reporte.locacion', 
'product.product', 
'addons/stock/report/reporte_locacion.rml', 
parser=reporte_locacion, 
header='internal' 
) 

而且我的報告(格式SXW,它有一個.rml版):

[[ repeatIn(objects,'o') ]] 
Stock Inventory 

Inventory 
Date 
[[ o.name ]] 
[[ formatLang(o.date,date_time=True) ]] 

Location 
Production Lot 
Product 
Quantity 
[[ repeatIn(o.product, 'p') ]] 
[[ p.location_id.name ]] 
[[ p.prod_lot_id and p.prod_lot_id.name or '' ]] 
[ [[ p.product_id.code ]] ] [[ p.product_id.name ]] 
[[ formatLang(p.product_qty) ]] [[ p.product_uom.name ]] 

Total: 
[[ formatLang(qty_total(o.inventory_line_id)['quantity']) ]] [[ qty_total(o.inventory_line_id)['uom'] ]] 

想不通,應該循環上product我不明白,有什麼想法嗎?

如果您需要進一步的解釋,請讓我知道,謝謝!

回答

1

o是Product的一個對象。您可以獲得產品的價值,例如[[o。 name_template]]它會返回產品名稱。

您正在嘗試使用[[o.product]但在product.product對象他們是沒有字段名產品

repeatIn被用於RML循環例如你要的名單記錄(one2many字段),這裏是語法。

[[ repeatIn(o.one2many_field_name, 'p') ]] 

對於repeatIn,你需要有對象(one2many)的名單和比它會得到價值正常。

希望這會幫助你。

+0

非常感謝!看起來非常合乎邏輯,是的,現在就試試吧! – NeoVe 2014-11-06 14:52:12

+0

是的,你說的沒錯,那就是要走的路,然後我會創造一些關係來完成我的工作!非常感謝你! – NeoVe 2014-11-06 16:24:25