2
votes

I am trying to modify the default value of the Sale Pricelist of a partner (field property_product_pricelist, tab Sales & Purchases, model res.partner). It seems that this default value was introduced via XML (since that field is of type property), adding a record to the ir.property model:

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

So I guess (I did not try it) that if you modify this XML record, you will change the default value, for example:

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

The problem is that I want to introduce different default values depending on other field (user_id). I mean, if user_id is the res.users with ID 1, I want the Public Pricelist as the default pricelist, otherwise, I want the pricelist created by me (my_default_pricelist) as the default one.

Can anyone help me, please?

1

1 Answers

0
votes

If you want conditional default values you have to move to Python.

Try extending the model and redefining the field but this time use the fnct=compute_method argument. compute_method is the method that will run each time to set the default value of the field.

The property class that the property_product_pricelist field is using, is an extension of the function class. Go to openerp/osv/fields.py and find the definition of the function class and take a look at the parameters.