Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
20 Respostes
77695 Vistes
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
Best Answer

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
Emipro Technologies Pvt. Ltd.
Best Answer

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
Tangaraj
Best Answer

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
Jacky
Best Answer

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

Avatar
Jose Angel Inda Herrera
Best Answer

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
Kirubanidhi Rajarathinam
Best Answer

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
Chandni Gandhi
Best Answer

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.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

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