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

how to limit the total number values for a one2many field?

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
one2manylimitvaluefor
5 Respostas
13700 Visualizações
Avatar
Vivekrajan Rayappan

Hi,

I would like to have a feature on the one2many field. Usually we can add any number of values to a one2many field. But I want restrict the user to enter only the first three values and not more than three. Three is just an example count. I should be able to define it to any number.

To be more clear, I want the user to enter only 3 line items in the sales order. After entering 3 line items, the create/add option should disappear.

Is there any way already existing? or is it to be implemented yet?

Thanks in advance.

0
Avatar
Cancelar
Avatar
Prakash
Melhor resposta

I have solution but without disappear Create/add option. To override create and write method and allow to user enter only 3 lines item.

Example:-

def create(self, cr, uid, vals, context=None):
       if vals.get('order_line'):
            count = len(vals.get('order_line'))
            if count > 3:
                raise osv.except_osv(_('Warning!'), _('Limit to create 3 Lines'))
        return super(sale_order, self).create(cr, uid, vals, context=context)

def write(self, cr, uid, id, vals, context=None):
    if vals.get('order_line'):
        count = len(vals.get('order_line'))
        if count > 3:
            raise osv.except_osv(_('Warning!'), _('Limit to create 3 Lines'))
    return super(sale_order, self).write(cr, uid, id, vals, context=context)
3
Avatar
Cancelar
Vivekrajan Rayappan
Autor

Prakash, that works but a little late while saving the form. But It should work instantly as we try to add the fourth one. Because, i will be able to add more than 3 upto any number with your solution and it is going to warn me only at the moment of saving the form. my time of entering more than 3 should be saved right upfront. I think it is only possible if we make changes in the x2many widget java scripts

Avatar
Ameen Rabea
Melhor resposta

I posted similar question of yours, but I need when user add more than , let's say, 5 items I warn him and delete the extra elements.

I was able to do onchange method, but I am not able to delete the extra items he added. Also I don't need to wait until the user click the parent "Save" button, but I need once he added the extra child element I delete it before waiting until save.

I tried to delete the extra item from child_ids list, or to use the unlink function but of Parent and Child, but no luck =(

How to delete the extra elements?


here is my post: 

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-prevent-adding-more-than-x-items-into-one2many-98375



0
Avatar
Cancelar
Avatar
Vivekrajan Rayappan
Autor Melhor resposta

Hi,

I have found a solution that best suits my requirement. That is to have a on_change method for the x2many field and check the count using len() python function. If it is more than 3 or x number, then popup a error message.

Apart from these, there are two other solutions. they have been mentioned already by Yug Faa and Prakash. i.e

1) Customize the x2many widget using js

2) Inherit the create and write method

Thanks to Prakash and Yug for their contribution.

0
Avatar
Cancelar
Avatar
Yug Faa
Melhor resposta

You will find a addons here :

bzr branch lp:~sylvain-legal/web-addons/web_field_float_compute

Module named : web_m2x_options

Make it resolved !

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 set limit row in tree view one2many in form view?
one2many limit
Avatar
Avatar
Avatar
Avatar
4
dez. 16
16362
How to go through a one2many field that contains text and the information obtained put it in another field
one2many for v15
Avatar
Avatar
1
out. 23
2087
How To prevent adding more than X items into One2Many Resolvido
one2many limit prevent
Avatar
Avatar
1
fev. 16
9450
How to set limit of items for one2many list view?
one2many limit pagination
Avatar
1
mar. 15
7780
Set max limit of rows one2many may contain
one2many v7 limit records
Avatar
Avatar
1
abr. 24
7169
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