This question has been flagged
2 Replies
5433 Views

I am getting the error: 

                          AccessError: ('AccessError', "No value found for account.invoice(u'66',).state")

I have this code here:

def _get_invoice_status(self, cr, uid, ids, invoice_status, arg, context=None):
        inv_status = {}

       inv_obj = self.pool.get('account.invoice')
        for record in self.browse(cr, uid, ids, context=context) :

           _inv = record.invoice and inv_obj.browse(cr, uid, record.invoice, context=context) or False
            inv_status[record.id] = _inv and _inv.state or ''    <-- error is from this line. How can I fix it?
        return inv_status

 

  _name = 'intrac.batches.registrations'
    _columns = {
        'name': fields.char('Registration Number', readonly=True),
        'invoice': fields.integer('Invoice'),
        'invoice_status' : fields.function(_get_invoice_status, type='char', store=False, string='Invoice Status'),  
    }

Avatar
Discard

@Abdullah, can you share the log (server or javascript console) that indicates that the line causing the problem is indeed that line? I've commented in your other question that u'..' is a unicode. Also, I can't find the exact error message in OpenERP v7 (your code is v7/old API style), are you using other version?

Best Answer

Probably invoice with ID = 66 not exists. My suggestion: before inv_obj.browse you call inv_obj.search. If not empty search result call browse.

            for record in self.browse(cr, uid, ids, context=context) :
                inv_status[record.id] = ''
                inv_ids = inv_obj.search(cr, uid, [('id', '=', record.invoice)], context=context)
                if inv_ids:
                    _inv = inv_obj.browse(cr, uid, inv_ids, context=context)
                    inv_status[record.id] = _inv.state                

 

Avatar
Discard
Author

invoice with id = 66 does exist zbik.

Answer updated

Author

before inv_obj.browse you call inv_obj.search. If not empty search result call browse I am not sure how to do this exactly

updated

Best Answer

Hello Abdullah,

In particular line define below giving you error : 

inv_status[record.id] = _inv and _inv.state or ''

This type of error comes when the particular state field in line you are browsing it's also functional field and It state field should be store=False. 

So, that's system can't find that particular field in database or their value and throwing error.

Make Sure that particular "state" field define your system it's also displaying value in database Check in database.

 

Thanks,

Avatar
Discard
Author

Hi Hiren, I check the database and the record is there.

Hi Abdullah, Make sure you have to check state field in 'account.invoice' object. Because you are taking value of 'account.invoice' object. Define your line in below. _inv = record.invoice and inv_obj.browse(cr, uid, record.invoice, context=context) or False Here inv_obj is 'account.invoice' object. Otherwise, If you want to solve out this issue immediately Checked if condition define below code. _inv = record.invoice and inv_obj.browse(cr, uid, record.invoice, context=context) or False if _inv: inv_status[record.id] = _inv and _inv.state or '' else: inv_status[record.id] = False Otherwise specify in functional field which value you want to browse because I can't understood why you are browsing account.invoice object and checking with current current object. Thanks,

@Hiren store=False has nothing to do with accessing the value of state field. The _inv here is a browse_object, an ORM object that will have all the fields values, regardless of stored or not. It will just calculate the value if functional field if not stored.

My mean is to check status field of 'account.invoice' object not your 'invoice_status' field. _inv = record.invoice and inv_obj.browse(cr, uid, record.invoice, context=context) or False Because in particular line you are taking value of 'account.invoice' object And Sorry to say you but you are browsing value in wrong way Let me brief explain: You are taking value like this : _inv = record.invoice and inv_obj.browse(cr, uid, record.invoice, context=context) or False Means you are browsing 'account.invoice' with id 'record.invoice'. 'record.invoice' is the value of your current object. If you are passing nothing then it will take False value of your "_inv" variable. If in your current object you are passing 2 for invoice field then it will browse account.invoice object which have ID contain 2. Then you have to simply check in database that what ever value you are passing for your current object define field : 'invoice': fields.integer('Invoice'), This field value you have to consider as a id as per your code. Suppose you are passing 5 in this particular field. Then you have to check in 5 number ID in account.invoice object and this particular state will be return. Thanks