Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
5 Risposte
5400 Visualizzazioni

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 

Avatar
Abbandona
Risposta migliore

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)]"/> 


Avatar
Abbandona
Autore

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: )>"

Autore

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.

Autore

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.

Autore

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

Autore

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?

Autore

yep, to fill it automatically

Risposta migliore

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

Avatar
Abbandona
Autore

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

Post correlati Risposte Visualizzazioni Attività
2
feb 23
4005
1
gen 21
5195
1
dic 19
2803
1
ago 24
2704
4
mag 24
12560