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 open a form with ir.action.server which executes python code

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
pythonxmlformformview
2 Respostas
49729 Visualizações
Avatar
Eric

Hello, 

  I have a custom module that has a new item in the "More" contextual dropdown menu.  When the item is clicked, it calls an action saved to the ir.action.server.  The action executes python code like it's supposed to.  The python code creates a new record on the sale.order table and is supposed to open the sale.order form with the newly created record.  I have a return statement at the end of the python code which is supposed to open the sale.order form, but for some reason it isn't.  I don't understand why, because the same return statement works on other function calls except this one.  Can anyone help me open the sale.order form after my function has created a new record on the sale.order model?

Here is the code that adds the line to the "More" contextual dropdown:

<record model="ir.values" id="test_more_item">
            <field name="name">New More Item</field>
            <field name="model" eval="'sale.licenses'" />
            <field name="key" >action</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.server,%d'%sale_license_more_item_action" />
            <field name="object" eval="True" />
        </record>

 

This is the action the the "More" item calls.  its from the ir.action.server

<record id="sale_license_more_item_action" model="ir.actions.server">
            <field name="name">Renew Licenses</field>
            <field name="type">ir.actions.server</field>
            <field name="res_model">sale.order</field>
            <field name="model_id" >283</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="state">code</field>
            <field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>
        </record>

 

This is the function that is called from the server action

def renew_license(self, cr, uid, ids, context=None):

     ...(code that creates new sale.order record)

     return {
            'name': 'Sale Order Form',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': self.pool.get('ir.ui.view').search(cr, uid, [('name','=','sale.order.form')])[0],
            'res_model': 'sale.order',
            'res_id': new_order_id,
            'type': 'ir.actions.act_window',
        }

Normally the return statement would open the sale.order form, but in this case it isn't.  Does anyone know what I am doing wrong with this?

4
Avatar
Cancelar
Avatar
Eric
Autor Melhor resposta

I finally got the answer right.  Thanks to Maniganda's answer found on this link: 

https://www.odoo.com/forum/help-1/question/call-function-from-the-more-dropdown-list-61330

 

All I needed to do was change this line:

<field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>

 

To this:

<field name="code">action = self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>

 

Thank you Maniganda!

9
Avatar
Cancelar
Ubaid ur Rehman

Thanks @Eric and @Maniganda your answer save my time.

Avatar
Ben Bernard
Melhor resposta

This is my guessing (I never do this). I think the problem is that new sale order, new_order_id, record hasn't been commited. As far as I know odoo commit transaction at the end of request. So when the method return an action, odoo makes the action void because new_order_id is not available yet.

0
Avatar
Cancelar
Eric
Autor

Hello Ben, I tried testing this by using an ID of another sale order, but it still didn't open the form view. Thanks for your reply

Sehrish

Server Action in Odoo: http://learnopenerp.blogspot.com/2020/01/odoo-server-action.html

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
Dynamic form depending of values in a one2many
python xml form v14
Avatar
0
jun. 21
3707
Embedding youtube video in form view
xml form view video formview
Avatar
Avatar
1
out. 24
2538
How to edit sign up form for new customers on your website Resolvido
python xml web form website
Avatar
Avatar
2
mai. 24
9735
How to hide view.xml fields group in Account module with attr
python xml
Avatar
Avatar
Avatar
2
dez. 23
13976
how to remove first empty element from fields.selection Resolvido
python xml
Avatar
Avatar
Avatar
3
jul. 22
24406
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