This question has been flagged
2 Replies
18808 Views

This is my first time using a function field. so please help me to see if I put the right calls and arguments.

I am just trying to get the state of the invoice which id I input in field "invoice"

I am getting this error: 

DataError: invalid input syntax for integer: "invoice"

LINE 2: WHERE account_invoice.id IN ('invoice') ...

 

This is the code:

 

    def _get_invoice_status(self, cr, uid, ids, invoice_status, arg, context=None):
        inv_status = {}
        for record in self.pool.get('account.invoice').browse(cr, uid, ['invoice'], context=context) :
            inv_status[record.id] = record.state or ''
        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'),
    }

 

Can someone help?

 

Avatar
Discard
Best Answer

The problem is in this line:

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

It expects list of integers in the place of ['invoice'].  My guess is, it should be:

    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 ''
        return inv_status

Having said that, why don't you make 'invoice' field to be many2one to the account.invoice model?

Avatar
Discard
Author

Thank you Ivan. Your code worked perfectly.

Author Best Answer

Thanks Ivan, But I am getting this error now in an alert window:

 

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

 

Working with odoo is very hard when simple things like this have no straightforward guide tutorial.

Avatar
Discard

Take a look at the server log or javascript console to see which line causes the error. It might not be the line that I've given you in my answer. The ID has been passed as string in the code u'...' means unicode string in python. Admittedly developing for Odoo is not for the faint heart, but it applies to all ERP. ERP can grow to such complexity that you wouldn't be able to "master" it. The best way is to learn how to find example, because the good thing about Odoo is it is open source and you can learn from how the official software has been build. Stephen Mack had collated one of the best collection of Odoo documentation. I would suggest that you learn about grep (or findstr in Windows), python, and read his posts: https://www.odoo.com/forum/help-1/question/the-hitchhikers-guide-to-odoo-71524 and https://www.odoo.com/forum/help-1/question/what-blogs-tutorials-forums-exist-about-odoo-68797