Odoo Help


How to keep default value on many2one field after saving OpenERP 7

Michael O. Lambert
on 2/13/14, 3:03 PM 2,362 views

I need your help please.

I have a class named document_tracking and we can add a new document_tracking from the res_partner form. I have the partner_id as a many2one field in my class document_tracking.

When I go in the partner and I create a new document_tracking, it fills the partner_id field but on the save, the partner_id is gone. Is there a way to prevent this?

    class document_tracking(osv.osv):

_name = "document.tracking"
_description = "Suivi d\'envoi"
_table = "document_tracking"

_columns = {
    'partner_id' : fields.many2one('res.partner','Nom du client'),
    'date': fields.date('Date d\'envoi'),
    'carrier_id': fields.many2one('stock.carrier','Mode de livraison'),
    'commentaire': fields.char('Commentaire'),
    'document_tracking_line_ids': fields.one2many('document.tracking.line','document_tracking_id','Document'),

_defaults = {
    'partner_id' : lambda self, cr, uid, context : context['partner_id'] if context and 'partner_id' in context else None

    <record model="ir.ui.view" id="view_partner_form_document_tracking">
        <field name="name">res.partner.form_document_tracking</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form" />
        <field name="arch" type="xml">
            <notebook position="inside" >
                <page string="Suivi d'envoi" >
                    <separator string="Suivi d'envoi"/>
                    <field name="document_tracking_ids" domain="[('partner_id','=',active_id)]"  context="{'partner_id':active_id}">
                        <form string="Suivi d'envoi" version="7.0">
                        <h1> <label string="Suivi d'envoi"/></h1>
                        <group col="4">
                            <group colspan="2">
                                <field name="partner_id" required="True"/>
                                <field name="carrier_id"/>
                            <group colspan="2">
                                <field name="date" required="True"/>
                        <notebook position="inside">
                            <page string="Documents">
                                <separator string="Documents"/>
                                <field name="document_tracking_line_ids"/>
                            <page string="Commentaires">
                                <separator string="Commentaires"/>
                                <field name="commentaire" string="Commentaires"/>

Thank you!

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 2/13/14, 3:03 PM
Seen: 2362 times
Last updated: 3/16/15, 8:10 AM