Skip to Content
Menu
This question has been flagged
5 Replies
17801 Views

I have created a custom module that adds a field show_separate_invoice to the ir.config.settings. Now how to check the condition if show_separate_invoice is checked or not? And if checked, how to  get the custom field journal_to_invoice value from another module(sale.order)

class CustomSettings(models.TransientModel): 
 _inherit = 'sale.config.settings'
 show_separate_invoice = fields.Boolean('separate_invoice')
 journal_to_invoice = fields.Many2one('account.journal', string='journal')
 
@api.model
 def get_default_show_separate_invoice(self, fields):
 irconfigparam = self.env['ir.config_parameter']
 return{
'show_separate_invoice': irconfigparam.get_param('show_separate_invoice', False)
 }
 
@api.multi
 def set_default_show_separate_invoice(self):
 self.ensure_one()
 irconfigparam = self.env['ir.config_parameter']
 irconfigparam.set_param('show_separate_invoice', self.show_separate_invoice)
 
@api.multi
 def set_default_journal_to_invoice(self):
 return self.env['ir.values'].sudo().set_default('sale.config.settings', 'journal_to_invoice', self.journal_to_invoice.id)


Avatar
Discard
Best Answer

Hi,

If you are trying to save something in the settings you can do it like this.

_inherit="base.config.settings"

@api.multi
def set_secret_key_validation(self):
    return self.env['ir.values'].sudo().set_default(
            'base.config.settings', 'abcde', self.field_name)

Then to access the saved value in the settings,


ir_values = request.env['ir.values']
field_value = ir_values.get_default('base.config.settings', 'abcde')

Thanks

Avatar
Discard

can you pls covert this code for v12cc

Best Answer

Hi Niyas, why my odoo dont have "base.config.setting" ?? my version is 11 

Avatar
Discard
Author

base.config.settings. Notice the 's'

Best Answer

@LaoThai, 

Odoo version 11 onwards have res.config.settings instead of base.config.settings.

Its a Transient Model, meaning data wont be persisted and will be cleaned by a CRON Schedular. The values get saved in ir.config_parameter model, which is a persisted model and saves the data based on key,value pairs

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 21
2113
4
Feb 17
12790
1
Nov 24
171
2
Oct 23
809
1
Jun 23
1194