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 set values to one2many field from js

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
javascriptone2manysessionrpcTechnical
1 Responder
4507 Visualizações
Avatar
Dino Varghese

Hi,

I need to set change some values in one2many from js dynamically, And also need to add a new line from js to one2many. The values for one2many field will be saved in the browser storage . So need to fetch the data from the session storage and need to do the changes in the one2many without using the RPC. 

0
Avatar
Cancelar
Avatar
Ashish Hirpara
Melhor resposta

To update values in a one2many field in Odoo from JavaScript, you can use the update_values method on the one2many field widget instance. This method takes an array of objects with the id and value properties, where id is the id of the record in the one2many field and value is the new value for that record.

Here is an example of how you can use this method to update values in a one2many field:

// Get the one2many field widget instance
const fieldWidget = this.field_manager.fields.my_one2many_field;

// Fetch the data from the session storage
const data = JSON.parse(sessionStorage.getItem('my_one2many_field_data'));

// Map the data to an array of objects with the required format for the `update_values` method
const values = data.map(item => ({
    id: item.id,
    value: item.value,
}));

// Use the `update_values` method to update the values in the one2many field
fieldWidget.update_values(values);

To add a new line to a one2many field from JavaScript, you can use the add_record method on the one2many field widget instance. This method takes an object with the value property, where value is the value for the new record.

Here is an example of how you can use this method to add a new line to a one2many field:

Copy code// Get the one2many field widget instance
const fieldWidget = this.field_manager.fields.my_one2many_field;

// Fetch the value for the new record from the session storage
const value = JSON.parse(sessionStorage.getItem('my_one2many_field_new_record'));

// Use the `add_record` method to add a new line to the one2many field
fieldWidget.add_record({ value });

Keep in mind that these changes will only be visible in the frontend and will not be saved in the database unless you explicitly call the save method on the form view.

0
Avatar
Cancelar
Bluerate

How to call below in V15?:

const fieldWidget = this.field_manager.fields.my_one2many_field;

fieldWidget.update_values(values);

Bluerate

Also how to set selected field on one2many filed to sessionStorage before getting it from sessionStorage, tried with below code but not working?

sessionStorage.setItem('soc_budget', JSON.stringify({
targetType: $(event.currentTarget).find('tr.o_data_row').data('id'),
}));

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
JavaScript RPC with public user: Session expired
javascript session rpc
Avatar
Avatar
1
jun. 15
9437
How to find the view_id using rpc call from JavaScript
javascript rpc
Avatar
Avatar
2
jan. 23
6714
Catch is not a function
javascript rpc
Avatar
0
fev. 21
4287
rpc.query doesn't work
javascript rpc odoo
Avatar
Avatar
1
ago. 23
411
How to use RPC query in JavaScript with search method in Odoo 11 / 12?
javascript rpc odoov11
Avatar
Avatar
1
set. 21
21586
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