Pular para o conteúdo
Odoo Menu
  • Entrar
  • Experimente grátis
  • Aplicativos
    Finanças
    • Financeiro
    • Faturamento
    • Despesas
    • Planilhas (BI)
    • Documentos
    • Assinar Documentos
    Vendas
    • CRM
    • Vendas
    • PDV Loja
    • PDV Restaurantes
    • Assinaturas
    • Locação
    Websites
    • Criador de Sites
    • e-Commerce
    • Blog
    • Fórum
    • Chat ao Vivo
    • e-Learning
    Cadeia de mantimentos
    • Inventário
    • Fabricação
    • PLM - Ciclo de Vida do Produto
    • Compras
    • Manutenção
    • Qualidade
    Recursos Humanos
    • Funcionários
    • Recrutamento
    • Folgas
    • Avaliações
    • Indicações
    • Frota
    Marketing
    • Redes Sociais
    • Marketing por E-mail
    • Marketing por SMS
    • Eventos
    • Automação de Marketing
    • Pesquisas
    Serviços
    • Projeto
    • Planilhas de Horas
    • Serviço de Campo
    • Central de Ajuda
    • Planejamento
    • Compromissos
    Produtividade
    • Mensagens
    • Aprovações
    • Internet das Coisas
    • VoIP
    • Conhecimento
    • WhatsApp
    Aplicativos de terceiros Odoo Studio Plataforma Odoo Cloud
  • Setores
    Varejo
    • Loja de livros
    • Loja de roupas
    • Loja de móveis
    • Mercearia
    • Loja de ferramentas
    • Loja de brinquedos
    Comida e hospitalidade
    • Bar e Pub
    • Restaurante
    • Fast Food
    • Hospedagem
    • Distribuidor de bebidas
    • Hotel
    Imóveis
    • Imobiliária
    • Escritório de arquitetura
    • Construção
    • Administração de propriedades
    • Jardinagem
    • Associação de proprietários de imóveis
    Consultoria
    • Escritório de Contabilidade
    • Parceiro Odoo
    • Agência de marketing
    • Escritório de advocacia
    • Aquisição de talentos
    • Auditoria e Certificação
    Fabricação
    • Têxtil
    • Metal
    • Móveis
    • Alimentação
    • Cervejaria
    • Presentes corporativos
    Saúde e Boa forma
    • Clube esportivo
    • Loja de óculos
    • Academia
    • Profissionais de bem-estar
    • Farmácia
    • Salão de cabeleireiro
    Comércio
    • Handyman
    • Hardware e Suporte de TI
    • Sistemas de energia solar
    • Sapataria
    • Serviços de limpeza
    • Serviços de climatização
    Outros
    • Organização sem fins lucrativos
    • Agência Ambiental
    • Aluguel de outdoors
    • Fotografia
    • Aluguel de bicicletas
    • Revendedor de software
    Navegar por todos os setores
  • Comunidade
    Aprenda
    • Tutoriais
    • Documentação
    • Certificações
    • Treinamento
    • Blog
    • Podcast
    Empodere a Educação
    • Programa de educação
    • Scale Up! Jogo de Negócios
    • Visite a Odoo
    Obtenha o Software
    • Baixar
    • Comparar edições
    • Releases
    Colaborar
    • Github
    • Fórum
    • Eventos
    • Traduções
    • Torne-se um parceiro
    • Serviços para parceiros
    • Cadastre seu escritório contábil
    Obtenha os serviços
    • Encontre um parceiro
    • Encontre um Contador
    • Conheça um consultor
    • Serviços de Implementação
    • Referências de Clientes
    • Suporte
    • Upgrades
    Github YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Faça uma demonstração
  • Preços
  • Ajuda

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

  • CRM
  • e-Commerce
  • Financeiro
  • Inventário
  • PoS
  • Projeto
  • MRP
All apps
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
Ajuda

onchange return domain for one2many product ID Field

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
domainone2manyonchange
7 Respostas
19865 Visualizações
Avatar
Prakash

Using (Sale Order) onchange Function how to add return domain for (Sale Order Line) one2many table Product ID Field?..

In Default onchange domain return example available for same table and column.

Example: return {'domain': {'column_name': [('id', 'in', listids)]}}

But how to add domain in one2many table Field using onchange method ?..

Requirement:-  Sale Order based on Partner selection dynamic add domain in Sale Order Line Product Field.

