【问题标题】:How to modify the default value of a property field in Odoo 8?如何修改 Odoo 8 中属性字段的默认值?
【发布时间】:2016-12-24 01:29:12
【问题描述】:

我正在尝试修改合作伙伴的销售价目表的默认值(字段property_product_pricelist,标签销售和采购,型号res.partner)。似乎这个默认值是通过 XML 引入的(因为该字段的类型是 property),在 ir.property 模型中添加了一条记录:

<record id="list0" model="product.pricelist">
    <field name="name">Public Pricelist</field>
    <field name="type">sale</field>
</record>
<record id="ver0" model="product.pricelist.version">
    <field name="pricelist_id" ref="list0"/>
    <field name="name">Default Public Pricelist Version</field>
</record>
<record id="item0" model="product.pricelist.item">
    <field name="price_version_id" ref="ver0"/>
    <field name="base" ref="list_price"/>
    <field name="sequence">1000</field>
    <field name="name">Default Public Pricelist Line</field>
</record>

<!--
Property
-->
<record forcecreate="True" id="property_product_pricelist" model="ir.property">
    <field name="name">property_product_pricelist</field>
    <field name="fields_id" search="[('model','=','res.partner'),('name','=','property_product_pricelist')]"/>
    <field eval="'product.pricelist,'+str(ref('list0'))" name="value"/>
</record>

所以我猜(我没有尝试过)如果你修改这个XML记录,你会改变默认值,例如:

<record forcecreate="True" id="product.property_product_pricelist" model="ir.property">
    <field name="name">property_product_pricelist</field>
    <field name="fields_id" search="[('model','=','res.partner'),('name','=','property_product_pricelist')]"/>
    <field eval="'product.pricelist,'+str(ref('my_default_pricelist'))" name="value"/>
</record>

问题是我想根据其他字段(user_id)引入不同的默认值。我的意思是,如果 user_id 是 ID 1res.users,我希望 Public Pricelist 作为默认价格表,否则,我想要我创建的价格表( my_default_pricelist) 作为默认值。

有人可以帮帮我吗?

【问题讨论】:

    标签: xml python-2.7 openerp odoo-8 default-value


    【解决方案1】:

    如果你想要有条件的默认值,你必须迁移到 Python。

    尝试扩展模型并重新定义字段,但这次使用fnct=compute_method 参数。 compute_method 是每次都会运行的设置字段默认值的方法。

    property_product_pricelist 字段使用的property 类是function 类的扩展。去openerp/osv/fields.py找到function类的定义,看看参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多