Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Select product and add product in your sale order line on button click in Odoo-8

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.15k
    Comment on it

    In Odoo first, we create custom module and also create function and pass this function in button. And when we open the form we will select the product and this product will show in sale order line.

    Follow these step given below

    Step1- First we create test module and then create file like as file and pass this file in your file. Use this code given below

    from openerp.osv import osv, fields
    from import _
    from openerp import workflow
    import openerp.addons.decimal_precision as dp
    class prod_set(osv.TransientModel):
        _name = "prod.set"
        _description = "Set Selection"
        _columns = {
             'set_item': fields.one2many('', 'set_one', 'Set Item'),
             'sequence': fields.char('Sequence')
        def add_item(self, cr, uid, ids, context=None):
            active_id = context.get('active_id', [])
            order_obj = self.pool.get('sale.order')
            order_line = self.pool.get('sale.order.line')
            set = self.browse(cr, uid, ids, context=context)
            order_id = order_obj.browse(cr, uid, active_id, context=context)
            set_line = set.set_line
            order_lines = []
            for line in set_line:
                line_vals = order_line.product_id_change(cr, uid, 0,,, partner_id =['value']
                line_vals.update({'product_id' :})
                print line_vals , 'line_vlas'
            if order_lines:
                order_obj.write(cr,uid,active_id, {'order_line' : order_lines})
            return True
    class set_prod(osv.TransientModel):
        _name = ""
        _description = "Set"
        _columns = {
            'product_id' : fields.many2one('product.product', string='Products'),


    Step2- Then we create test.xml file in your own module and pass this file in your file. And use this code to open the form to click of button.

            <record id="view_product_set" model="ir.ui.view">
                <field name="name">view_product_set</field>
                <field name="model">product.set</field>
                <field name="arch" type="xml">
                            <field name="sequence"/>
                        <field name="set_item">
                            <tree string="Set Items" editable="bottom"> 
                                <field name="product_id"/> 
                            <button string="Add Product" name="add_item" type="object" class="oe_highlight"/>
                            <button string="Cancel" class="oe_link" special="cancel"/>
     <record model="ir.ui.view" id="purchase_order_inherit">
                <field name="name">purchase.order.inherit</field>
                <field name="model">purchase.order</field>
                <field name="inherit_id" ref="purchase.purchase_order_form"/>
                <field name="arch" type="xml">
     <xpath expr="//field[@name='order_line']" position="before">
                                <button name="%(action_product_set)d" type='action' class="oe_highlight" string='Add Item Set'/>
            <record id="action_product_set" model="ir.actions.act_window">
                <field name="name">Set</field>
                <field name="type">ir.actions.act_window</field>
                <field name="res_model">product.set</field>
                <field name="view_type">form</field>
                <field name="view_mode">form</field>
                <field name="target">new</field>

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: