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

How to return or update a one2many field using button click?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
1 Respondre
10606 Vistes
Avatar
rosey

def button_dummy(self, cr, uid, ids, context=None):
          res = []
          valiue = {}
          print "employee",context,ids
          ename = context.get('employee_id');         
          emp_obj = self.pool.get('hr.employee')
          emp_name = emp_obj.search(cr, uid, [('name','=',ename)], context=context)
          print "emp_name",emp_name
          location_lines = []
          location_ids = self.pool.get('employee.location').search(cr, uid, [('employee_id','=',emp_name)],limit=5)
       
          for p in self.pool.get('employee.location').browse(cr, uid, location_ids):
              location_lines.append((0,0,{'current_location':p.current_location.name
                        },{'location_type':p.location_type
                        }))
            ## First i used this return to update the one2many field, but no output
          res['value']['location_line_ids']=location_lines
          return res

         ## Second i used this return to update the one2many field, but no output

          return {'value': {'location_line_ids': location_lines}}

How can i return values into one2many field using button click?

 

Updated question:

First i created employee.location model. Then i call employee.location(one2many) model in hr.employee. In employee.location there is a many2one employee_id field to connect both the models.

Already i added datas in employee.location using different form view. Now i just want to see the history of the employee location in the employee profile. For that

<button name="button_dummy" string="Refresh" type="object" context="{'employee_id':name,'location_line_ids':location_line_ids}"/>                      
                         <field name="location_line_ids" options="{'reload_on_button': true}">

 

When i click the button above function will call and just display the employee location data for only displaying. I dont want to write the datas again, only want to display the datas in each employee profile using employee_id.


                        

 

0
Avatar
Descartar
Emipro Technologies Pvt. Ltd.

I have edited my ans, check it. Let me know if that works or not. You don't need any button click. Just put the field in as shown in my ans.

rosey
Autor

Thanks for your reply. I have two different menu: HR-Employee and another is Employee location. In Employee location i will add the locations against each employees. Then i need an extra addons- ie, i want to see the history of these employee locations in each employee profile. So i added employee location as one2many in my employee profile. And added a button click. For an example, i added 3 records of employee sam in Employee location. Next i select HR-employee and select sam, there is a one2many field in sam's(employee profile). Above to the one2many field there is button. when i click the button it will select 3 records from the employee.location table, and will just display the records in the one2many field. I need this requirement. Do you understand my requirement?

Avatar
Emipro Technologies Pvt. Ltd.
Best Answer

You will directly update the values using the 'write' method, returning 'value' will not work. This is not 'onchange' method.

1./ Also, here you tried to find the location based on the 'employee_id' which could be a many2one field and you have tried searching as 'employee_id' ,'=',emp_name, that is an integer value and you are trying to search by 'string' value. I am wondering whether this is working for you or not.

2./ Where does 'project_ids' came from in the loop? I think it should be 'location_ids'.

Anyways, try following:

for p in self.pool.get('employee.location').browse(cr, uid, project_ids):
              location_lines.append((0,0,{'current_location':p.current_location.name
                        ,'location_type':p.location_type
                        }))

Once everything is stored in location_lines then you have to update that value using 'write' method

self.write(cr,uid,ids,{'project_line_ids':location_lines})

Edited:

I don't think you need any button click, just to display the employee location. System will autmatically display all those values based on the relation.
Just put your field as shown below in your view, wherever you need it.


<field name="location_line_ids">
<tree string="Employee Locations">
    <<Your Fields From The Model 'employee.location'>>
</tree>
</field>   

 

Hope this helps !!.

1
Avatar
Descartar
rosey
Autor

Thanks for your help. i don't know python. i just started with python coding.

rosey
Autor

Please see my updated question. Code is working, but i don't want to write the datas again. I just want to display the datas. Please help me. I dont know python, coding makes me more confusion, so please help me.

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
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