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

function field DataError: invalid input syntax for integer

By
Abdullah Sofan
on 1/24/15, 1:52 AM 1,304 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?

 

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/24/15, 3:18 AM

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?

Thank you Ivan. Your code worked perfectly.

Abdullah Sofan
on 1/24/15, 8:09 AM
0
Abdullah Sofan
On 1/24/15, 4:51 AM

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.

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

Ivan
on 1/24/15, 7:38 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, 1:52 AM
Seen: 1304 times
Last updated: 3/16/15, 8:10 AM