Skip to Content
Menu
This question has been flagged
3 Replies
5788 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 !


Avatar
Discard
Author Best Answer

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."




Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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

still without working? please post your error logs

Related Posts Replies Views Activity
4
Dec 24
14791
1
Jun 24
623
1
May 24
323
1
Nov 23
684
1
Mar 24
1374