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

[solved] domain restriction and clear the previously selected value of a many2one field

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
domainmany2one
2 Respostas
13372 Visualizações
Avatar
Romuald Franck

Hi to everyone!

I have two many2one fields (list1 and list2) in the same class and view. I want when a user select a value from list1, the list2 to automatically update with a restriction domain value. this is done

But I also want the 'previously' selected value of list2 to be drop so that the user is force to reselect it, in the case he has previously selected a value in list2 and then reselect in list1. Because domain restriction only update the list2 but leave the previously (now not pertinant) value of list2 and the user can pass. Thx to any help!

0
Avatar
Cancelar
Avatar
Brett Lehrer
Melhor resposta

You need to add an onchange event to list1. Would look something like this in the XML:

<field name="list1" on_change="my_onchange_function(list1)"/>

Then you'd need a function in that object with the name listed in on_change, which is hopefully a better name than my example:

def my_onchange_function(self, cr, uid, ids, list1, context=None):
    if context is None: context = {}
    # If there's a value in list1 now, empty list2.
    res = {}
    if list1:
        res['list2'] = False
        res['list3'] = False
        res['some_number'] = 0
    return {'value': res}

You could add in a few more features to make the onchange function a bit smarter, but that will basically do the job.

1
Avatar
Cancelar
Romuald Franck
Autor

Thank you it works. I have put another on_change action on list2 and it was that which gave me errors. I have fixed it. Please How to return many value for several fields at a time. Thx

Brett Lehrer

Just keep adding dictionary entries to res. I'll edit the answer to change multiple values at once.

Avatar
Romuald Franck
Autor Melhor resposta

I tried it but got and error. Please look . Here is my onchange def :

def on_change_salle_de_classe_id(self,cr,uid,ids,salle_de_classe_id,context=None):
    salle_de_classe = self.pool.get('schoolem.salle_de_classe').browse(cr,uid,salle_de_classe_id)

    cours_obj = self.pool.get('schoolem.cours')
    ids1 = cours_obj.search(cr, uid, [('niveau_id.id', '=', salle_de_classe.classe_id.niveau_id.id)])
    ids2 = cours_obj.search(cr, uid, [('niveau_id.id', '=', salle_de_classe.classe_id.niveau_id.id),('specialite_id.id', '=', salle_de_classe.classe_id.specialite_id.id)])
    if context is None: context = {}
    # If there's a value in list1 now, empty list2.
    res = {}        
    if salle_de_classe_id:
        res['cours_id'] = False
    return {'value': res}
    #return {'domain':{'cours_id':[('id','in',ids1+ids2)]}}
    #return {'value':{'cours_id':False},'domain':{'cours_id':[('id','in',ids1+ids2)]}}

but I got this error :

ProgrammingError: ERREUR: l'opérateur n'existe pas : integer = boolean LINE 1: ....id FROM "schoolem_cours" WHERE schoolem_cours.id IN (false)...
^ HINT: Aucun opérateur ne correspond au nom donné et aux types d'arguments. Vous devez ajouter des conversions explicites de type.

0
Avatar
Cancelar
Brett Lehrer

This is a type casting error due to the fact that one of the IDs you're filtering on is actually not set at all. Make sure you're checking that ids1 and ids2 both have values in them first before returning them into the domain. Both are currently returning empty lists, which translates to False, generating an error down the road. Also, since ids2 is a subset of ids1, there will be duplicate ids in the combined list, and a quick way to fix that before passing it along is to use list(set(ids1+ids2)). Convert to a set to remove duplicates, then back to a list.

Romuald Franck
Autor

I tried this :return {'domain':{'cours_id':[('id','in',list(set(ids1+ids2)))]},'value':{'cours_id':False}} but still have the same error. Even without using domain

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
Domain with inherited field Resolvido
domain many2one
Avatar
1
out. 22
4511
Error in Creating Dynamic Domain for many2one field from onchange method in OpernErp v7 ???
domain many2one
Avatar
Avatar
Avatar
8
fev. 17
9113
Domain One2many filter
domain many2one
Avatar
0
jan. 17
6397
Set dynamic domain on fields based on other fields value Resolvido
domain many2one edit
Avatar
Avatar
Avatar
Avatar
4
mai. 24
19445
domain in many2one that in One2many field Resolvido
domain many2one one2many
Avatar
1
out. 22
4053
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