forked from OCA/report-print-send
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir_report.py
115 lines (101 loc) · 4.06 KB
/
ir_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2007 Ferran Pegueroles <[email protected]>
# Copyright (c) 2009 Albert Cervera i Areny <[email protected]>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
from openerp import models, fields, api
_logger = logging.getLogger('base_report_to_printer')
class ReportXml(models.Model):
"""
Reports
"""
_inherit = 'ir.actions.report.xml'
property_printing_action = fields.Many2one(
comodel_name='printing.action',
string='Action',
company_dependent=True,
)
printing_printer_id = fields.Many2one(
comodel_name='printing.printer',
string='Printer'
)
printing_action_ids = fields.One2many(
comodel_name='printing.report.xml.action',
inverse_name='report_id',
string='Actions',
help='This field allows configuring action and printer on a per '
'user basis'
)
@api.model
def print_action_for_report_name(self, report_name):
""" Returns if the action is a direct print or pdf
Called from js
"""
report_obj = self.env['report']
report = report_obj._get_report_from_name(report_name)
if not report:
return {}
result = report.behaviour()[report.id]
serializable_result = {
'action': result['action'],
'printer_name': result['printer'].name,
}
return serializable_result
@api.multi
def behaviour(self):
result = {}
printer_obj = self.env['printing.printer']
printing_act_obj = self.env['printing.report.xml.action']
# Set hardcoded default action
default_action = 'client'
# Retrieve system wide printer
default_printer = printer_obj.get_default()
# Retrieve user default values
user = self.env.user
if user.printing_action:
default_action = user.printing_action
if user.printing_printer_id:
default_printer = user.printing_printer_id
for report in self:
action = default_action
printer = default_printer
# Retrieve report default values
report_action = report.property_printing_action
if report_action and report_action.type != 'user_default':
action = report_action.type
if report.printing_printer_id:
printer = report.printing_printer_id
# Retrieve report-user specific values
print_action = printing_act_obj.search(
[('report_id', '=', report.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default')],
limit=1)
if print_action:
user_action = print_action.behaviour()
action = user_action['action']
if user_action['printer']:
printer = user_action['printer']
result[report.id] = {'action': action,
'printer': printer,
}
return result