Odoo Help


How to retrieve id of in a many2one field

on 5/11/13, 10:14 AM 1,247 views

I have created a many2one field "section_id" in sale order view. This field allow me to decompose a quotation into multiples sections. So each order_line is link to a section, but when i create a section in the view i need to have the id of the current order. Here is the Python code for the "sale_order_section" :

class sale_order_section(osv.osv):

_name = 'sale.order.section'
_rec_name = 'number'
_columns = {
            'order_line': fields.one2many('sale.order.line', 'section_id', 'Order Lines', readonly=False),
            'number': fields.integer('n° section', help='permet de décomposer le devis en sous-sections'),
            'order_id': fields.many2one('sale.order', 'Order reference', ondelete='cascade', select=True, readonly=True)
_defaults = {
            'number': lambda *a: 1,
            'order_id': lambda self, cr, uid, context: context.get('order_id', False),
_sql_constraints = [
    ('number_uniq', 'unique(number, order_id)', 'Number of section must be unique per Order!'),

And the view i have inherited :

<?xml version="1.0" encoding="utf-8"?>
    <!-- modification formulaire ligne devis -->
    <record id="view_order_form_inherit_1" model="ir.ui.view">
        <field name="name">sale.order.form.inherit_1</field>
        <field name="model">sale.order</field>
        <!-- héritage de la vue existante -->
        <field name="inherit_id" ref="sale.view_order_form"/>
                    <field name="arch" type="xml">
                expr="//tree[@string='Sales Order Lines' and @editable='bottom']/field[@name='product_id']" position="before">
                <field name="is_option"/>
                <field name="section_id" widget="many2one_list" attrs="{'invisible':[('is_option','=',True)]}">
                        <field name="order_id" invisible="1"/>
                        <field name="number" 

Have you an idea how to have automatically the sale_order id when i create a sale order section ? Thanks!

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: 5/11/13, 10:14 AM
Seen: 1247 times
Last updated: 3/16/15, 8:10 AM