Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to implement view for just one record (used to keep configuration data)?

By
Maxim Litnitskiy
on 9/26/14, 9:52 AM 618 views

res.config,settings is used for automatic module installing and other difficult thing. 

Its name is misleading because it is not used to keep application configuration. Or I simply did not get it right.

So I implemented the following.

1
Maxim Litnitskiy
On 9/26/14, 9:53 AM

from openerp import fields, models, api, _

class server_settings(models.Model):
    _name = 'asterisk.server.settings'

    ari_url = fields.Char(required=True, string=_('Server URL'))
    ari_user = fields.Char(required=True, string=_('ARI username'))
    ari_pass = fields.Char(required=True, string=_('ARI password'))
    context_name = fields.Char(required=True, string=_('Dialplan context'))
    

    _defaults = {
        'ari_url': 'http://localhost:8088',
        'context_name': 'dialer',
        'ari_user': '',
        'ari_pass': '',
    }
    
    @api.one
    def execute(self):
        print self.ari_url, self.ari_user
        
        
    @api.one
    def clear(self):
        self.ari_user = ''
        self.ari_pass = ''

 

<openerp>
<data>

        <record id="view_asterisk_server_settings" model="ir.ui.view">
            <field name="name">Asterisk Server Settings</field>
            <field name="model">asterisk.server.settings</field>
            <field name='type'>form</field>
            <field name="arch" type="xml">
                <form string="Configure Asterisk Server">
                    <header>
                        <button string="Apply" type="object" name="execute" class="oe_highlight"/>
                        or
                        <button string="Clear" type="object" name="clear" class="oe_link"/>
                    </header>
                    <separator string="ARI Connection Information"/>
                    <group name="Server">
                        <label for="id" string="Asterisk HTTP server URL"/>
                        <div>
                            <div>
                                <field name="ari_url" class='oe_inline'/>
                                <label for="name" string='Usually http://localhost:8088, see http.conf.'/>
                            </div>
                        </div>
                    </group>                    
                    <div string='ARI configuration'>
                    <group name="ARI">
                        <label for="id" string="ARI access"/>
                        <div>
                            <div>
                                <field name="ari_user" class='oe_inline'/>
                                <label for="ari_user"/>
                            </div>
                            <div>
                                <field name="ari_pass" class='oe_inline'/>
                                <label for="ari_pass"/>
                            </div>
                        </div>                        
                    </group>                    
                   <group name="Dialplan">
                        <label for="id" string="Asterisk Dialplan for Dialer"/>
                        <div>
                            <div>
                                <field name="context_name" class='oe_inline'/>
                                <label for="context_name" string='Dialplan context name, see README for details'/>
                            </div>
                        </div>                        
                    </group>                    
                </form>
            </field>
        </record>

        <record id="action_asterisk_server_settings" model="ir.actions.act_window">
            <field name="name">Asterisk Dialer</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">asterisk.server.settings</field>
            <field name="view_id" ref="view_asterisk_server_settings"/>
            <field name='view_type'>form</field>
            <field name="view_mode">form</field>
            <field name="target">inline</field>
            <field name='res_id'>1</field>
        </record>
        
        <menuitem id="menu_asterisk_server_settings" parent="base.menu_config"
            sequence="200" action="action_asterisk_server_settings"/>
            
    </data>
</openerp>

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/26/14, 9:52 AM
Seen: 618 times
Last updated: 3/16/15, 8:10 AM