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

I need to fetch the fields and its values from Settings > Accounting > Taxes, particularly the Avatax configs. 


I tried self.env['res.config.settings'] but it always returns False

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

this is resolved apparently i'm looking at the wrong model

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

you can use the ir.config_parameter model. Here's an example of how you can retrieve the Avatax configuration values:

avatax_account_number = self.env['ir.config_parameter'].sudo().get_param('account.avatax_account_number') avatax_license_key = self.env['ir.config_parameter'].sudo().get_param('account.avatax_license_key'

# Fetch other Avatax configuration fields as needed

# Process the retrieved values as required

In the above code, account.avatax_account_number and account.avatax_license_key are the parameter keys for the Avatax configuration fields.

Make sure to import the ir.config_parameter model in your Python file:

from odoo import models, fields, api

Note: The specific parameter keys may vary depending on the module or customization you have installed for Avatax integration in Odoo. You can refer to the Avatax module's code or documentation to find the exact parameter keys for the configuration fields you need.

If self.env['res.config.settings'] is returning False, it means that there is no active configuration settings record available. In that case, you can directly fetch the configuration values from the ir.config_parameter model as shown above.

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

i tried this one: avatax_account_number = self.env['ir.config_parameter'].sudo().get_param('account.avalara_environment')

but it still returns false

Tác giả

also, self.env['ir.config_parameter'].sudo() doesnt return anything

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

Hi,
Please check this eg:

please define field in res.config.settings like below.

    Fieldname = fields.Boolean(config_parameter='module_name.field_name')

   mobile_phone_no = fields.Char(srting='Mobile Phone No:',
                                  config_parameter="integration_whatsapp_chat_live.mobile_phone_no",
                                  default='', help='User Can add the mobile number')
    then fetch field value.

    Fieldname = self.env['ir.config_parameter'].sudo().get_param('module_name.field_name')


Hope it helps

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

does this mean i have to create a new model that inherits the config_parameter?

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

no, you don't need to create new model you can directly access like self.env['ir.config_parameter'].sudo().get_param('account.avatax_license_key')

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 5 24
16743
1
thg 4 24
1471
3
thg 8 23
3776
1
thg 5 23
3334
2
thg 1 24
1330