Skip to content

Commit

Permalink
[FIX] printer_tray: Allow to call print_option with no report
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain GARANCHER committed Feb 9, 2017
1 parent 20284f7 commit f2c45bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion printer_tray/__openerp__.py
Expand Up @@ -4,7 +4,7 @@

{
'name': 'Report to printer - Paper tray selection',
'version': '9.0.1.0.0',
'version': '9.0.1.0.1',
'category': 'Printer',
'author': "Camptocamp, Odoo Community Association (OCA)",
'maintainer': 'Camptocamp',
Expand Down
38 changes: 20 additions & 18 deletions printer_tray/models/printing_printer.py
Expand Up @@ -67,27 +67,29 @@ def _prepare_update_from_cups(self, cups_connection, cups_printer):
return vals

@api.multi
def print_options(self, report, format, copies=1):
def print_options(self, report=None, format=None, copies=1):
""" Hook to define Tray """
printing_act_obj = self.env['printing.report.xml.action']
options = super(PrintingPrinter, self).print_options(report, format)

# Retrieve user default values
user = self.env.user
tray = user.printer_tray_id

# Retrieve report default values
if report.printer_tray_id:
tray = report.printer_tray_id

# Retrieve report-user specific values
action = printing_act_obj.search([('report_id', '=', report.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default')],
limit=1)
if action.printer_tray_id:
tray = action.printer_tray_id

if tray:
options['InputSlot'] = str(tray.system_name)
tray = self.env.user.printer_tray_id

if report is not None:
# Retrieve report default values
if report.printer_tray_id:
tray = report.printer_tray_id

# Retrieve report-user specific values
action = printing_act_obj.search([
('report_id', '=', report.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default'),
], limit=1)
if action.printer_tray_id:
tray = action.printer_tray_id

if tray:
options['InputSlot'] = str(tray.system_name)

return options
5 changes: 5 additions & 0 deletions printer_tray/tests/test_printing_printer.py
Expand Up @@ -113,6 +113,11 @@ def test_print_options(self):
'system_name': 'Action tray',
})

# No report passed
self.env.user.printer_tray_id = False
options = self.Model.print_options()
self.assertFalse('InputSlot' in options)

# No tray defined
self.env.user.printer_tray_id = False
report.printer_tray_id = False
Expand Down

0 comments on commit f2c45bd

Please sign in to comment.