Search code examples
odoo

display one2many values of a model in a wizard


I have a class salesin which has a one2many field emidetails . Here i defined abutton that directs to a wizard saleswizard . What i need to acheive is when i click the button , the wizard that opens should contain the emidetails one2many field of salesin class .. How to

'''

     class Salesin(models.Model):

   _inherit = 'sale.order'

    amount = fields.Integer(string="Total Amount")
    product = fields.Char(string="Product")
    paymenttype = fields.Selection([('Full Payment', 'Full Payment'), ('EMI', 'EMI'), ], 
    string=" Payment Type : ", default='Full Payment')
    emidetails = fields.One2many(comodel_name="emidetails",inverse_name="saleorder",string="Emi Details",onchange="restrict")

   @api.multi
   def cnfirm(self):
   result = {
    'view_type': 'form',
    'view_mode': 'form',
    'res_model': 'confirmbox',
    'name': 'Confirm the Quantities Currently Have',
    'type': 'ir.actions.act_window',
    'target': 'new',

      }
    return result


 class emidetails(models.Model):

_name = "emidetails"
saleorder = fields.Many2one( comodel_name="sale.order' ,string="SO")
 installment = fields.Selection([('Level 1', '1st Installment'), ('Level 2', '2nd 
 Installment'), ('Level 3', '3rd Installment'), ],
                           string=" Installment : ",)
 amount = fields.Char(string="Amount:",onchange="calculate_med")
  date = fields.Date(string="Due Date")
 cust = fields.Many2one(comodel_name="sale.order")
  status = fields.Selection([('Pending', 'Pending'), ('Paid', 'Paid'), ],
                           string=" Status : ",)


 class saleswizard(models.TransientMOdel) :
  _name = saleswiz
 emidetails = fields.One2many 
  (comodel_name="emidetails",inverse_name="saleorder",string="Emi 
  Details",onchange="restrict")

Solution

  • Use a Many2many field:

    emidetails = fields.Many2many("emidetails", string="EmiDetails")
    

    And passe default values in context:

    @api.multi
    def cnfirm(self):
        self.ensure_one()
        emidetails = [(4, emit.id, 0) for emit in self.emidetails]
        result = {
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'saleswiz',
            'name': 'Confirm the Quantities Currently Have',
            'type': 'ir.actions.act_window',
            'target': 'new',
            'context': {'default_emidetails': emidetails}
    
        }
        return result