Odoo Help

0

Problem with making a view for settings of a custom module

By
Matthieu
on 6/27/16, 5:57 AM 1,145 views

Hello,


I'm currently making a custom module for Odoo 9 and I want to create a configuration view to set 3 values.

I have a view with a record to call it in an xml file :

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

  <field name="name">to.magento.form</field>

  <field name="model">to.magento</field>

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

   <form class="oe_form_configuration">

    <header>

     <button string="Apply" type="object" name="execute" class="oe_highlight"/>

     <button string="Cancel" type="object" name="cancel" class="oe_link"/>

    </header>

    <group string="General informations">

     <label for="id" string="URL"/>

     <div>

      <field name="url" class="oe_inline"/>

     </div>

      <label for="id" string="API User"/>

     <div>

      <field name="api_user" class="oe_inline"/>

     </div>

      <label for="id" string="API Key"/>

     <div>

      <field name="api_key" class="oe_inline"/>

     </div>

    </group>

   </form>

  </field>

</record>

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

  <field name="name">Configure Magento</field>

  <field name="res_model">to.magento</field>

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

  <field name="target">inline</field>

</record>

I have a model too in a python file :

class to_magento (osv.TransientModel):

  _inherit = 'res.config.settings'

  _name = 'to.magento'

 _columns = {

   'url' : fields.char('URL', size=32, select=2, required=True, help='An internal identification for this url'),

   'api_user' : fields.char('API User', size=32, select=3, required=True, help='An internal identification for this API User'),

   'api_key' : fields.char('API Key', size=32, select=4, required=True, help='An internal identification for this API Key'),

}

I have the following view that apear :

http://i.imgur.com/c2XqK77.png

When I use the Apply button, in the database, the values are recorded but when I reload the page, it show me void fields and when I apply again, a new line is created in the database.

My problem is here. I want to have only one line in the database with an unique value for each field, that is loaded when exists in my settings view.

How can I do that ?


Thank you in advance for your help !


0
Matthieu
On 6/30/16, 9:55 AM

My code is here, and it's still not working :

Python

class custom_config_settings(osv.osv_memory):

_name = 'custom.config.settings'

_inherit = 'res.config.settings'

_columns = {

'url' : fields.char('URL', size=32, required='True', select=2, help='An internal identification for this url'),

'api_user' : fields.char('API User', size=32, required='True', select=3, help='An internal identification for this API User'),

'api_key' : fields.char('API Key', size=32, required='True', select=4, help='An internal identification for this API Key'),

}

_defaults = {

'url': "",

'api_user': "",

'api_key': "",

}

def get_default_url(self, cr, uid, fields, context=None):

#some code...

#you can get the field content from some table and return it

#as a example

user_url=self.pool.get('custom.config.settings').browse(cr, uid, uid, context=context).url

return {'url': user_url}

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

#some code...

#you can get the field content from some table and return it

#as a example

config = self.browse(cr, uid, ids[0], context)

new_url=config.url

self.pool.get('custom.config.settings').write(cr, uid, uid, {'url': new_url})

def get_default_api_user(self, cr, uid, fields, context=None):

#some code...

#you can get the field content from some table and return it

#as a example

user_api_user=self.pool.get('custom.config.settings').browse(cr, uid, uid, context=context).api_user

return {'api_user': user_api_user}

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

#some code...

#you can get the field content from some table and return it

#as a example

config = self.browse(cr, uid, ids[0], context)

new_api_user=config.api_user

self.pool.get('custom.config.settings').write(cr, uid, uid, {'api_user': new_api_user})

def get_default_api_key(self, cr, uid, fields, context=None):

#some code...

#you can get the field content from some table and return it

#as a example

user_api_key=self.pool.get('custom.config.settings').browse(cr, uid, uid, context=context).api_key

return {'api_key': user_api_key}

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

#some code...

#you can get the field content from some table and return it

#as a example

config = self.browse(cr, uid, ids[0], context)

new_api_key=config.api_key

self.pool.get('custom.config.settings').write(cr, uid, uid, {'api_key': new_api_key})

XML

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

<field name="name">custom settings</field>

<field name="model">custom.config.settings</field>

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

<form string="Configure Accounting" version="7.0" class="oe_form_configuration">

<header>

<button string="Apply" type="object" name="execute" class="oe_highlight"/>

or

<button string="Cancel" type="object" name="cancel" class="oe_link"/>

</header>

<field name="url"/>

</form>

</field>

</record>

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

<field name="name">Custom Settings</field>

<field name="type">ir.actions.act_window</field>

<field name="res_model">custom.config.settings</field>

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

<field name="target">inline</field>

</record>

 Why ? Please, help me to understand ! I'm doing my best and the result is just an error popup saying "Record does not exist or has been deleted."




0
Axel Mendoza
On 6/27/16, 6:36 AM

Check this another thread that will show you a way to do it, clean and simple!!

https://www.odoo.com/forum/ayuda-1/question/how-to-save-and-update-custom-settings-in-odoo-transientmodel-93908#answer_93914

I tried but it currently doesn't work. I've got this message in the log file :

RuntimeError: maximum recursion depth exceeded while calling a Python object

My updated code is here :

http://pastebin.com/YC9karyq

Matthieu
on 6/27/16, 9:46 AM

still without working? please post your error logs

Axel Mendoza
on 7/5/16, 1:13 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 6/27/16, 5:57 AM
Seen: 1145 times
Last updated: 7/5/16, 1:13 AM