Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
827 Vues

here is my api

@http.route('/dashboard_api/generate_report', type='json', auth='public', methods=['POST'])
def generate_report(self, **kw):
report_action = request.env.ref('op_custom_ev_report_card.result_card_for_class_I_to_IX')
report_template = request.env['ir.actions.report.xml'].search([('report_id', '=', report_action.id)], limit=1)
report_pdf, _ = report_template._render_qweb_pdf([report_action.id])
if report_pdf:
return request.make_response(report_pdf,
[('Content-Type', 'application/pdf'),
('Content-Disposition', 'attachment; filename="generated_report.pdf"')])
else:
return "Failed to generate the report"

and here the error i get in postman
{    "jsonrpc": "2.0",    "id": null,    "error": {        "code": 200,        "message": "Odoo Server Error",        "data": {            "name": "builtins.KeyError",            "debug": "Traceback (most recent call last):\n  File \"F:\\odoo-14.0\\odoo\\addons\\base\\models\\ir_http.py\", line 237, in _dispatch\n    result = request.dispatch()\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 683, in dispatch\n    result = self._call_function(**self.params)\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 359, in _call_function\n    return checked_call(self.db, *args, **kwargs)\n  File \"F:\\odoo-14.0\\odoo\\service\\model.py\", line 94, in wrapper\n    return f(dbname, *args, **kwargs)\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 347, in checked_call\n    result = self.endpoint(*a, **kw)\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 912, in __call__\n    return self.method(*args, **kw)\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 531, in response_wrap\n    response = f(*args, **kw)\n  File \"f:\\odoo-14.0\\djit\\dashboard_api\\controllers\\dashboard.py\", line 15, in generate_report\n    report_template = request.env['ir.actions.report.xml'].search([('report_id', '=', report_action.id)], limit=1)\n  File \"F:\\odoo-14.0\\odoo\\api.py\", line 476, in __getitem__\n    return self.registry[model_name]._browse(self, (), ())\n  File \"F:\\odoo-14.0\\odoo\\modules\\registry.py\", line 177, in __getitem__\n    return self.models[model_name]\nException\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 639, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"F:\\odoo-14.0\\odoo\\http.py\", line 315, in _handle_exception\n    raise exception.with_traceback(None) from new_cause\nKeyError: 'ir.actions.report.xml'\n",            "message": "ir.actions.report.xml",            "arguments": [                "ir.actions.report.xml"            ],            "context": {}        }    }} 
how can i solve this
please anyone can help me

Avatar
Ignorer
Meilleure réponse

Hi,


The error indicates that Odoo can't locate the 'ir.actions.report.xml' model, resulting in a KeyError. The correct code is:


report_template = request.env['ir.actions.report'].search([('report_id', '=', report_action.id)], limit=1)


Hope it helps

Avatar
Ignorer