Search code examples
pythonreportodooerprml

Add multiple objects in OpenERP report


How would one go about passing multiple objects to the reporting engine?

I'm trying to create a custom Invoice report where I need to attach data from other application to be displayed on the invoice. I can get the data into OpenERP server using Web Services but how do I pass it to the reporting engine? Perhaps the

set_context or (self.localcontext.update())

method will be useful here as it allows me to pass custom variables to the report but how would one pass a whole object.

What I'm importing from other application is essentially a massive table with potentially 100's of records that are related to the current partner, I don't need to save it in OpenERP database, simply display it while generating an invoice.

EDIT:

To test the object I have in the parser

class test_invoice(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
    super(test_invoice, self).__init__(cr, uid, name, context=context)
    self.localcontext.update({
        'time': time,
        'test_var': 'Worked!',
        'get_list': self._get_list,
    })


def _get_list(self):
    result = []
    ress = {'first': '1',
        'second': '2',
        }
    result.append(ress)
    return result

and in the rml file

...start of rml file
     <section>
        <para>
            [[ repeatIn(get_list(), 'g')]]
            [[ g.first ]]
        </para>
    </section>

  </story>
</document>

but this throws an error "coercing to Unicode: need string or buffer, tuple found". How can we display a custom list in rml?

Thank You.


Solution

  • you can pass whole objects as far as OpenERP (well, the python you run OpenERP with) knows about that object. Otherwise you have to 'proxy' the object is some manner. Using SQLAlchemy for fetching data from the external db could be an handful solution. You could hand with something like that:

    [...somewhere into your parser...]
    self.localcontext.update({'external_rows': session.query(MyObject).filter_by(foo='baz')})
    

    or if you are managing CSV data:

    self.localcontext.updarte({'external_rows': self._get_myrows_from_csv()})
    

    where _get_myrows_from_csv returns a list of dictionaries for instance.