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 create selection that shows all incoming e-mail titles?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
1 Respondre
4432 Vistes
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys

I would love to be able to get all e-mails that are sent to Odoo (so incoming on Odoo) in a dropdown in the project view. I then want to create a dropdown where the user can see every title of an email, choose one and save it on a project. The idea is that the user can also directly click on the item and that it opens up the correct e-mail.

Is this possible and how should I do it?
I assume it is possible since you have the model 'mail.mail' which contains all e-mails and you can fetch them in the view?

What I tried so far is to add a new field on the form from project_view.xml (<record id="edit_project" model="ir.ui.view">) by doing so:

<group col="4">
                            <field name="user_id" string="Project Manager"
                                    attrs="{'readonly':[('state','in',['close', 'cancelled'])]}"
                                    context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'project.group_project_manager']}"/>
                            <newline/>
                            <field name="partner_id" on_change="onchange_partner_id(partner_id)" string="Customer"/>
                <newline/>
               <field name="email_id" on_change="onchange_email_id(email_id)" string="Emails"/>
                        </group>

I then created the new field email_id in project.py in the columns = {} under the class project like this:

fields = {
//Lots of irrelevant code

'state': fields.selection([('template', 'Template'),
                                   ('draft','New'),
                                   ('open','In Progress'),
                                   ('cancelled', 'Cancelled'),
                                   ('pending','Pending'),
                                   ('close','Closed')],
                                  'Status', required=True, copy=False),
        'doc_count': fields.function(
            _get_attached_docs, string="Number of documents attached", type='integer'
        ),
        'email_id': fields.many2one(
            'mail.mail', '??', help='This holds all e-mails that you recieved.'),

     }

And finally in project.py I created an on_change function like this:

    def onchange_email_id(self, cr, uid, ids, part=False, context=None):
        email_obj = self.pool.get('mail.mail')
        return {'value': email_obj}

Everything looks pretty good but I get one more error when I want to create / modify a project:

 

So what am I doing wrong or am I missing?
Yenthe

1
Avatar
Descartar
Avatar
Ivan
Best Answer

Why don't you use many2one field instead?  With the proper domain I believe it can achieve what you need.
Your many2one should look like this:

'email_id': fields.many2one(
            'mail.mail', '--', help='This holds all e-mails that you recieved.'),

Your XML like this (with a domain that filters on received e-mails):

<field name="email_id" on_change="onchange_email_id(email_id)" string="Emails" domain="[('state','=','Received')]"/>

1
Avatar
Descartar
Yenthe Van Ginneken (Mainframe Monkey)
Autor

Hmm good idea Ivan! I actually created a many2one field, like you suggested. 'email_id': fields.many2one( 'mail.mail', '??', help="This holds all e-mails that you recieved.'), so how can I filter this to only show e-mails that are recieved in Odoo and not sent? If I have that I'm almost done..

Ivan

mail.mail has a state field that can be ('outgoing', 'Outgoing'), ('sent', 'Sent'), ('received', 'Received'), ('exception', 'Delivery Failed'), ('cancel', 'Cancelled'). Maybe you can use that to filter incoming mails?

Yenthe Van Ginneken (Mainframe Monkey)
Autor

So how can I apply this in a domain / filter? I honestly haven't ever used them..

Ivan

You have 2 options, AFAIK, put the domain in the field definition, something like: 'email_id': fields.many2one('mail.mail', 'ee', domain=[('state', 'in', [list of the states])], required=True, copy=False). Or you can put it in the view: <field name="email_id" domain="[('state', 'in', [list of the states])]" string="Emails"/>

Yenthe Van Ginneken (Mainframe Monkey)
Autor

domain="[('state','=','received')]" seems to do the job perfect. I only have one error remaining,. I'll update my question for this, could you have a look at this in a few minutes please? I'll accept your answer afterwards.

Ivan

You seemed to inherit from model.Models but code using the old API way. Try to inherit from orm.Model instead?

Ivan

Is that (inheriting model.Models) it?

Yenthe Van Ginneken (Mainframe Monkey)
Autor

@Ivan I tried importing both at the top and this gives me the error from openerp import model.Models ^ SyntaxError: invalid syntax But I'm not sure how this would be related to this error? :s How could I alternatively fix this or do this in V8 code?

Yenthe Van Ginneken (Mainframe Monkey)
Autor

I had another fields.many2one which was screwing things up, so my bad! Its working perfect now. Is it okay that I update your answer with the final result? Then its a honest 'accepted' answer. I don't know who accepted it yet so :)

Ivan

No, it does not. You should be importing models instead: from openerp import models, fields, api, _. Usually you just inherit the class from models.Model not from the Model itself. I'm not well versed in v8 API. Sorry, I also missed that you used fields instead of _column. fields is a keyword in OpenERP. Maybe that is the cause.

Ivan

Yup. Go ahead.

Yenthe Van Ginneken (Mainframe Monkey)
Autor

Added my code in your answer. Alright thanks for the help Ivan! Upvoted & accepted.

Ivan

Pleasure to help.

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