Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[8.0] Default Values for Many2One Fields

By
John
on 12/27/14, 2:24 AM 662 views

I am trying to set default values for a many2one field without using the 'Set Default' technical setting.  I created the following data file:

     <record model="ir.values" id="partner_default_cust_terms_value">
        <field name="name">property_payment_term_default</field>
        <field name="key">default</field>
        <field name="key2"></field>
        <field name="model">res.partner</field>
        <field name="user_id"></field>
        <field name="company_id">1</field>
        <field name="value" eval="str('account.payment.terms,')+str(ref('account.account_payment_term_net'))"/>
     </record

Is there a way to create the value field correctly by just using data files?

Hi John, can you give it in .py file?

Baiju
on 12/27/14, 10:55 PM

@Baiju KS, I'm not sure how I would do that? What method would I override?

John
on 12/29/14, 8:29 AM
0
sameer alhwety
On 12/31/14, 4:46 AM

from .py :

def _set_default(self, cr, uid, context=None):
        if context is None: context = {}
        res = {}
        for line in self.browse(cr ,uid ,ids):
            res[line.id] = YOUR_DEFAULT_VALUE
        return res

 

from .xml :

<record model="ir.values" id="partner_default_cust_terms_value">
        <field name="name">property_payment_term_default</field>
        <field name="key">default</field>
        <field name="key2"></field>
        <field name="model">res.partner</field>
        <field name="user_id"></field>
        <field name="company_id">1</field>
        <field eval="'account.payment.terms,'+str('account.account_payment_term_net')" name="value" />
     </record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/27/14, 2:24 AM
Seen: 662 times
Last updated: 3/16/15, 8:10 AM