我正在使用Odoo 10-e。我来自.net,我想要做的是我需要在Odoo中创建自定义设置配置文件,就像我们在asp.net中有AppSettings
文件一样,我们在项目中设置一些静态键值来使用它们。如何创建这种文件以及如何在python代码或xml文件中访问该文件?
答案 0 :(得分:0)
class farmacia_pedido_config_settings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'farmacia.config.settings'
lista_precios_defecto = fields.Many2one(
'product.pricelist',
string='Lista de precios por defecto')
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_farmacia_configuration" model="ir.ui.view">
<field name="name">farmacia config settings</field>
<field name="model">farmacia.config.settings</field>
<field name="arch" type="xml">
<form string="Farmacia" class="oe_form_configuration">
<header>
<button string="Aplicar" type="object" name="execute" class="oe_highlight"/>
<button string="Cancelar" type="object" name="cancel" class="oe_link"/>
</header>
<field name="lista_precios_defecto" class="oe_inline"/>
</group>
</form>
</field>
</record>
<record id="action_farmacia_configuration" model="ir.actions.act_window">
<field name="name">Farmacia</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">farmacia.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem id="menu_farmacia_config" name="Farmacia" parent="base.menu_config"
sequence="3" action="action_farmacia_configuration"/>
</data>
</openerp>
config = ConfigParser()
your_file = os.getenv("HOME")+os.path.sep+"your_file.conf"
if os.path.isfile(your_file):
config.read(your_file)
else:
raise models.except_orm(
'Error',
"File not found " + os.getcwd())