Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
16213 Vizualizări

As describe in https://doc.odoo.com/6.0/developer/2_5_Objects_Fields_Methods/field_type/#relational-types

I have created a many2one field with custom selection function :

def _get_partner_sup(self, cr, uid, context=None):
    obj = self.pool.get('res.partner')
    ids = obj.search(cr, uid, [('supplier','=',True), ('is_company','=',True)])
    res = obj.read(cr, uid, ids, ['name', 'id','email'], context)
    res = [(r['id'], r['name']) for r in res]    
    return res

_columns = {
    'partner_sup_id': fields.many2one('res.partner', 'Select Supplier 2 ', selection=_get_partner_sup),
}

But it's still like a normal many2one field. What is wrong ?

And I don't want use widget='selection' or domain=[('supplier','=',True), ('is_company','=',True)]

Thanks in Advance

Imagine profil
Abandonează
Cel mai bun răspuns

Wrong parameter. The many2one field doesn't have parameter "selection". 

Can you explain please, why you don't want to use:

_columns = {
'partner_sup_id': fields.many2one('res.partner', 'Select Supplier 2 ', domain=[('supplier','=',True), ('is_company','=',True)),
}
you can also set domain in the XML, if you like to have domain filter only in the particular page.

?

if you want to limit displayed columns(fields) to the 'name' field in the selection(you seem to try this in your function), then you've to achieve it with custom view (treeview) for this model.

Imagine profil
Abandonează
Cel mai bun răspuns

You can use any of the provided Options here but the final adjustment is that you need to set the widget selection for the field in your xml view definition. For example:

#in your .py  

_columns = {

    'partner_sup_id': fields.many2one('res.partner', 'Select Supplier 2 ', domain=[('supplier','=',True), ('is_company','=',True)),

}

 

#in your xml
 

<field name="partner_sup_id" widget="selection">
 

Imagine profil
Abandonează
Cel mai bun răspuns


Well if you don't want to use Domain / Widget...

Then you can try with either of these options

Option 1:

Define a field as Selection, instead of Many2One, along with a selection to achieve your requirement...

Coming to your Requirement:

def _get_partner_sup(self, cr, uid, context=None):

obj = self.pool.get('res.partner')

ids = obj.search(cr, uid, [('supplier','=',True), ('is_company','=',True)])

res = obj.read(cr, uid, ids, ['name', 'id','email'], context)

res = [(r['id'], r['name']) for r in res]

return res

_columns = {

'partner_sup_id': fields.Selection(selection=_get_partner_sup),

}

Option2: If your intention is just not to provide Create/Edit option to the users, then in XML, against that fields just "options={'no_create':True}", by doing this also, you can achieve the same...

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
oct. 20
3243
1
aug. 17
3697
0
mar. 15
3060
1
mar. 15
6211
1
sept. 23
1708