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

how i get  class site_survey(models.Model): id in another class class site_survey_cancellation(models.TransientModel):

code is below

class site_survey(models.Model):
_name = 'site.survey'
name = fields.Char(readonly=True)
@api.multi
def action_cancel(self):
# self.state = 'cancel'
self._context
return {
'name': ('Cancel Reason'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'site.survey.cancellation',
'view_id': False,
'type': 'ir.actions.act_window',
'target': 'new',
'res_id':self._context
}

class site_survey_cancellation(models.TransientModel):
_name = 'site.survey.cancellation'
cancel_note = fields.Char("Cancel Reason")
site_survey_id = ??????


Avatar
Discard
Author Best Answer
I use your given code but it gives error below

prefetch[cls._name].update(ids)
TypeError: unhashable type: 'dict'



class site_survey(models.Model):
    _name = 'site.survey'
    name = fields.Char(readonly=True)
    cancel_reason = fields.Char("cancel reason")

    @api.multi
    def action_cancel(self):
       # self.state = 'cancel'
        self._context
        return {
            'name': ('Cancel Reason'),
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'site.survey.cancellation',
            'view_id': False,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'res_id': self._context
        }

class site_survey_cancellation(models.TransientModel):
    _name = 'site.survey.cancellation'
    cancel_note = fields.Char("Cancel Reason")
    site_survey_id = fields.Many2one('site.survey', required=True,compute='cancel_it', store=True)

    @api.multi
    def cancel_it(self):
        self.site_survey_id = self._context.get('id')
Avatar
Discard
Best Answer

Hi,

try this:

    to find by id:

        self.env['site_survey'].browse(your_id_here)

    to find by some condition:

        self.env['site_survey'].search([your_domain_here])


Avatar
Discard