Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
5 Ответы
5401 Представления

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

Related Posts Ответы Просмотры Активность
2
февр. 23
4008
1
янв. 21
5196
1
дек. 19
2803
1
авг. 24
2707
4
мая 24
12565