跳至內容
選單
此問題已被標幟
5 回覆
18901 瀏覽次數

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
2576
4
2月 17
13939
1
2月 25
775
2
12月 24
1277
2
10月 23
1600