Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2911 Lượt xem

Greetings,

i want to change the domain of many2one field to present new records , the code worked fine but with wrong values

after i invoke the function : the values first will present the comanies name and if i click on one company , the values which i want (customer names ) will appeare .

how i can remove the first list which is the locations ? and from where this values retrieved i don't know .

 

My Code :

#------------PY

'customer_name':fields.many2one('res.partner'),

#------------XML

<field name="customer_name" widget="selection"/>

#---------- Function

cus_array=[]

        myobj = self.pool.get('res.partner')
        ids = myobj.search(cr, uid, [])
        for id in ids:
            customer = self.pool.get('res.partner').browse(cr, uid, [id], {})            
            if customer.country_id.id == customer_country:
                cus_array.append(str(customer.name))
                               
        return {'domain':{'customer_name':[('name','=',cus_array)]}}

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I would advise you to read the answer to this question: https://www.odoo.com/forum/help-1/question/best-practices-as-to-when-to-use-fields-selection-vs-fields-many2one-69262.

You cannot dynamically domain a many2one field with widget="selection".

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

well done thats worked for me ^____________^

 

Ảnh đại diện
Huỷ bỏ