This question has been flagged

Hello All,

I want to return selected check-box values from One2many field to Many2many in sales order line. Now, my values are already return but i want that select values return in sales order line. In below code commented part in the function where i try to implement check box condition. And 'wizards'(many2many) is the field where i try to return values for 'wizard'(many2many in One2many) with selected 'gold2' (Boolean type) field. Code works well. But, not work with check-box condition only. So, anyone guide me for programming commented part?

My Python Code Here:

class SalePackWizard(models.TransientModel):
    _name = "sale.pack.wizard"
    _description = "Sale Pack Wizard"

    product_id = fields.Many2one('product.product', string="Product Pack", required=True, domain="[('is_pack','=',True)]")
    pack_ids = fields.Many2many('product.pack', string='Pack Products')
    qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0)
    wizard = fields.One2many('product.gold','gold1')

     @api.multi
    def action_salepack_add(self):
        rec = self._context.get('active_ids', [])
        print "REC", rec, self.product_id.categ_id #product_uom
        print "B:", self.services
        #print "C:", self.srv_prds.service
        print "D:", [g.id for g in self.srv_prds]
        print "E:", [p.id for p in self.services]
        print "F:", [q.id for q in self.wizard]
        print "g:", self.wizard.gold2
        if rec:
            line_values = {'product_id': self.product_id.id,
                           #'design_id':self.design_id.id,
                           #'product_pack': self.product_id.name,
                           'wizards': [(6, 0, [q.id for q in self.wizard])],
                           'pack_id': [(6, 0, [v.id for v in self.product_id.product_pack])],
                           'products_id': [(6, 0, [g.id for g in self.services])] ,
                           'srv_prd': [(6, 0, [g.id for g in self.srv_prds])],
                           'category_id':self.product_id.categ_id.id,
                           'order_id':rec[0],
                           'product_uom_qty':self.qty,
                           }
            """if self.wizard.gold2:
                line = { 'wizards': [(6, 0, [q.id for q in self.wizard])],
                }
                sale_order_line = self.env['sale.order.line'].create(line)
            else:
                line = {}"""
            sale_order_line = self.env['sale.order.line'].create(line_values)
            print "D:", sale_order_line

class ProductDesign(models.Model):
    _description = 'Product Pack'
    _name = "product.gold"
    _rec_name = "gold3"

    gold1= fields.Many2one('product.val', string='Templates', required="True", ondelete='cascade', index=True, copy=True)
    gold2 = fields.Boolean('#')
    gold3 = fields.Many2one('product.product', string='Product', required="True")
    gold4 = fields.Many2one('gold.service')
    gold5 = fields.Integer('Quantity', default=1)

XML Code:

<record id="view_sale_pack_wizard" model="ir.ui.view">
            <field name="name">Sale pack wizard</field>
            <field name="model">sale.pack.wizard</field>
            <field name="arch" type="xml">
                <form string="Sales Pack">
                    <group>
                        <group>
                            <field name="product_id"/>
                            <!--<field name="pack_ids"/>-->
                            <field name="wizard" style="width:600px">
                                <tree editable="bottom">
                                    <field name="gold2" style="width:50px"/>
                                    <field name="gold3"/>
                                    <field name="gold4"/>
                                    <field name="gold5"/>
                                </tree>
                            </field>
                        </group>
                    </group>
                    <footer>
                        <button name="action_salepack_add" string="Ok" type="object"
                                class="btn-primary"/>
                        <button string="Cancel" class="btn-default" special="cancel"/>
                    </footer>
                </form>
            </field>
        </record>

        <record id="action_view_sale_pack_wizard" model="ir.actions.act_window">
            <field name="name">Sale Pack</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">sale.pack.wizard</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_sale_pack_wizard"/>
            <field name="target">new</field>
        </record>

Avatar
Discard