Report Issue in OpenERP v7

Question:

I’m making a new report, from OpenOffice with base_report_designer module, on product object.

Everything seems ok, but everytime I try to print it, it throws this error:

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

This usually happens when you actually ‘save’ the document instead of sending to the server, but i’m not doing that, i’m using a parser made by me, using product.product model, and it should work, this is my parser:

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

And my report (sxw format, it has an .rml version):

[[ 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'] ]]

Can’t figure it out, it should loop on product I don’t get it, any ideas?

Asked By: NeoVe

||

Answers:

o is a object of Product. You can get value of product for example [[ o. name_template ]] it will return product name.

You are trying to use [[ o.product ]] but in product.product object their is no field name product

repeatIn is used for looping in RML for example you have to list of record (one2many field) and here is syntax.

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

For repeatIn, you need to have list of object (one2many) and than it will get value properly.

Answered By: Bhavesh Odedra