diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d276bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Python +*.py[cod] +__pycache__/ +*.so + +# Odoo +*.po~ +*.pot~ + +# Editor / System +.DS_Store +.vscode/ +*.swp +*.swo +*~ diff --git a/__manifest__.py b/__manifest__.py index 5167361..23235d4 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'Web Direct Print', - 'version': '18.0.1.0.0', + 'version': '19.0.1.0.0', 'category': 'Extra Tools', 'summary': 'Enable direct printing from web browser to local printers', 'description': """ @@ -36,6 +36,7 @@ 'stock', ], 'data': [ + 'security/ir.model.access.csv', 'data/ir_actions_server.xml', 'views/direct_print_templates.xml', 'views/sale_order_views.xml', diff --git a/controllers/main.py b/controllers/main.py index 01b6140..f8dbd7b 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -1,90 +1,90 @@ -from odoo import http -from odoo.http import request -import json -import base64 - - -class DirectPrintController(http.Controller): - - @http.route('/web/direct_print', type='json', auth='user') - def direct_print(self, report_name, docids, data=None): - """ - Controller method to handle direct print requests - :param report_name: Name of the report to print - :param docids: IDs of documents to print - :param data: Additional data for the report - :return: JSON response with print data - """ - try: - import logging - _logger = logging.getLogger(__name__) - _logger.info(f"Controller received: report_name={report_name} (type: {type(report_name)}), docids={docids} (type: {type(docids)}), data={data}") - - # Handle parameters that might come as different types - if isinstance(report_name, list): - report_name = report_name[0] if report_name else '' - - if isinstance(docids, str): - try: - # Try to convert string to list of integers - if ',' in docids: - docids = [int(x.strip()) for x in docids.split(',') if x.strip()] - else: - docids = [int(docids)] - except ValueError: - docids = [] - elif not isinstance(docids, list): - docids = [docids] if docids else [] - - _logger.info(f"Processed parameters: report_name={report_name}, docids={docids}") - - # Call the direct print model method with proper context - result = request.env['web.direct.print'].sudo().direct_print_action( - report_name, docids, data, context=request.context - ) - return result - except Exception as e: - import logging - _logger = logging.getLogger(__name__) - _logger.error(f"Controller error: {str(e)}") - _logger.exception("Full traceback:") - return { - 'success': False, - 'error': str(e) - } - - @http.route('/web/direct_print/get_reports', type='json', auth='user') - def get_available_reports(self): - """ - Controller method to get available reports for direct printing - :return: JSON response with available reports - """ - try: - result = request.env['web.direct.print'].sudo().get_available_reports() - return result - except Exception as e: - return { - 'success': False, - 'error': str(e) - } - - @http.route('/web/direct_print/test', type='http', auth='user', website=True) - def test_direct_print(self, **kwargs): - """ - Test endpoint for direct printing functionality - """ - # This could be used for testing purposes - html_content = """ - - -
-This page demonstrates the direct print functionality.
- - - - """ +from odoo import http +from odoo.http import request +import json +import base64 + + +class DirectPrintController(http.Controller): + + @http.route('/web/direct_print', type='jsonrpc', auth='user') + def direct_print(self, report_name, docids, data=None): + """ + Controller method to handle direct print requests + :param report_name: Name of the report to print + :param docids: IDs of documents to print + :param data: Additional data for the report + :return: JSON response with print data + """ + try: + import logging + _logger = logging.getLogger(__name__) + _logger.info(f"Controller received: report_name={report_name} (type: {type(report_name)}), docids={docids} (type: {type(docids)}), data={data}") + + # Handle parameters that might come as different types + if isinstance(report_name, list): + report_name = report_name[0] if report_name else '' + + if isinstance(docids, str): + try: + # Try to convert string to list of integers + if ',' in docids: + docids = [int(x.strip()) for x in docids.split(',') if x.strip()] + else: + docids = [int(docids)] + except ValueError: + docids = [] + elif not isinstance(docids, list): + docids = [docids] if docids else [] + + _logger.info(f"Processed parameters: report_name={report_name}, docids={docids}") + + # Call the direct print model method with proper context + result = request.env['web.direct.print'].sudo().direct_print_action( + report_name, docids, data, context=request.context + ) + return result + except Exception as e: + import logging + _logger = logging.getLogger(__name__) + _logger.error(f"Controller error: {str(e)}") + _logger.exception("Full traceback:") + return { + 'success': False, + 'error': str(e) + } + + @http.route('/web/direct_print/get_reports', type='jsonrpc', auth='user') + def get_available_reports(self): + """ + Controller method to get available reports for direct printing + :return: JSON response with available reports + """ + try: + result = request.env['web.direct.print'].sudo().get_available_reports() + return result + except Exception as e: + return { + 'success': False, + 'error': str(e) + } + + @http.route('/web/direct_print/test', type='http', auth='user', website=True) + def test_direct_print(self, **kwargs): + """ + Test endpoint for direct printing functionality + """ + # This could be used for testing purposes + html_content = """ + + + +This page demonstrates the direct print functionality.
+ + + + """ return html_content \ No newline at end of file diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv new file mode 100644 index 0000000..deb24f5 --- /dev/null +++ b/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_web_direct_print,web.direct.print,model_web_direct_print,base.group_user,1,1,1,1 diff --git a/views/stock_picking_views.xml b/views/stock_picking_views.xml index b71c302..8ee3e52 100644 --- a/views/stock_picking_views.xml +++ b/views/stock_picking_views.xml @@ -140,8 +140,8 @@ if records: