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.

1

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

By
Michael O. Lambert
on 2/13/14, 3:03 PM 1,863 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">
                        <sheet>
                        <h1> <label string="Suivi d'envoi"/></h1>
                        <group col="4">
                            <group colspan="2">
                                <field name="partner_id" required="True"/>
                                <field name="carrier_id"/>
                            </group>
                            <group colspan="2">
                                <field name="date" required="True"/>
                            </group>
                        </group>
                        <notebook position="inside">
                            <page string="Documents">
                                <separator string="Documents"/>
                                <field name="document_tracking_line_ids"/>
                            </page>
                            <page string="Commentaires">
                                <separator string="Commentaires"/>
                                <field name="commentaire" string="Commentaires"/>
                            </page>
                        </notebook>
                        </sheet>
                        </form>
                    </field> 
                </page>
            </notebook>
        </field>
    </record>

Thank you!

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

0 follower(s)

Stats

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