Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
19046 Lượt xem

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)


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

can you pls covert this code for v12cc

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

base.config.settings. Notice the 's'

Câu trả lời hay nhất

@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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 21
2625
4
thg 2 17
14083
1
thg 2 25
939
2
thg 12 24
1418
2
thg 10 23
1669