This question has been flagged

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!

Avatar
Discard