Odoo Help

0

how to access one class id in another class

By
Fawad Mazhar
on 7/17/17, 8:30 AM 105 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 = ??????


0
Fawad Mazhar
On 7/18/17, 1:40 AM
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')
0
Igor Kurilko
On 7/17/17, 10:56 AM

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])


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 7/17/17, 8:30 AM
Seen: 105 times
Last updated: 7/18/17, 1:40 AM