Initial commit
This commit is contained in:
5
pdf_print_preview/models/__init__.py
Normal file
5
pdf_print_preview/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import res_users
|
||||
from . import ir_http
|
||||
from . import ir_actions_report
|
||||
28
pdf_print_preview/models/ir_actions_report.py
Normal file
28
pdf_print_preview/models/ir_actions_report.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, tools
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
import traceback
|
||||
|
||||
|
||||
class Http(models.Model):
|
||||
_inherit = "ir.actions.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
|
||||
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()
|
||||
|
||||
if messageError:
|
||||
report_ref = "pdf_print_preview.report_error_catcher"
|
||||
data = {'error': messageError}
|
||||
result = super()._render_qweb_pdf(report_ref, res_ids=[], data=data)
|
||||
return result
|
||||
19
pdf_print_preview/models/ir_http.py
Normal file
19
pdf_print_preview/models/ir_http.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models
|
||||
|
||||
class Http(models.AbstractModel):
|
||||
_inherit = "ir.http"
|
||||
|
||||
def session_info(self):
|
||||
result = super(Http, self).session_info()
|
||||
|
||||
user = self.env.user
|
||||
|
||||
result.update({
|
||||
"preview_print": user.preview_print,
|
||||
"automatic_printing": user.automatic_printing,
|
||||
"report_layout": bool(user.company_id.external_report_layout_id)
|
||||
})
|
||||
|
||||
return result
|
||||
36
pdf_print_preview/models/res_users.py
Normal file
36
pdf_print_preview/models/res_users.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = "res.users"
|
||||
|
||||
preview_print = fields.Boolean(
|
||||
string="Preview print",
|
||||
default=True
|
||||
)
|
||||
|
||||
automatic_printing = fields.Boolean(
|
||||
string="Automatic printing"
|
||||
)
|
||||
|
||||
def preview_reload(self):
|
||||
return {
|
||||
"type": "ir.actions.client",
|
||||
"tag": "reload"
|
||||
}
|
||||
|
||||
def preview_print_save(self):
|
||||
return {
|
||||
"type": "ir.actions.client",
|
||||
"tag": "reload_context"
|
||||
}
|
||||
|
||||
@property
|
||||
def SELF_READABLE_FIELDS(self):
|
||||
return super().SELF_READABLE_FIELDS + ["preview_print", "automatic_printing"]
|
||||
|
||||
@property
|
||||
def SELF_WRITEABLE_FIELDS(self):
|
||||
return super().SELF_WRITEABLE_FIELDS + ["preview_print", "automatic_printing"]
|
||||
Reference in New Issue
Block a user