0
votes

On my class folder a have many goods and many amounts. I need to use a domain filter on my field good_id of class amount, on that field I need to show the list of my object folder's goods.

so I create a function on my amount class (_get_folder_list_goods) that returns the list of folder's goods and I add a domain attribute on my field good_id of class amount.

here are my classes:

class folder(osv.osv):
_name = 'folder'

_columns = {

    'name' : fields.char(u'Numéro',size=50, readonly=True),
    'goods_ids': fields.many2many('good', 'doss_bien_rel', 'folder_id', 'good_id', 'Goods'),
    'amount_id': fields.one2many('amount', 'folder_id', 'Amounts'),

....}

class good(osv.osv):
_name = 'good'
_columns = {

    'name' : fields.function(_name_get_fnc, type="char", string=u''),

....}

class amount(osv.osv):
_name = 'amount'

def _get_folder_list_biens(self, cr, uid,folder_id, context={}):
    liste_goods=[]
    object_folder =  self.pool.get('folder').browse(cr,uid,folder_id,context)
    if object_folder.goods_ids:
        for good in object_folder.goods_ids:
            liste_goods.append(good.id)
    return liste_goods

_columns = {

    'folder_id': fields.many2one('folder', 'Ref folder', select=True),
    'good_id':fields.many2one('good', Goos',domain="[('id', 'in', _get_folder_list_biens(folder_id))]"),
}

I got this error:

Uncaught Error: NameError: name '_get_folder_list_biens' is not defined

1

1 Answers

1
votes

The domain is used on the client when the user starts to key (or lookup) and Good and it (the client) knows nothing about this method. What you need to do is create a functional field of type many2one that calls _get_folder_list_biens and returns a list of ids. Put the new functional field on your form as invisible and then make your domain ('id', 'in', my_functional_field)