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
    • 2.14k
    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 test.py file and pass this file in your __init__.py file. Use this code given below

    from openerp.osv import osv, fields
    from openerp.tools.translate 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.prod', '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, order_id.pricelist_id.id, line.product_id.id, partner_id = order_id.partner_id.id)['value']
                line_vals.update({'product_id' : line.product_id.id})
                order_lines.append([0,False,line_vals])
                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 = "set.prod"
        _description = "Set"
        _columns = {
            'product_id' : fields.many2one('product.product', string='Products'),
            }
    set_prod()
    

     

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

    <openerp>
        <data>
            <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">
                    <form>
                        <group>
                            <field name="sequence"/>
                        </group>
                        <field name="set_item">
                            <tree string="Set Items" editable="bottom"> 
                                <field name="product_id"/> 
                            </tree>
                        </field>
                        <footer>
                            <button string="Add Product" name="add_item" type="object" class="oe_highlight"/>
                            or
                            <button string="Cancel" class="oe_link" special="cancel"/>
                            or 
                        </footer>
                    </form>
                </field>
            </record>
     <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">
                            <newline/>
                            <group>
                                <button name="%(action_product_set)d" type='action' class="oe_highlight" string='Add Item Set'/>
                            </group>
                        </xpath>
                 </field>
     </record>     
            <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>
            </record>
        </data>
    </openerp>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: