Hi guys,
I've created a new view which should always only allow one record, so I've made a view just like under Settings > Configuration.
1) Create a menu item
<menuitem id="menu_tech_settings_screen" action="technical_details_odoo_installer_action" parent="server_main_menu" sequence="30"/>
2) Add an act_window behind it:
<record id="technical_details_odoo_installer_action" model="ir.actions.act_window"> <field name="name">Configure settings</field> <field name="type">ir.actions.act_window</field> <field name="res_model">odoo.environment.technical.settings</field> <field name="view_id" ref="configure_technical_settings_odoo_installer"/> <field name="view_mode">form</field> <field name="target">inline</field> </record>
3) Create a view just like under Settings > Configuration > General Settings:
<record id="configure_technical_settings_odoo_installer" model="ir.ui.view"> <field name="name">Technical configuration</field> <field name="model">odoo.environment.technical.settings</field> <field name="arch" type="xml"> <form string="Configure Sales" 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> <div name="configuration"> <group> <field name="my_custom_field"/> </group> </div> </form> </field> </record>
The view is being rendered fine but I'm now wondering how to proceed. How exactly can I store the new value when a user clicks on the Apply button? There should only be one record at all times and this is used to configure the rest on. I've inherited res.config.settings, created my own model and I have a get and set function for this. Example:
class my_custom_class(models.Model): _name = 'my.custom.model' _inherit = 'res.config.settings' odoo_username = fields.Char('Ubuntu users password',help='Please fill in the password for the Ubuntu user that runs this Odoo. This password is needed to automatically install a new Odoo server through a shell script. Installing a new Odoo needs sudo rights!',required=True) def get_default_username(self, cr, uid, fields, context=None): odoo_username=self.pool.get('my.custom.model').browse(cr, uid, uid, context=context).odoo_username return {'odoo_username': odoo_username} def set_default_username(self, cr, uid, ids, context=None): config = self.browse(cr, uid, ids[0], context) new_odoo_username=config.odoo_username self.pool.get('my.custom.model').write(cr, uid, uid, {'odoo_username': new_odoo_username})
The problem here is that this will still create a new record every time and I'm not sure if this is the correct behaviour for this type of view either.
Thanks,
Yenthe
Hello yenthe,
I am also facing the same issue in odoo 12. So did you find any solution for that?