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

How to retrieve id of in a many2one field

By
N
on 5/11/13, 10:14 AM 753 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"?>
<openerp>
<data>
    <!-- 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">
            <xpath
                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)]}">
                    <form>
                        <field name="order_id" invisible="1"/>
                        <field name="number" 
                        context="{'order_id':4}"
                        groups="base.group_user" 
                       />
                    </form>
                </field>
            </xpath>
        </field>
    </record>
</data>
    </openerp>

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

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