コンテンツへスキップ
メニュー
この質問にフラグが付けられました
5 返信
18907 ビュー

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)


アバター
破棄
最善の回答

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

アバター
破棄

can you pls covert this code for v12cc

最善の回答

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

アバター
破棄
著作者

base.config.settings. Notice the 's'

最善の回答

@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

アバター
破棄
関連投稿 返信 ビュー 活動
0
7月 21
2578
4
2月 17
13945
1
2月 25
775
2
12月 24
1280
2
10月 23
1602