Code:

  def onchange_partner_id(self, cr, uid, ids, part, context=None):
        res = super(sale_order, self).onchange_partner_id(cr, uid, ids, part, context=context)       
        res['value'].update({'order_line': []})
        if part:
            product_obj = self.pool.get('product.product')
            matching_cust_ids = product_obj.search(cr, uid, [('x_cust_name','=',part)])            
            res['value'].update({'custproduct_id': matching_cust_ids})   
            domain = {'domain':{'order_line.product_id': [('order_line.id', '=', matching_cust_ids)]}}    
            res['value']['order_line'].append(domain)             
        return res       

Issue: The above code return domain for one2many table product Field is not working.

0
Avatar
Cancelar
Alex Gallien

For more background, what we were trying to do earlier (https://www.odoo.com/forum/help-1/question/limiting-customers-to-specific-products-58972) is link a customer and a product using a field on many2one field on the product page - 'x_cust_name': fields.many2one('res.partner', 'Customer', store=True). Ideally the module would only display the products that have the 'x_cust_name" equal to the name of the customer on the Sales Order.

Alex Gallien

Prakash - Janeesh's solution below worked! I think we were seriously overthinking things. Thanks again for your help, I really appreciate it.

Avatar
Janeesh
Melhor resposta

If field_id is a many2one field to partner, then you can simply give domain in xml for product_id field. Domain should be domain="[('field', '=', parent.partner_id)]"

11
Avatar
Cancelar
Alex Gallien

Ah of course it is way simpler than we were trying to make it. This worked perfectly using 'edit form view' from dev mode, but I am having trouble figuring out how to declare the xpath in my module. I am adding an answer with my code - if you could take a look I would really appreciate it.

Alex Gallien

Actually, scratch that - I figured it out. Thanks for the help!!

Avatar
John Daniel
Melhor resposta

If field_id is a many2one field to partner, then you can simply give domain in xml for product_id field. Domain should be domain="[('field_id', '=', parent.partner_id)]"

3
Avatar
Cancelar
Avatar
Alex Gallien
Melhor resposta

Janeesh - here is my attempt to implement your solution in a module. The domain isn't showing up for me right now, and I think it is because of my xpath declaration. Could someone help me figure out how to declare this domain correctly? Thanks!

EDIT: For anyone wondering the solution here, I think it had to do with the fact that the 'field' tag I was looking for was embedded past another field tag. The xpath that ended up working for me was:

 <xpath expr="//field[@name='order_line']/tree/field[@name='product_id']"

which actually could be shortened to 

xpath expr="//tree/field[@name='product_id']"

Here is my original (not functional) code.

   

    <record id="view_quotation_tree" model="ir.ui.view">

        <field name="name">sale.order.form</field>

        <field name="model">sale.order</field>

        <field name="inherit_id" ref="sale.view_order_form"/>

        <field name="arch" type="xml">

           <xpath expr="//field[@name='product_id']" position="replace">

              <field name="product_id" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}" groups="base.group_user" on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)" domain="[('x_cust_name', '=', parent.partner_id)]"/>

           </xpath>

        </field>

     </record>

0
Avatar
Cancelar
Está gostando da discussão? Não fique apenas lendo, participe!

Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!

Inscreva-se
Publicações relacionadas Respostas Visualizações Atividade
How to return domain on one2many field so that seleted values are not shown in next line
domain one2many onchange
Avatar
1
abr. 23
5897
How to update two levels o2m fileds relation
one2many onchange
Avatar
0
set. 20
3677
How i can Apply onchange method on one2many field ?
domain onchange
Avatar
Avatar
1
set. 19
5155
Several levels of One2many
one2many onchange
Avatar
0
abr. 16
3815
One2many onchange in ODOO Resolvido
one2many onchange
Avatar
Avatar
3
mar. 16
14851
Comunidade
  • Tutoriais
  • Documentação
  • Fórum
Open Source
  • Baixar
  • Github
  • Runbot
  • Traduções
Serviços
  • Odoo.sh Hosting
  • Suporte
  • Upgrade
  • Desenvolvimentos personalizados
  • Educação
  • Encontre um Contador
  • Encontre um parceiro
  • Torne-se um parceiro
Sobre nós
  • Nossa empresa
  • Ativos da marca
  • Contato
  • Empregos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidade
  • Segurança
الْعَرَبيّة 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 é um conjunto de aplicativos de negócios em código aberto que cobre todas as necessidades de sua empresa: CRM, comércio eletrônico, contabilidade, estoque, ponto de venda, gerenciamento de projetos, etc.

A proposta de valor exclusiva Odoo é ser, ao mesmo tempo, muito fácil de usar e totalmente integrado.

Site feito com

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