Advertisement
Guest User

Updated settings

a guest
Jun 27th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. -- MY PYTHONS --
  2.  
  3. class to_magento (osv.osv):
  4. _name = 'to.magento'
  5. _columns = {
  6. 'url' : fields.Char('URL', size=32, select=2, required=True, help='An internal identification for this url'),
  7. 'api_user' : fields.Char('API User', size=32, select=3, required=True, help='An internal identification for this API User'),
  8. 'api_key' : fields.Char('API Key', size=32, select=4, required=True, help='An internal identification for this API Key'),
  9. }
  10.  
  11. class ResConfigMagento(osv.TransientModel):
  12. _name = 'to.magento.settings'
  13. _inherit = 'res.config.settings'
  14.  
  15. _columns = {
  16. 'magento_id' : fields.Many2one('to.magento', string='Magento'),
  17. 'url' : fields.Char(related='magento_id.url'),
  18. 'api_user' : fields.Char(related='magento_id.api_user'),
  19. 'api_key' : fields.Char(related='magento_id.api_key'),
  20. }
  21.  
  22. def on_change_magento_id(self, cr, uid, ids, magento_id, context=None):
  23. _logger.critical('ON_CHANGE_MAGENTO_ID')
  24. if not magento_id:
  25. #This means it was never configged - default values here!
  26. return {'value': {'url': '', 'api_user': '', 'api_key': ''}}
  27. magento_data = self.pool.get('to.magento').read(cr, uid, [magento_id], [], context=context)[0]
  28. values = {
  29. 'url': magento_data['url'],
  30. 'api_user': magento_data['api_user'],
  31. 'api_user': magento_data['api_user'],
  32. }
  33. for fname, v in magento_data.items():
  34. if fname in self._columns:
  35. values[fname] = v[0] if v and self._columns[fname]._type == 'many2one' else v
  36. return {'value': values}
  37.  
  38. def create(self, cr, uid, vals, context=None):
  39. _logger.critical('CREATE' + str (vals))
  40. config_id = super(ResConfigMagento, self).create(cr, uid, vals, context=context)
  41. self.write(cr, uid, config_id, vals, context=context)
  42. return config_id
  43.  
  44. _defaults = {
  45. 'magento_id': lambda self,cr,uid,c: self.pool.get('to.magento').search(cr, uid, [], context=c)[0]
  46. }
  47.  
  48. -- MY XML VIEW --
  49.  
  50. <record id="view_magento_config_settings_form_pos" model="ir.ui.view">
  51. <field name="name">to.magento.form</field>
  52. <field name="model">to.magento.settings</field>
  53. <field name="arch" type="xml">
  54. <form class="oe_form_configuration">
  55. <header>
  56. <button string="Apply" type="object" name="execute" class="oe_highlight"/>
  57. <button string="Cancel" type="object" name="cancel" class="oe_link"/>
  58. </header>
  59. <group string="General informations">
  60. <label for="id" string="URL"/>
  61. <div>
  62. <field name="url" class="oe_inline"/>
  63. </div>
  64. <label for="id" string="API User"/>
  65. <div>
  66. <field name="api_user" class="oe_inline"/>
  67. </div>
  68. <label for="id" string="API Key"/>
  69. <div>
  70. <field name="api_key" class="oe_inline"/>
  71. </div>
  72. </group>
  73. </form>
  74. </field>
  75. </record>
  76.  
  77. <record id="action_magento_configuration" model="ir.actions.act_window">
  78. <field name="name">Configure Magento</field>
  79. <field name="res_model">to.magento.settings</field>
  80. <field name="view_mode">form</field>
  81. <field name="target">inline</field>
  82. </record>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement