changes
This commit is contained in:
@@ -3,3 +3,5 @@
|
||||
from . import res_users
|
||||
from . import ir_http
|
||||
from . import ir_actions_report
|
||||
from . import res_config_settings
|
||||
from . import preview_log
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, tools
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
import traceback
|
||||
|
||||
from odoo import fields, models, tools
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
class Http(models.Model):
|
||||
|
||||
class IrActionsReport(models.Model):
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
fusion_preview_mode = fields.Selection([
|
||||
('default', 'Use User Preference'),
|
||||
('preview', 'Always Preview'),
|
||||
('download', 'Always Download'),
|
||||
('auto_print', 'Always Auto-Print'),
|
||||
], string='PDF Preview Mode', default='default',
|
||||
help='Override user-level PDF preview settings for this specific report.')
|
||||
|
||||
def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
|
||||
if tools.config['test_enable'] or tools.config['test_file']:
|
||||
return super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
|
||||
|
||||
result = False, False
|
||||
messageError = False
|
||||
message_error = False
|
||||
try:
|
||||
result = super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
|
||||
except (UserError, ValidationError) as e:
|
||||
messageError = str(e)
|
||||
except Exception as e:
|
||||
messageError = traceback.format_exc()
|
||||
message_error = str(e)
|
||||
except Exception:
|
||||
message_error = traceback.format_exc()
|
||||
|
||||
if messageError:
|
||||
report_ref = "pdf_print_preview.report_error_catcher"
|
||||
data = {'error': messageError}
|
||||
if message_error:
|
||||
report_ref = "fusion_pdf_preview.report_error_catcher"
|
||||
data = {'error': message_error}
|
||||
result = super()._render_qweb_pdf(report_ref, res_ids=[], data=data)
|
||||
return result
|
||||
|
||||
37
fusion_pdf_preview/models/preview_log.py
Normal file
37
fusion_pdf_preview/models/preview_log.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class FusionPdfPreviewLog(models.Model):
|
||||
_name = 'fusion.pdf.preview.log'
|
||||
_description = 'PDF Preview Audit Log'
|
||||
_order = 'create_date desc'
|
||||
_rec_name = 'report_name'
|
||||
|
||||
user_id = fields.Many2one(
|
||||
'res.users', string='User',
|
||||
required=True, default=lambda self: self.env.uid,
|
||||
index=True,
|
||||
)
|
||||
report_id = fields.Many2one(
|
||||
'ir.actions.report', string='Report',
|
||||
ondelete='set null', index=True,
|
||||
)
|
||||
report_name = fields.Char(
|
||||
string='Report Name', required=True,
|
||||
help='Stored report name for reference even if the report is later deleted.',
|
||||
)
|
||||
action_type = fields.Selection([
|
||||
('preview', 'Preview'),
|
||||
('print', 'Print'),
|
||||
('download', 'Download'),
|
||||
], string='Action', required=True, index=True)
|
||||
record_ids = fields.Char(
|
||||
string='Record IDs',
|
||||
help='Comma-separated list of record IDs included in the report.',
|
||||
)
|
||||
model_name = fields.Char(
|
||||
string='Model',
|
||||
help='Technical model name of the records.',
|
||||
)
|
||||
42
fusion_pdf_preview/models/res_config_settings.py
Normal file
42
fusion_pdf_preview/models/res_config_settings.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
fpv_default_preview_print = fields.Boolean(
|
||||
string='Default Preview Print',
|
||||
config_parameter='fusion_pdf_preview.default_preview_print',
|
||||
default=True,
|
||||
help='Default value for PDF preview when new users are created.',
|
||||
)
|
||||
|
||||
fpv_default_automatic_printing = fields.Boolean(
|
||||
string='Default Automatic Printing',
|
||||
config_parameter='fusion_pdf_preview.default_automatic_printing',
|
||||
help='Default value for automatic printing when new users are created.',
|
||||
)
|
||||
|
||||
def action_fpv_apply_to_all_users(self):
|
||||
"""Apply current default PDF preview settings to all internal users in the company."""
|
||||
self.ensure_one()
|
||||
users = self.env['res.users'].search([
|
||||
('share', '=', False),
|
||||
('company_id', '=', self.env.company.id),
|
||||
])
|
||||
users.write({
|
||||
'preview_print': self.fpv_default_preview_print,
|
||||
'automatic_printing': self.fpv_default_automatic_printing,
|
||||
})
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': 'PDF Preview Settings',
|
||||
'message': f'Settings applied to {len(users)} user(s).',
|
||||
'type': 'success',
|
||||
'sticky': False,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user