How to solve the error when clicking a button to open a new form in odoo10?

def create_file(self):

    opportunity_id = self.convert_to_file()
    return self.env['trademark.process'].view_file(opportunity_id)

      

I used convert file to pass some values ​​of the current model to trademark.process

def convert_to_file(self, partner_id=False):

    tm_process_obj = self.env['trademark.process']
    tm_search_record = self.env['trademark.search'].browse(self.id)
    for rec in tm_search_record:
        opportunity_id = tm_process_obj.create({
                        'search_name_char': rec.search_name or False,
                        'classification_no_id':rec.classification_no_id.id or False,
                        'partner_id': rec.partner_id.id or False,
                        'user_id': rec.user_id.id or False,
                        'search_date': rec.search_date or False,
                        'search_seq_no': rec.seq_no or False,
                    })
        vals = {
            'file_no': opportunity_id.seq_no,
        }
        self.write(vals)
    return opportunity_id

      

Then finally, I return the id capability and pass it to the file viewer function .

def view_file(self, opportunity_id):
    view_id=self.env.ref('trademark_services.trademark_process_form_view').id
    return {
        'name': _('File Details'),
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'trademark.process',
        'view_id': view_id,
        'res_id': opportunity_id,
        'target':'current'
    }

      

But when I click the button, there was an error.

Traceback (most recent call last):
File "/home/ubuntu/workspace/amzsys_erp/odoo/http.py", line 638, in 
 _handle_exception
 return super(JsonRequest, self)._handle_exception(exception)
File "/home/ubuntu/workspace/amzsys_erp/odoo/http.py", line 689, in 
   dispatch
   return self._json_response(result)
 File "/home/ubuntu/workspace/amzsys_erp/odoo/http.py", line 627, in 
_json_response
   body = json.dumps(response)
 File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
  return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
  return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
  raise TypeError(repr(o) + " is not JSON serializable")
TypeError: trademark.process(131,) is not JSON serializable

      

How to solve this problem. How do I open a new form when I click a button.

I want to pass some values ​​to this form.

What's the mistake in my code?

Note: using odoo10

+3


source to share


1 answer


The problem is in this method where you are passing res_id.

Use options_id.id function.



def view_file(self, opportunity_id):
    view_id=self.env.ref('trademark_services.trademark_process_form_view').id
    return {
        'name': _('File Details'),
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'trademark.process',
        'view_id': view_id,
        'res_id': opportunity_id.id,
        'target':'current'
    }

      

+4


source







All Articles