Skip to Content
Menu
This question has been flagged
1 Reply
4363 Views

Hi Community,

I inherited the view of model[res.config.settings]. i add the new field in this model after filling the field when i save the record at that time field would be blank. why field is not save please suggest me.

See my Code :

class ResConfigSettings(models.TransientModel):

    _inherit = 'res.config.settings'

    

    order_approval = fields.Boolean(string="Order Approval", implied_group='sale_management.group_sale_order_template')

    minimum_amount = fields.Char(string="Minimun Amount")


    @api.onchange('order_approval')

    def _onchange_order_approval(self):

        if not self.order_approval:

            self.minimum_amount = False


.XML

<?xml version="1.0" encoding="utf-8"?>

<odoo>

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

        <field name="name">sales.order.res.config.settings.view.form.inherit.sale</field>

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

        <field name="priority" eval="10"/>

        <field name="inherit_id" ref="sale.res_config_settings_view_form" />

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

        <xpath expr="//div/div/div[@id='sale_config_online_confirmation_sign']" position="before">

                <div class="col-12 col-lg-6 o_setting_box">

                    <div class="o_setting_left_pane">

                        <field name="order_approval"/>

                    </div>

                    <div class="o_setting_right_pane">

                        <label for="order_approval"/>

                        <div class="text-muted">

                            Managers must approve orders

                        </div>

                        <div class="content-group" attrs="{'invisible': [('order_approval', '=', False)]}">

                            <div class="mt16">

                                <label for="minimum_amount" class="o_light_label"/>

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

                            </div>

                            

                        </div>

                    </div>

                </div>


        </xpath>

        </field>

    </record>

</odoo>

Avatar
Discard
Best Answer

Hi,

You have to save the values to the ir.config_parameter model, if you search the functions named get_values and set_values you can see lot of use cases.


See an example from the module mail ,

class ResConfigSettings(models.TransientModel):
""" Inherit the base settings to add a counter of failed email + configure
the alias domain. """
_inherit = 'res.config.settings'

fail_counter = fields.Integer('Fail Mail', readonly=True)
alias_domain = fields.Char('Alias Domain', help="If you have setup a catch-all email domain redirected to "
"the Odoo server, enter the domain name here.", config_parameter='mail.catchall.domain')

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()

previous_date = datetime.datetime.now() - datetime.timedelta(days=30)

res.update(
fail_counter=self.env['mail.mail'].sudo().search_count([
('date', '>=', previous_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)),
('state', '=', 'exception')]),
)

return res

def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].set_param("mail.catchall.domain", self.alias_domain or '')


Also see this : How To Add Settings/Configuration For Module in Odoo


Thanks

Avatar
Discard
Author

Thanks @Niyas your ans worked for me. :)

Related Posts Replies Views Activity
1
Jan 22
3639
1
Oct 20
2036
1
Sep 15
3682
2
Mar 24
539
0
May 21
1894