Odoo Help

0

Function to get number of records from another class does not output anything on the screen

By
Orsina
on 4/3/15, 12:18 PM 673 views

Hello. I am new to OpenERP and i am trying to build a function in class library.book which is supposed to output the number of book that are reserved by the students (which means the number of books that are registered in the class library.reservation). But even the raise I have build output correctly the number of reserved books for each book, the function does not output anything in the field i have build for it. Further more when I write the function all the books disappeared from the list and the tree view of the class library.function is empty.


Here is the function i have build:


  def _book_available(self, cr, uid, ids, name, args, context=None):
        res={}
        books = self.browse(cr, uid, ids, context=context)
        for book_avail in books:
            book_ids=self.pool.get('library.reservation').search(cr, uid,[('book_id', '=', book_avail.id)], context=context)
            res[book_avail.id]=len(book_ids)
        raise osv.except_osv(_('Error _reservationed_book_number'),_('"%s"') % (res)
        return res

and here is the corresponding field:


'available_number_book':fields.function(_book_available, string='Available number of books'), 

Please can you help me? I have been stuck on this for hours

Can you give me any suggestion, any idea where my mistake is? Please...

Orsina
on 4/3/15, 12:56 PM

openerp version ? you should put entire 2 class wih fields, with your description, no enough informations

Cyril Gaspard (GEM)
on 4/3/15, 5:18 PM
0

Zbik

--Zbik--
6253
| 6 4 7
Lodz, Poland
--Zbik--


Zbik
On 4/3/15, 2:11 PM

Try adding the parameter  store=True to fields.function.

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.

Register

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

2 follower(s)

Stats

Asked: 4/3/15, 12:18 PM
Seen: 673 times
Last updated: 4/3/15, 5:18 PM