Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

[v10] Pass active_id through button to fill fields

Subscriure's

Get notified when there's activity on this post

This question has been flagged
actionmany2onebuttonautocompleteactive_id
9 Respostes
10431 Vistes
Avatar
Bastien Bascou

Hello !

I get troubles to fill fields of my model opened in edit form view.

Here are some screens of the usecase :

http://imgur.com/G1ptWXN

http://imgur.com/lWrrDRj

http://imgur.com/1FvI25l

In the URL, I can see the active_id (or active_ids) of my products on the second screenshot. But my trouble is in filling the field Article with them (WITHOUT saving it : I want the user to choose to save or not)

Here is the code of my "new" button action right now :


def new_match(self):
    return{
        'name':("Save a new matching"),
        'view_mode': 'form',
        'view_type': 'form',
        'view_id': False,
        'res_model': 'label.label',
        'res_id': self.id,
        'type': 'ir.actions.act_window',
        'target': 'current',
        'domain': '[]',
        'flags': {'initial_mode': 'edit',} ,
        '_default':{'products':[(6,0,[self._context.get('active_ids')])]},
  }

I tried a lot of stuff that didn't work, without giving me any error or stuff. I'm a bit lost here

If someone could give me solution or part of it that'd be great ! :)

Thanks !

0
Avatar
Descartar
Bastien Bascou
Autor

The code of my list view :

<record model="ir.ui.view" id="label.tree_new_match">

<field name="name">Create Matching</field>

<field name="model">label.label</field>

<field name="view_type">form</field>

<field name="view_mode">tree</field>

<field name="arch" type="xml">

<tree colors="red:status=='OFFLINE';black:len(products)!=0;green:len(products)==0" default_order='len_products, real_id' create='false' delete='false'>

<button string="New" type="object" name="new_match"/>

<field name="description" string="Name"/>

<field name="real_id"/>

<field name="type"/>

<field name="products"/>

<field name="status"/>

<field name="len_products" invisible="context.get('len_products')!=1000"/>

</tree>

</field>

</record>

Avatar
Bastien Bascou
Autor Best Answer

The only way i found to do this was to set the fields direclty in the action function, but that doesn't do what i wanted to do at first :'(

0
Avatar
Descartar
Avatar
Keyur Gajjar (kga)
Best Answer

Hello Bastein,

You need to pass the context here instead of '_default':

    e.g. 'context': {},

And in context you need to pass fields which you want to set defaults with 'default_' prefix.

in your case its like 

    'context': {'default_partners': [(6,0, active_ids)]}, 

0
Avatar
Descartar
Bastien Bascou
Autor

Hi ! Thank you for the answer

I got the error : NameError: global name 'active_id' is not defined

when I put it between '' no mistakes but doesn't work.

Keyur Gajjar (kga)

sorry, my bad. Try using self.env.context.get('active_ids') instead of active_ids.

Bastien Bascou
Autor

Still doesn't work, i tried with self._context.get('active_ids') as well,replacing active_ids by active_id etc ...

Do I need to pass values trough context of my tree view ?

Keyur Gajjar (kga)

Yeah you need to pass that active_id in the context when clicking on the action in 'More' dropdown. which will be propagated to the "New" button action's context.

Bastien Bascou
Autor

Is it automatically propagated ? because as i said in my original post, in the url the active_id on my second screenshot is the products i want to match with my label, but in the third screenshot the active_id is the label itself. so i'm scared that i can't use the active_id of the product anymore at this point.

Bastien Bascou
Autor

Ok got some news :

def new_match(self):

context=self._context.copy()

if context.get('active_ids'):

context.update(default_products=[(6,0,context.get('active_ids'))])

else:

context.update(default_products=[(6,0,context.get('active_id'))])

return {

'name':_("Save a new matching"),

'view_mode': 'form',

'view_type': 'form',

'view_id': False,

'res_model': 'label.label',

'res_id': self.id,

'type': 'ir.actions.act_window',

'target': 'current',

'domain': '[]',

'context': context,

'flags': {'initial_mode': 'edit',},

}

with this action button, I manage to get the active_ids of my products in the 3rd screenshot. But still nothing filled where it should be. :)

Thank you again !

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Active id Bug in odoo v15
action active_id
Avatar
0
de maig 22
3167
action button is disabled in the list view Solved
action button
Avatar
1
de març 21
5611
How set STATE=DONE? (Action & Button)
action button
Avatar
Avatar
Avatar
3
de març 15
11220
How to change string of the button without altering its action
action button string
Avatar
Avatar
Avatar
2
de febr. 23
4372
Custom back button no longer working. Solved
action button customization
Avatar
2
d’oct. 20
6801
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now