Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • 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 Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and 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
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
domainformviewmany2oneone2many
3 Replies
27268 Zobrazenia
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
Zrušiť
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
Zrušiť
Pascal Tremblay
Autor

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
Autor 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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
domain in many2one that in One2many field Solved
domain many2one one2many
Avatar
1
okt 22
4015
Don't show equipment more than once
domain many2one one2many
Avatar
Avatar
1
aug 19
3085
Odoo 9: Set domain for field in One2many
domain many2one one2many
Avatar
Avatar
1
sep 17
5960
Display One2many field multiple time in same form Solved
domain form one2many
Avatar
Avatar
1
aug 16
9551
Why is my many2one field not displayed the same way at this two places? Solved
address form view many2one
Avatar
Avatar
5
feb 17
6563
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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