Odoo Help


KeyError: "Field '0' does not exist in object 'browse_record(pos.order, 8)'"

Tomas Parnarauskas
on 5/22/13, 8:53 AM 1,900 views

I created this wizard to add custom invoice in 'pos.order':

import wizard
import pooler
from tools.translate import _

class link_invoice(wizard.interface):

    def _show_report(self, cr, uid, data, context):
        pos_obj = pooler.get_pool(cr.dbname).get('pos.order')
        found = False
        for pos in pos_obj.browse(cr, uid, data['ids'], context = context):
            for inv in pos.invoice_id:
                if inv.state != 'cancel':
                    found = True
        if not found:
            raise wizard.except_wizard(_('Error'), _('POS has no related invoices.'))
        return {
            'report_name': 'invoice.with_picking_lists',
            'type': 'ir.actions.report.xml' }

    states = {
        'init': {
            'actions': [],
            'result': {
                'type': 'action',
                'action': _show_report,
                'state': 'end' } } }


When I try to open invoice, I get this error:

KeyError: "Field '0' does not exist in object 'browse_record(pos.order, 8)'"


| 6 5 8
Delhi, India
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
On 5/22/13, 9:04 AM

hey Andrius

this part of code should be :

 for pos in pos_obj.browse(cr, uid, data['ids'], context = context):
       #for inv in pos.invoice_id:
       if inv.invoice_id.state != 'cancel':
           found = True

remember invoice_id is an many2one field so you can directly get state of that invoive like this invoice_id.state


Thanks, but I it should be pos.invoice_id.state, because inv is not assigned (when it is commented). I tried it, but now I'm getting this error: local variable 'objects' referenced before assignment

NOD Baltic, UAB, Tomas Parnarauskas
on 5/22/13, 11:20 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/22/13, 8:53 AM
Seen: 1900 times
Last updated: 3/16/15, 8:10 AM