Odoo Help


Sortable function field - how to ? [Closed]

Dr Obx
on 7/9/15, 6:20 AM 913 views

The Question has been closed for reason: not relevant or out dated

Dr Obx
on 07/27/2015 05:05:36

Some time ago I started this project and so far I have ...

What is it doing:

Whilst you creating a move of the product it check the location of the product and quantity and displays it in the drop down list

so in Origin you can see where this product is located and how many you have in this place. All other locations shows '0'

My target is just limit displayed locations on this list only to the locations where this product exist. If for example this product is only in one location, list will contain only one line, if more it will display more lines. The point is to give user as precise information as possible to avoid  a wasting time searching for location of this product. (in case if your warehouse contains a hundreds of locations like mine).

It works but ... I can't filter locations and it still show me all of them which is over 5 hundred.

And getting this error: ProgrammingError: can't adapt type 'builtin_function_or_method'

My question is, what is wrong with my code and why I can't use domain filter to select only locations where this product is ?

Check code below ...

from openerp.osv import fields,osv

class stock_location(osv.osv):

_inherit = 'stock.location'

# Get stocks quantity

def _get_current_stock(self, cr, uid, ids, fields, arg, context=None):

res = []

quants = []

for obj in self.browse(cr, uid, ids, context=context):

if 'default_product_id' in context:

quants = self.pool.get('stock.quant').search(cr, uid, [('location_id','=',id),('product_id','=?',context.get('default_product_id'))])


quants = self.pool.get('stock.quant').search(cr, uid, [('location_id','=',id)])

for quant in self.pool.get('stock.quant').browse(cr, uid, quants, context):

res[obj.id] += quant.qty

return res

# Get locations ids

def _get_locations(self, cr, uid, ids, context=None):

res = []

for quant in self.pool.get('stock.quants').browse(cr, uid, ids, context=context):

if quant.location_id:


return res

# Fields declaration

_columns = {

'qty': fields.function(_get_current_stock, type = "float", string = 'qty', store = {'stock.quants': (_get_locations, ['location_id','qty'], 1 ) } ),


# Overriding name_get

def name_get(self, cr, uid, ids, context=None):

res = []

for loc in self.browse(cr, uid, ids, context):

res.append((loc.id, loc.name + " / " + str(loc.qty) + " Units" or ''))

return res


Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 7/10/15, 1:32 AM

In OpenERP/Odoo you cannot filter or group by a function field(neither related, dummy, property or any other function based field) to do that you could just override the read_group method in your own model to programatically filter the results.

Would you give me an example ?

Dr Obx
on 7/10/15, 4:16 AM

it's dificult, first you need to determine what field in the group_by is a function field then call super with the clean params and with the results apply then the business rules of the filter/group_by for the case, to remove or add lines of results. You need to debug the read_group method to know more of what I tell you

Axel Mendoza
on 7/10/15, 5:34 AM

I'm a beginner in Odoo so everything you just told me is a kind of a magic :) Check this code and analyze it please. Tell me what should i change or is completely useless. As far as I know, at the beginning there is a function which gather quants of products and locations, save it to the table then selecting locations where the product exist but something is not right because it won't count and display quants ...

Dr Obx
on 7/10/15, 8:55 AM

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.


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)


Asked: 7/9/15, 6:20 AM
Seen: 913 times
Last updated: 7/27/15, 5:05 AM