feat: Migrate module to Odoo 19, updating stock package references, controller route types, and adding access rights and a gitignore.
This commit is contained in:
parent
dd4bcba2c7
commit
4138df365c
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Python
|
||||||
|
*.py[cod]
|
||||||
|
__pycache__/
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Odoo
|
||||||
|
*.po~
|
||||||
|
*.pot~
|
||||||
|
|
||||||
|
# Editor / System
|
||||||
|
.DS_Store
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
'name': 'Web Direct Print',
|
'name': 'Web Direct Print',
|
||||||
'version': '18.0.1.0.0',
|
'version': '19.0.1.0.0',
|
||||||
'category': 'Extra Tools',
|
'category': 'Extra Tools',
|
||||||
'summary': 'Enable direct printing from web browser to local printers',
|
'summary': 'Enable direct printing from web browser to local printers',
|
||||||
'description': """
|
'description': """
|
||||||
@ -36,6 +36,7 @@
|
|||||||
'stock',
|
'stock',
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
|
'security/ir.model.access.csv',
|
||||||
'data/ir_actions_server.xml',
|
'data/ir_actions_server.xml',
|
||||||
'views/direct_print_templates.xml',
|
'views/direct_print_templates.xml',
|
||||||
'views/sale_order_views.xml',
|
'views/sale_order_views.xml',
|
||||||
|
|||||||
@ -1,90 +1,90 @@
|
|||||||
from odoo import http
|
from odoo import http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
class DirectPrintController(http.Controller):
|
class DirectPrintController(http.Controller):
|
||||||
|
|
||||||
@http.route('/web/direct_print', type='json', auth='user')
|
@http.route('/web/direct_print', type='jsonrpc', auth='user')
|
||||||
def direct_print(self, report_name, docids, data=None):
|
def direct_print(self, report_name, docids, data=None):
|
||||||
"""
|
"""
|
||||||
Controller method to handle direct print requests
|
Controller method to handle direct print requests
|
||||||
:param report_name: Name of the report to print
|
:param report_name: Name of the report to print
|
||||||
:param docids: IDs of documents to print
|
:param docids: IDs of documents to print
|
||||||
:param data: Additional data for the report
|
:param data: Additional data for the report
|
||||||
:return: JSON response with print data
|
:return: JSON response with print data
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import logging
|
import logging
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
_logger.info(f"Controller received: report_name={report_name} (type: {type(report_name)}), docids={docids} (type: {type(docids)}), data={data}")
|
_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
|
# Handle parameters that might come as different types
|
||||||
if isinstance(report_name, list):
|
if isinstance(report_name, list):
|
||||||
report_name = report_name[0] if report_name else ''
|
report_name = report_name[0] if report_name else ''
|
||||||
|
|
||||||
if isinstance(docids, str):
|
if isinstance(docids, str):
|
||||||
try:
|
try:
|
||||||
# Try to convert string to list of integers
|
# Try to convert string to list of integers
|
||||||
if ',' in docids:
|
if ',' in docids:
|
||||||
docids = [int(x.strip()) for x in docids.split(',') if x.strip()]
|
docids = [int(x.strip()) for x in docids.split(',') if x.strip()]
|
||||||
else:
|
else:
|
||||||
docids = [int(docids)]
|
docids = [int(docids)]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
docids = []
|
docids = []
|
||||||
elif not isinstance(docids, list):
|
elif not isinstance(docids, list):
|
||||||
docids = [docids] if docids else []
|
docids = [docids] if docids else []
|
||||||
|
|
||||||
_logger.info(f"Processed parameters: report_name={report_name}, docids={docids}")
|
_logger.info(f"Processed parameters: report_name={report_name}, docids={docids}")
|
||||||
|
|
||||||
# Call the direct print model method with proper context
|
# Call the direct print model method with proper context
|
||||||
result = request.env['web.direct.print'].sudo().direct_print_action(
|
result = request.env['web.direct.print'].sudo().direct_print_action(
|
||||||
report_name, docids, data, context=request.context
|
report_name, docids, data, context=request.context
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import logging
|
import logging
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
_logger.error(f"Controller error: {str(e)}")
|
_logger.error(f"Controller error: {str(e)}")
|
||||||
_logger.exception("Full traceback:")
|
_logger.exception("Full traceback:")
|
||||||
return {
|
return {
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': str(e)
|
'error': str(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@http.route('/web/direct_print/get_reports', type='json', auth='user')
|
@http.route('/web/direct_print/get_reports', type='jsonrpc', auth='user')
|
||||||
def get_available_reports(self):
|
def get_available_reports(self):
|
||||||
"""
|
"""
|
||||||
Controller method to get available reports for direct printing
|
Controller method to get available reports for direct printing
|
||||||
:return: JSON response with available reports
|
:return: JSON response with available reports
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result = request.env['web.direct.print'].sudo().get_available_reports()
|
result = request.env['web.direct.print'].sudo().get_available_reports()
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': str(e)
|
'error': str(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@http.route('/web/direct_print/test', type='http', auth='user', website=True)
|
@http.route('/web/direct_print/test', type='http', auth='user', website=True)
|
||||||
def test_direct_print(self, **kwargs):
|
def test_direct_print(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Test endpoint for direct printing functionality
|
Test endpoint for direct printing functionality
|
||||||
"""
|
"""
|
||||||
# This could be used for testing purposes
|
# This could be used for testing purposes
|
||||||
html_content = """
|
html_content = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Direct Print Test</title>
|
<title>Direct Print Test</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Direct Print Test Page</h1>
|
<h1>Direct Print Test Page</h1>
|
||||||
<p>This page demonstrates the direct print functionality.</p>
|
<p>This page demonstrates the direct print functionality.</p>
|
||||||
<button onclick="window.print()">Print this page</button>
|
<button onclick="window.print()">Print this page</button>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
return html_content
|
return html_content
|
||||||
2
security/ir.model.access.csv
Normal file
2
security/ir.model.access.csv
Normal file
@ -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
|
||||||
|
@ -140,8 +140,8 @@ if records:
|
|||||||
<!-- Package/Lot Tracking Direct Print -->
|
<!-- Package/Lot Tracking Direct Print -->
|
||||||
<record id="action_direct_print_package_content" model="ir.actions.server">
|
<record id="action_direct_print_package_content" model="ir.actions.server">
|
||||||
<field name="name">Direct Print Package Content</field>
|
<field name="name">Direct Print Package Content</field>
|
||||||
<field name="model_id" ref="stock.model_stock_quant_package"/>
|
<field name="model_id" ref="stock.model_stock_package"/>
|
||||||
<field name="binding_model_id" ref="stock.model_stock_quant_package"/>
|
<field name="binding_model_id" ref="stock.model_stock_package"/>
|
||||||
<field name="binding_view_types">list,form</field>
|
<field name="binding_view_types">list,form</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">
|
<field name="code">
|
||||||
@ -149,7 +149,7 @@ if records:
|
|||||||
action = {
|
action = {
|
||||||
'type': 'ir.actions.client',
|
'type': 'ir.actions.client',
|
||||||
'tag': 'direct_print',
|
'tag': 'direct_print',
|
||||||
'report_name': 'stock.action_report_quant_package_barcode',
|
'report_name': 'stock.action_report_package_barcode',
|
||||||
'docids': records.ids,
|
'docids': records.ids,
|
||||||
'context': env.context,
|
'context': env.context,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user