Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
18896 Widoki

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)


Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć

can you pls covert this code for v12cc

Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

base.config.settings. Notice the 's'

Najlepsza odpowiedź

@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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lip 21
2575
4
lut 17
13936
1
lut 25
772
2
gru 24
1276
2
paź 23
1598