Skip to Content
Menu
This question has been flagged
2 Replies
4300 Views


I need to send data in a one2many field of a form to a a one2many field of a wizard [opens on a button click].. the wizard contains a one2many field of same format.. How to acheive this??


Parent CLass

class wrhouse(models.Model):

 wproductlist = fields.One2many(comodel_name="productlist1", inverse_name="ppp", string="Product List")

@api.multi

 def Submittopm(self):

result = {
    'view_type': 'form',
    'view_mode': 'form',
    'res_model': 'submitquantwiz',
    'name': 'Enter Quantity of Stock Needed',
    'type': 'ir.actions.act_window',
    'target': 'new',

}
return result  
class productlist1(models.Model)
 _name = "productlist1"
ppp = fields.Char(String="hai")
_rec_name = "productname"
productname = fields.Char(string="Product Name")
reqquantity = fields.Char(string="Required Quantity")
quantav = fields.Char(string="Product Available", onchange="pro_quantity")
maxdate = fields.Date(string="Deadline Date")

Wizard Class


  class wrhousesub(models.TransientModel):
_name = 'submitquantwiz'
No = fields.One2many(comodel_name="id",inverse_name="quant",string="Products")

class wr(models.Model):
_name = "id"
# p = fields.Char(string="ff")
products = fields.Many2one(comodel_name='productlist1',string="Product")
quant = fields.Char(string="Quntities")




Avatar
Discard

@jignesh mehta :

i cant chnage the productname to many2one because it is written from another class using create function



Ok. Then search product before append in line.

Best Answer

Hello bazithtdpa,

For that, You have to call default_get method in wizard. So When wizard form call, default_get is called.

class productlist1(models.Model)  _name = "productlist1"
ppp = fields.Char(String="hai")
_rec_name = "productname"
productname = fields.Char(string="Product Name") # You need to change this field to Many2one because in wizard you add Many2one field for Products.


Here is default_get method for wizard:
class wrhousesub(models.TransientModel):    _name = 'submitquantwiz'    @api.model    def default_get(self, fields):        rec = super(wrhousesub, self).default_get(fields)        product_line = []        active_obj = self.env['active.model'].browse(self._context.get('active_ids'))        for line in active_obj:            product_line.append((0, 0, {                'products': line.productname.id,                'quant': line.reqquantity,            }))        rec['No'] = product_line        return rec​

Hope it will works for you.
Thanks,


Avatar
Discard