Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MY PYTHONS --
- class to_magento (osv.osv):
- _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'),
- }
- class ResConfigMagento(osv.TransientModel):
- _name = 'to.magento.settings'
- _inherit = 'res.config.settings'
- _columns = {
- 'magento_id' : fields.Many2one('to.magento', string='Magento'),
- 'url' : fields.Char(related='magento_id.url'),
- 'api_user' : fields.Char(related='magento_id.api_user'),
- 'api_key' : fields.Char(related='magento_id.api_key'),
- }
- def on_change_magento_id(self, cr, uid, ids, magento_id, context=None):
- _logger.critical('ON_CHANGE_MAGENTO_ID')
- if not magento_id:
- #This means it was never configged - default values here!
- return {'value': {'url': '', 'api_user': '', 'api_key': ''}}
- magento_data = self.pool.get('to.magento').read(cr, uid, [magento_id], [], context=context)[0]
- values = {
- 'url': magento_data['url'],
- 'api_user': magento_data['api_user'],
- 'api_user': magento_data['api_user'],
- }
- for fname, v in magento_data.items():
- if fname in self._columns:
- values[fname] = v[0] if v and self._columns[fname]._type == 'many2one' else v
- return {'value': values}
- def create(self, cr, uid, vals, context=None):
- _logger.critical('CREATE' + str (vals))
- config_id = super(ResConfigMagento, self).create(cr, uid, vals, context=context)
- self.write(cr, uid, config_id, vals, context=context)
- return config_id
- _defaults = {
- 'magento_id': lambda self,cr,uid,c: self.pool.get('to.magento').search(cr, uid, [], context=c)[0]
- }
- -- MY XML VIEW --
- <record id="view_magento_config_settings_form_pos" model="ir.ui.view">
- <field name="name">to.magento.form</field>
- <field name="model">to.magento.settings</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.settings</field>
- <field name="view_mode">form</field>
- <field name="target">inline</field>
- </record>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement