Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to open a new form when i click in a button?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
20 Respuestas
77702 Vistas
Avatar
Arunagiri K

I want to create button field . If i click a button it will show a new form . Please tell anyone how to create it  

Here is my code

myform.py

import time
from lxml import etree
import openerp.addons.decimal_precision as dp
import openerp.exceptions

from openerp import netsvc
from openerp import pooler
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _

 

class my_form(osv.osv):
            _name = "my.form"
            _description = 'Formview Module'
            _columns = {
               'name': fields.char('Name', size=64),
               'project': fields.char('Project', size=64),
               'image': fields.binary('Image'),
               'file':fields.binary('attach file')
 #~ def create_field(self, cr, uid, ids, context=None):              
}
my_form()

class my_form2(osv.osv):
        _name="my.form2"
        _description="new form"
        _columns={
          'add':fields.char('Address',size=64)
          }
my_form2()

myform_view.xml

<openerp>
    <data>
        <record model="ir.ui.view" id="from_view_form">
        <field name="name">form.view.form</field>
        <field name="model">my.form</field>
        <field name="arch" type="xml">
            <form string="Form" version="7.0">
                <group>
                    <field name="name" />
                    <field name="project" />
                    <button name="%(create_field)d" string="Create Field" type="action" />
                </group>
            </form>
        </field>
    </record>
        <record model="ir.ui.view" id="from_view_form2">
        <field name="name">form.view.form</field>
        <field name="model">my.form</field>
        <field name="arch" type="xml">
            <form string="Form" version="7.0">
               <group>
                   <field name="name"/>
               </group>
            </form>
        </field>
    </record>

         <record model="ir.ui.view" id="from_view_tree">
        <field name="name">form.view.tree</field>
        <field name="model">my.form</field>
        <field name="arch" type="xml">
            <tree string="Form">
                <field name="name" />
            </tree>
        </field>
    </record>    
        
        <record model='ir.actions.act_window' id='%(create_field)d'>
        <field name="name">Form</field>
        <field name="res_model">my.form</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="context">{}</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to create a new record.
            </p>
            <p>This is a test class developed to learn Openerp.</p>
        </field>
    </record>
    
    
        <record model='ir.actions.act_window' id='form_view_action'>
        <field name="name">Form</field>
        <field name="res_model">my.form</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{}</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to create a new record.
            </p>
            <p>This is a test class developed to learn Openerp.</p>
        </field>
    </record>

         <menuitem id="myform_ID" name="myforms" />

         <menuitem id="myform_menu_ID" name="myform" parent="myform_ID"  />

         <menuitem id="myform_menu2_ID" name="myform" parent="myform_menu_ID"  action='form_view_action' />

        
        
        
    </data>
    
    </openerp>

 

 

3
Avatar
Descartar
Arunagiri K
Autor

import time from lxml import etree import openerp.addons.decimal_precision as dp import openerp.exceptions from openerp import netsvc from openerp import pooler from openerp.osv import fields, osv, orm from openerp.tools.translate import _ class my_form(osv.osv): _name = "my.form" _description = 'Formview Module' _columns = { 'name': fields.char('Name', size=64), 'project': fields.char('Project', size=64), 'image': fields.binary('Image'), 'file':fields.binary('attach file') #~ def create_field(self, cr, uid, ids, context=None): } my_form() class my_form2(osv.osv): _name="my.form2" _description="new form" _columns={ 'add':fields.char('Address',size=64) } my_form2()

Arunagiri K
Autor

i try myself but its not working please tell me ef create_field(self,cr, uid, ids,create_field, context={}): if not ids: return False if context is None: context={} model_data_pool = self.pool.get('ir.model.data') view = model_data_pool.get_object(cr, uid, 'my_form2', 'view_copy_multiple', context=context) return{ 'name': _("Copy multiple records"), 'type': 'ir.actions.act_window', 'view_mode': 'form', 'view_id': [view.id], 'view_type': 'form', 'res_model': 'my.form', 'nodestroy': True, 'target': 'new', 'context': context, 'res_id': ids, }

Avatar
Indrabhan Bhamare
Mejor respuesta

Hello May be this will help you.

You can define object type button and return action.

example.py and example.xml

    @api.multi
def method_name(self):
view_id = self.env.ref('modul_name._id_of_form_view').id
context = self._context.copy()
return {
'name':'form_name',
'view_type':'form',
'view_mode':'tree',
'views' : [(view_id,'form')],
'res_model':'model_name',
'view_id':view_id,
'type':'ir.actions.act_window',
'res_id':self.id,
'target':'new',
'context':context,
}

<button name="method_name" string="open_form" type="object"/> 
8
Avatar
Descartar
Avatar
Tangaraj
Mejor respuesta

Hi

Try like this ...

<button type="action" string="submit" name= "%(module_name.form_action_id)d" class="oe_highlight"/>

which form u want open,put ur id mentioned in  above line( form_action-id),,, <record model="ir.ui.view" id="......."


3
Avatar
Descartar
Avatar
Emipro Technologies Pvt. Ltd.
Mejor respuesta

Hi,

<button name="%(create_field)d" string="Create Field" type="action" />

Button with type "action" is like above will call the action with ID="create_field". So, you have to make one action with ID = "create_field".

But you have created action with ID = "%(create_field)d" is not good. please change it with ID = "create_field"

I hope this will help you. If you have still any issue then let me know.

Or 

You can put the button type="object" and make one function into python with same name as button name.

in your case :

<button name="create_field" string="Create Field" type="object" />

In your python code put the function as like below.

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

        return {
            'name': _('My Form'),
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'my.form',
            'view_id': False,
            'type': 'ir.actions.act_window',
        }

It will open one window to create record of the model 'my.form'. If you want to open window to create 'my.form2' then just replate 'res_model' value with 'my.form2'.

thats it.

 

3
Avatar
Descartar
Arunagiri K
Autor

I already try that one but its not working . Any changes in function for action of button in python file if you know please tell me

Emipro Technologies Pvt. Ltd.

Then you have to take button type="object" and then return the form view from that button click function. When you take type="object" then system will call the function of python as same name of that button.

Arunagiri K
Autor

Hi i change type ="object" but i got an error like this AttributeError: 'my.form' object has no attribute 'create_field'

Arunagiri K
Autor

Thats the thing i asked how to write a function i don't know i'm new to openerp if you tell about that it will helpfull to me . This is my test project only i just want to learn please help me

Emipro Technologies Pvt. Ltd.

Hello, I have update my answer please have a look on it.

Arunagiri K
Autor

def create_field(self,cr, uid, ids,create_field, context={}): if not ids: return False if context is None: context={} model_data_pool = self.pool.get('ir.model.data') view = model_data_pool.get_object(cr, uid, 'my_form2', 'view_copy_multiple', context=context) return{ 'name': _("Copy multiple records"), 'type': 'ir.actions.act_window', 'view_mode': 'form', 'view_id': [view.id], 'view_type': 'form', 'res_model': 'my.form', 'nodestroy': True, 'target': 'new', 'context': context, 'res_id': ids, }

Arunagiri K
Autor

Hi i follow your code instructions i'm working odoo 8 i had an error again here is the error message : AccessError The requested operation cannot be completed due to security restrictions. Please contact your system administrator. (Document type: ir.actions.actions, Operation: read)

Emipro Technologies Pvt. Ltd.

For that you have to make sure that user have an access rights for the model ir.actions.actions. Thats it. you can also give access rights to a particular model via setting => Technical => Security => Access control List.

Arunagiri K
Autor

Hi i change the Access control list till i got an error please give me any suggestion

Avatar
Chandni Gandhi
Mejor respuesta

Hi,

Refer this site, it might be help u.

http://www.odooclass.com/shop/product/how-to-create-custom-smart-buttons-in-odoo-8-24


Creating Smart Buttons in Odoo

1. Add required fields to the model so you can store your calculations

voucher_count = fields.Integer(compute='_voucher_count', string='# of Vouchers')

account_voucher_ids = fields.One2many('account.voucher', 'partner_id', 'Voucher History')

2. Create a custom view template and use the interhit id that matches the external id of the form 

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

<field name="name">view.res.partner.form.crm.inherited2</field> <field name="model">res.partner</field> <field name="priority" eval="200"/> <field name="inherit_id" ref="base.view_partner_form"/>

3. Use xpath in the template to tell the Odoo framework where to place your button

<xpath expr="//div[@name='buttons']" position="inside">

4. Add your Odoo smart button code to the view

<button class="oe_inline oe_stat_button" type="action" name="%(pay_view_voucher_tree)d" attrs="{'invisible': [('customer', '=', False)]}" icon="fa-usd"> <field string="Payments" name="voucher_count" widget="statinfo"/> </button>

5. Create a python function to calcuate the functional field (voucher_count)

@api.one @api.depends('account_voucher_ids','account_voucher_ids.state')

def _voucher_count(self):

        vouchers = self.env['account.voucher'].search([('partner_id', '=', self.id)])

        self.voucher_count = len(vouchers)


6. . Create a view for the action to display your results (payments in this case) when the user clicks the button

<record model="ir.actions.act_window" id="pay_view_voucher_tree">

<field name="name">Payments</field>

<field name="res_model">account.voucher</field>

<field name="view_type">form</field>

<field name="view_mode">tree,form,graph</field>

<field name="context">{'search_default_partner_id': active_id}</field>

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

          <tree string="Payments">

               <field name="date"/> <field name="number"/> <field name="reference"/> <field name="partner_id"/>

                <field name="type" invisible="context.get('visible', True)"/> <field name="amount" sum="Total Amount"/> <field name="state"/>

         </tree>

  </field>

</record>

If you found this as correct, please mark this as correct. Thanks.

0
Avatar
Descartar
Purnendu Singh

Your answer is not relevant to this question! He simply want a button which will open a form view. Say for example our sale order line set as editable top. And we want to put a new button on sale order line which will popup sale order line form view in which we can edit things.

Avatar
Kirubanidhi Rajarathinam
Mejor respuesta

In odoo 9 , 

We apply for this way


<button string="Library details" type="object"

class="oe_highlight oe_right" name="library_method" icon="fa-fire" >

</button>

@api.multi

def library_method(self):

print self._context

course_form = self.env.ref('college.return_form', False)

return {

'name': 'New Course',

'type': 'ir.actions.act_window',

'res_model': 'college.return',

'view_type': 'form',

'view_mode': 'tree,form',

'target': 'self',

'views': [(course_form.id, 'form')],

'view_id': 'course_form.id',

'flags': {'action_buttons': True},

}

0
Avatar
Descartar
ANSU MARY JACOB

hey how to visible a tab while clicking a button , the condition where 2 boolean field is true

Kirubanidhi Rajarathinam
Create a new wizard form. 

Check the existing code by using 



api.multi
def method_name(self):
view_id = self.env.ref('modul_name._id_of_form_view').id
context = self._context.copy()
return {
'name':'form_name',
'view_type':'form',
'view_mode':'tree',
'views' : [(view_id,'form')],
'res_model':'model_name',
'view_id':view_id,
'type':'ir.actions.act_window',
'res_id':self.id,
'target':'new',
'context':context,
}



On Tue, 2 Nov, 2021, 6:08 pm ANSU MARY JACOB, <ansu@zbeanztech.com> wrote:

hey how to visible a tab while clicking a button , the condition where 2 boolean field is true

Sent by Odoo S.A. using Odoo.

Avatar
Jose Angel Inda Herrera
Mejor respuesta

I agree with Arunagiri, that is the way to resolve your problem and, in the action dict definition, you push also the 'target' property to show modal dialog

0
Avatar
Descartar
Arunagiri K
Autor

You know about the module if you let me know please ................!!!!

Avatar
Jacky
Mejor respuesta

Question is not clear. Give an example. I think you can make it through a wizard.

0
Avatar
Descartar
Arunagiri K
Autor

i add a button in my module i want to new form when i click a button

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

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