Odoo Help

Welcome!

This community 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.

0

AccessError: No value found function field

By
Abdullah Sofan
on 1/24/15, 5:18 AM 1,544 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'),  
    }

@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?

Ivan
on 1/24/15, 8:04 AM
1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 1/24/15, 5:50 AM

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                

 

invoice with id = 66 does exist zbik.

Abdullah Sofan
on 1/24/15, 6:31 AM

Answer updated

zbik
on 1/24/15, 6:51 AM

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

Abdullah Sofan
on 1/24/15, 7:01 AM

updated

zbik
on 1/24/15, 7:51 AM
0
Hiren OdooERP
On 1/24/15, 7:15 AM

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,

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

Abdullah Sofan
on 1/24/15, 7:16 AM

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 OdooERP
on 1/24/15, 7:39 AM

@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.

Ivan
on 1/24/15, 8:00 AM

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

Hiren OdooERP
on 1/24/15, 8:23 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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/24/15, 5:18 AM
Seen: 1544 times
Last updated: 3/16/15, 8:10 AM