Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to create selection that shows all incoming e-mail titles?

Subscribe

Get notified when there's activity on this post

This question has been flagged
1 Reply
4435 Views
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
Discard
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
Discard
Yenthe Van Ginneken (Mainframe Monkey)
Author

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

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

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

@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)
Author

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

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!

Sign up
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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