Reputation: 480
def create_file(self):
opportunity_id = self.convert_to_file()
return self.env['trademark.process'].view_file(opportunity_id)
I used convert file function to pass some values of 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 opportunity id and passed to view file 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 an error occured when i click the button .
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 issue.How to open new form when i clicking the button.
I want to pass some values to that form.
What is the mistake in my code?
Note:using odoo10
Upvotes: 4
Views: 334
Reputation: 14746
Problem in this method where you are passing res_id.
Use opportunity_id.id.
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'
}
Upvotes: 4