Python sales.config.settings中自定义字段的值不显示在sales settings视图中
我尝试通过使用自定义模块继承标准销售设置视图/模型,为销售配置设置添加新的配置字段 在模型中创建字段工作正常,在视图中输入的值也成功写入数据库。 但是,如果我重新加载销售配置视图,以前存储的值将返回到0.00(在表中仍然正常!)。 为此苦苦挣扎了好几天,通过研究(odoo网站和stackoverflow)找到了相关的帖子,不幸的是,这些帖子对我来说都不起作用 这是视图定义XML文件:Python sales.config.settings中自定义字段的值不显示在sales settings视图中,python,openerp,openerp-7,Python,Openerp,Openerp 7,我尝试通过使用自定义模块继承标准销售设置视图/模型,为销售配置设置添加新的配置字段 在模型中创建字段工作正常,在视图中输入的值也成功写入数据库。 但是,如果我重新加载销售配置视图,以前存储的值将返回到0.00(在表中仍然正常!)。 为此苦苦挣扎了好几天,通过研究(odoo网站和stackoverflow)找到了相关的帖子,不幸的是,这些帖子对我来说都不起作用 这是视图定义XML文件: <openerp> <data> <!-- SALE CO
<openerp>
<data>
<!-- SALE CONFIG FORM VIEW Section -->
<record model="ir.ui.view" id="view_custom_sale_config_form_inherited">
<field name="name">sale settings</field>
<field name="model">sale.config.settings</field>
<field name="type">form</field>
<field name="inherit_id" ref="sale.view_sales_config" />
<field name="arch" type="xml">
<data>
<xpath expr="//div[@name='Sale Features']/div" position="inside">
<div name="threshold_price_mgr_sig">
<label for="threshold_price_mgr_sig"/>
<field name="threshold_price_mgr_sig" class="oe_inline"/>
</div>
</xpath>
</data>
</field>
</record>
</data>
</openerp>
通过调试,我还发现函数get\u default\u threshold\u price\u mgr\u sig
从未执行过
我知道“配置设置”字段的工作原理与普通字段不同,只是不知道如何
您知道我做错了什么吗?应用程序设置的基本配置向导。它支持设置默认值、将组分配给员工用户以及安装模块。要创建这样的“设置”向导,请定义如下模型:
class my_config_wizard(osv.osv_memory):
_name = 'my.settings'
_inherit = 'res.config.settings'
_columns = {
'default_foo': fields.type(..., default_model='my.model'),
'group_bar': fields.boolean(..., group='base.group_user', implied_group='my.group'),
'module_baz': fields.boolean(...),
'other_field': fields.type(...),
}
方法execute基于命名约定提供了一些支持:
* For a field like 'default_XXX', ``execute`` sets the (global) default value of
the field 'XXX' in the model named by ``default_model`` to the field's value.
* For a boolean field like 'group_XXX', ``execute`` adds/removes 'implied_group'
to/from the implied groups of 'group', depending on the field's value.
By default 'group' is the group Employee. Groups are given by their xml id.
* For a boolean field like 'module_XXX', ``execute`` triggers the immediate
installation of the module named 'XXX' if the field has value ``True``.
* For the other fields, the method ``execute`` invokes all methods with a name
that starts with 'set_'; such methods can be defined to implement the effect
of those fields.
方法get\u default
检索反映数据库当前状态的值
字段,如“default_XXX”、“group_XXX”和“module_XXX”。它还调用所有方法
名称以“get_default_”开头;这些方法可以定义为提供
其他字段的当前值
配置页面之所以有效,是因为当您打开配置页面时,将调用所有“get_”函数。当您保存它时,所有的“set_”函数都将运行
我希望这能对您有所帮助。您应该首先添加在数据库中存储数据时设置值的方法。否则,它将返回默认值0.0。尝试使用以下方法:def set_default_threshold_price_mgr_sig(self、cr、uid、ids、context=None):#存储值的ToDo代码无需设置默认值,因为浮点值default返回0.0感谢您的回答@Rutul单击
execute
按钮时,在设置表单视图中输入的变量成功到达sale.config.settings
中的表格字段中,但表单视图在重新加载时始终显示0.00
。所以我认为这不是一个保存价值的问题,而是更多地加载和显示它?谢谢Rutul-将尝试一下并分享我的结果。
* For a field like 'default_XXX', ``execute`` sets the (global) default value of
the field 'XXX' in the model named by ``default_model`` to the field's value.
* For a boolean field like 'group_XXX', ``execute`` adds/removes 'implied_group'
to/from the implied groups of 'group', depending on the field's value.
By default 'group' is the group Employee. Groups are given by their xml id.
* For a boolean field like 'module_XXX', ``execute`` triggers the immediate
installation of the module named 'XXX' if the field has value ``True``.
* For the other fields, the method ``execute`` invokes all methods with a name
that starts with 'set_'; such methods can be defined to implement the effect
of those fields.