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 filter One2many field base on Many2one field? odoo 12

Subscriure's

Get notified when there's activity on this post

This question has been flagged
2 Respostes
6195 Vistes
Avatar
jonathankabre1@gmail.com

hello,
how can i filter my One2many field base on Many2one field?

exemple, i have 2 classes like:

--------begin-----------
class btp_caution(models.Model):
    _name = "btp.caution"
    _description = "Les cautions"

    name = fields.Char(string='Libellé caution', required=True)
    nemero = fields.Char(string='Numéro caution')
    banque_id = fields.Many2one('btp.banque', 'Banque')
    projet_id = fields.Many2one('btp.projet', 'Projet')
    etat_caution = fields.Many2one('btp.etatcaution', 'etat_caution_')

class btp_etatcaution(models.Model):
    _name = "btp.etatcaution"
    _description = "voir les etats des differentes cautions filtres par banque et par projet/marche"
    _auto = 'False'

    name = fields.Char('Name')
    banque_id = fields.Many2one('btp.banque', 'Banque')
    projet_id = fields.Many2one('btp.projet', 'Projet')
    ligne_caution_etat = fields.One2many('btp.caution', 'etat_caution', 'etat_caution')
--------end-----------

and i have view related to this last one (btp.etatcaution) like:

--------begin-----------
<record id="view_btp_etatcaution_form" model="ir.ui.view">
    <field name="name">etatcaution</field>
    <field name="model">btp.etatcaution</field>
    <field name="arch" type="xml">
        <form string="etatcaution" class="oe_form_configuration" create="false">
            <sheet>
                <group>
                    <field name="banque_id" class="oe_inline"/>
                    <field name="projet_id" class="oe_inline"/>
                </group>
            </sheet>
            <notebook>
                <page string="Etat caution">
                    <div class="row"><div class="col-xs-12 text-muted">
                    <field name="ligne_caution_etat" >

                        <tree editable="bottom" string="Etat caution" create="false">
                            <field name="name"/>
                            <field name="nemero"/>
                            <field name="banque_id"/>
                            <field name="projet_id"/>
                        </tree>
                </field>
                </div></div>
            </page>
        </notebook>
    </form>
    </field>
</record>
<record id="action_etatcaution" model="ir.actions.act_window">
    <field name="name">etatcaution</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">btp.etatcaution</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="res_id">1</field>
    <field name="view_id" ref="view_btp_etatcaution_form"/>
</record>
--------end-----------

how can i do to filter my notebook data in oder to return only record which banque_id and projet_id are choosed in the form view?
e.g : the value of banque_id and projet_id in all notebook lines should be the same that those we have shoosed in <sheet> .... </sheet>



0
Avatar
Descartar
Sehrish

Read this documentation for odoo customization: https://learnopenerp.tumblr.com/

Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

If you want to set default value of O2m field from the field of your parent object, you can pass default value in the context of O2m field.

Try following code:

<field name="ligne_caution_etat"
       context="{'default_banque_id': banque_id, 'default_projet_id': projet_id}"> 

Let me know if you are trying something else.

2
Avatar
Descartar
jonathankabre1@gmail.com
Autor

Nothing change on my view. Insn't it any way to use filtered() in the model side like:

class btp_etatcaution(models.Model):

...

ligne_caution_etat = fields.One2many('btp.caution', 'etat_caution', 'etat_caution').filtered(lambda r: r.banque_id == "etat_caution.banque_id")

Avatar
Apanda
Best Answer

Try this:

<field name="ligne_caution_etat" domain=[('banque_id', '=', parent.banque_id)]>

.....

</field>

0
Avatar
Descartar
jonathankabre1@gmail.com
Autor

e

jonathankabre1@gmail.com
Autor

mothing change on my view. insn't any way to use filter in the model side like:

class btp_etatcaution(models.Model):

...

ligne_caution_etat = fields.One2many('btp.caution', 'etat_caution', 'etat_caution').filtered(lambda r: r.banque_id == "etat_caution.banque_id")

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