コンテンツへスキップ
メニュー
この質問にフラグが付けられました
5 返信
5412 ビュー

i have two models crm.store in which i have declared thoses two fields

name = fields.Char(string="Name store")
id_store = fields.Char(string="ID store")

and  crm.unit which in which i have the fallowing fields 

st_or_id = fields.Char(string="ID")
store = fields.Many2one('crm.store', string='Store')
store_id = fields.Char(related='store.id_store', string='Store ID)

i want when i give the st_or_id, the store field will be feed up with the store name that has the same id of id_store 

for that i tried in my xml

    <field name="store_id " invisible="1"/>    
    <field name="st_or_id "/>
    <field name="store" domain="[('st_or_id ', '=', store_id)]"/> 

i want to know how could i acheive this, using an onchange function.

i tried that , to applie the domain on the store field

 @api.onchange('st_or_id')
def onchange_store_id(self):
    return {'domain': {'store': [('st_or_id', '=', 'store_id')]}}

but it dosent work 

アバター
破棄
最善の回答

I think you want to show Store (in m2o) matching entered ID (in st_or_id field) with "ID Store". If yes, you don't need onchange because you can directly add the domain in XML.

Try the following code:

<field name="store" domain="[('id_store', '=', st_or_id)]"/> 


アバター
破棄
著作者

hi

i tried that already, and i get this error

Invalid field 'magasin_id' in leaf "<osv.ExtendedLeaf: ('magasin_id', '=', '5577') on crm_magasin (ctx: )>"

著作者

magasin_id = is in my case id_store

As per error, "magasin_id" does not exist in "crm.magasin" object. Please double check the field.

著作者

yes i have checked, and i even declared the related field as store=True

It would be more helpful if you can share your original code.

著作者

i prefer to keep it as simple as the code that i am mentioning, the original code that i am working on, works in a three diffrent modules, so it just gonna make it even harder, i gave the same example with just renaming the fields for more clarity

著作者

besidesn your code is not gonna feed up automatically the store field based on the st_or_id, yours just established a domain where the id_store equals to st_or_id

Do you want to just apply a domain on the m2o field or want to fill it up automatically when you enter a value in "st_or_id" field?

著作者

yep, to fill it automatically

最善の回答

Hi,

Try this code,

@api.onchange('st_or_id')
def onchange_store_id(self):
for rec in self:
return {'domain': {'store': [('id', '=', rec.st_or_id)]}}

Thanks

アバター
破棄
著作者

it works like just a simple many2one field,not what i am looking for

関連投稿 返信 ビュー 活動
2
2月 23
4019
1
1月 21
5215
1
12月 19
2805
1
8月 24
2716
4
5月 24
12594