sales.config.settings中自定义字段的值不会显示在销售设置视图中

时间:2015-12-10 15:02:44

标签: python openerp openerp-7

我尝试使用自定义模块继承标准销售设置视图/模型,为销售配置设置添加新配置字段。

在模型中创建字段工作正常,并且在视图中输入的值也会成功写入数据库。 但是,如果我重新加载销售配置视图,之前存储的值将恢复为0.00(表中仍然可以!)。

现在苦苦挣扎几天,通过研究发现了相关的帖子(odoo site和stackoverflow),但遗憾的是这些帖子对我来说都不起作用。

这是视图定义XML文件:

<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>

这是Python代码:

from openerp.osv import osv, fields
import openerp.addons.decimal_precision as dp

# modify class sale.config.settings to insert a new field
class my_custom_sale_config_settings(osv.osv_memory):
    _name = 'sale.config.settings'
    _inherit = "sale.config.settings"

    _columns = {
        'threshold_price_mgr_sig': fields.float('Threshold Price for Managers Signature', 
            digits_compute=dp.get_precision('Product Price'), 
            default_model='sale.config.settings',
            help="""Threshold price from which the managers signature is required. 
                This is valid for quotations and order confirmations."""),
        }

    _defaults = {
        'threshold_price_mgr_sig': 0.00,
        }

    def get_default_threshold_price_mgr_sig(self, cr, uid, fields, context=None):
        last_ids = self.pool.get('sale.config.settings').search(cr, uid, [], order='id desc', limit=1)
        result_obj = self.pool.get('sale.config.settings').browse(cr,uid,last_ids[0])
        t_p_m_s = result_obj.threshold_price_mgr_sig

    return {'threshold_price_mgr_sig': t_p_m_s}

通过调试我也发现​​,函数get_default_threshold_price_mgr_sig永远不会被执行......

我知道配置设置字段与普通字段的工作方式不同 - 只是无法弄清楚如何。

你知道吗,我做错了什么?

1 个答案:

答案 0 :(得分:0)

应用程序设置的基本配置向导。它支持设置默认值,为员工用户分配组以及安装模块。制作这样的设置&#39;向导,定义像::

这样的模型
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(...),
        }

方法执行根据命名约定提供一些支持:

*   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_default检索反映当前状态的值 像&#39; default_XXX&#39;,&#39; group_XXX&#39;等字段和&#39; module_XXX&#39;。它还会调用所有方法 名称以&#39; get_default _&#39;开头;可以定义这样的方法来提供 其他字段的当前值。

  

配置页面有效,因为当您打开配置页面时,所有&#34; get _&#34;函数将被调用。当你保存所有&#34;设置_&#34;功能将会运行。

我希望这可以帮到你。