Skip to Content
Odoo Menu
  • Prijavi
  • 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
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to write this domain for a one2many field on a view?

Naroči se

Get notified when there's activity on this post

This question has been flagged
domainformviewmany2oneone2many
3 Odgovori
27281 Prikazi
Avatar
Pascal Tremblay

Hello guys!

I really have problem with domain for one2many field.

In the res.company form, I select some partners for the field line_of_business_ids. I save this and it works.

In the view view_partner_property_form (see below) the field line_business_ids of the partner should only offer the values available in the field line_of_business_ids of his own and only company_id. Every partner has a company_id field. And any company has a line_of_business_ids field (in my case). 

I'm not able to write this domain myself.

Could you help me?

Thanks to help

I actually have this code :

In Python

class Partner(models.Model):
_inherit = "res.partner"
     related_business_id = fields.Many2one('res.partner', string='Related business line')
     line_business_ids = fields.One2many(comodel_name='res.partner', inverse_name='related_business_id')

class res_company(models.Model):
_inherit = "res.company"
     line_of_business_ids = fields.Many2many(comodel_name='res.partner')

In the xml view

<record id="view_partner_property_form" model="ir.ui.view">
    <field name="name">base.view.partner.form.inherit.vtm2</field>
     <field name="model">res.partner</field>
     <field name="inherit_id" ref="base.view_partner_form" />
     <field name="arch" type="xml">
         <field name="category_id" position="after">
            <field name="line_business_ids" widget="many2many_tags"
                attrs="{'invisible': [('is_company','=', False)]}"
                options="{'no_create_edit': True}"
                domain="[('id', 'in', 'company_id.line_of_business_ids.ids')]" />
        </field>
    </field>
</record>


See image of the situation



Edit #1

I have tried all this domains. No success...

domain="[('company_id.line_of_business_ids', 'in', id )]"

domain="[('id', 'in', company_id.line_of_business_ids)]

domain="[ ( 'company_id.line_of_business_ids', '=', [ (6, [0], [id]) ] ) ]

domain="[('company_id.line_of_business_ids.id', 'in', company_id.line_of_business_ids )]"

domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.ids )]"

domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.id )]"

domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.partner_id.id )]"

domain="[('company_id.line_of_business_ids', 'in', company_id.line_of_business_ids )]"

domain="[('company_id.line_of_business_ids', 'in', company_id.line_of_business_ids[0][2] )]"


1
Avatar
Opusti
Avatar
Akhil P Sivan
Best Answer

Hi, 

Pardon me if I misunderstood your requirement. But please clarify the following.

Why can't you use a related One2many field on res.partner to company_id.line_of_business_ids, which could be a readonly field. Since a partner is supposed to have only one company_id, I think no need to use a Many2many field in res.company, you could have use a One2many field. For related fields, both field types should be same.

Then on the partner form, in line_business_ids you can only see the partners added on his company.

For eg:

class Partner(models.Model):
    _inherit = "res.partner"
    line_business_ids = fields.One2many(related='company_id.line_of_business_ids', readonly=True, string="Line business ids")

class res_company(models.Model):
    _inherit = "res.company"
    line_of_business_ids = fields.One2many('res.partner','company_id',string="Line of business ids")
3
Avatar
Opusti
Pascal Tremblay
Avtor

Mister Sivan, I want to send you 1000 thanks for this precious answer. I will publish my solution soon.

A chance you have been there!

Akhil P Sivan

Good to know that my answer helps you :)

Avatar
Pascal Tremblay
Avtor Best Answer

Big thanks to mister Sivan for his help. It was precious!

Here is our complete solution

In Python, with more significant names

class Partner(models.Model):
    _inherit = "res.partner"

    customer_of_division_id = fields.Many2one(comodel_name='res.partner', domain="[('division_of_company_id','=',company_id)]", string='Customer of the division')
    division_of_company_id = fields.Many2one('res.company', string='Division of the company')

class res_company(models.Model):
    _inherit = "res.company"
   
    division_ids = fields.One2many('res.partner','division_of_company_id', string="Divisions of this company")


In views

<record id="view_company_form" model="ir.ui.view">
            <field name="name">base.view.company.form.inherited.vtm2</field>
            <field name="model">res.company</field>
            <field name="inherit_id" ref="base.view_company_form" />
            <field name="arch" type="xml">
                <field name="website" position="after">
                    <field name="division_ids" widget="many2many_tags" string="Divisions of this company" />
                </field>
            </field>
</record>


<record id="view_partner_property_form_inherit" model="ir.ui.view">
            <field name="name">base.view.partner.form.inherit.vtm2</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="arch" type="xml">
                <field name="category_id" position="after">
                      <field name="customer_of_division_id" />
                    <field name="division_of_company_id" />
               </field>
            </field>
</record>


In images






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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
domain in many2one that in One2many field Solved
domain many2one one2many
Avatar
1
okt. 22
4017
Don't show equipment more than once
domain many2one one2many
Avatar
Avatar
1
avg. 19
3095
Odoo 9: Set domain for field in One2many
domain many2one one2many
Avatar
Avatar
1
sep. 17
5967
Display One2many field multiple time in same form Solved
domain form one2many
Avatar
Avatar
1
avg. 16
9552
Why is my many2one field not displayed the same way at this two places? Solved
address form view many2one
Avatar
Avatar
5
feb. 17
6566
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