[FIX] Set back old tray behaviour to take user or report default if tray not set on action - update tests for printer tray to new determinant location

This commit is contained in:
Graeme Gellatly
2017-10-08 21:02:25 +13:00
parent a051a146d7
commit 8220b750b5
5 changed files with 118 additions and 74 deletions

View File

@@ -93,7 +93,10 @@ class IrActionsReport(models.Model):
('action', '!=', 'user_default'),
], limit=1)
if print_action:
result.update(print_action.behaviour())
# For some reason design takes report defaults over
# False action entries so we must allow for that here
result.update({k: v for k, v in
print_action.behaviour().items() if v})
return result
@api.multi

View File

@@ -165,9 +165,13 @@ class PrintingPrinter(models.Model):
@api.multi
def print_options(self, report=None, **print_opts):
options = {}
if not report:
return options
for option, value in print_opts.items():
try:
getattr(self, '_set_option_%s' % option)(report, value)
options.update(getattr(
self, '_set_option_%s' % option)(report, value))
except AttributeError:
options[option] = str(value)
return options

View File

@@ -44,6 +44,12 @@ class TestIrActionsReportXml(TransactionCase):
'uri': 'URI',
})
def new_tray(self, vals=None, defaults=None):
values = dict(defaults)
if vals is not None:
values.update(vals)
return self.env['printing.tray'].create(values)
def test_print_action_for_report_name_gets_report(self):
""" It should get report by name """
with mock.patch.object(self.Model, '_get_report_from_name') as mk:
@@ -205,6 +211,70 @@ class TestIrActionsReportXml(TransactionCase):
},
)
def test_print_tray_behaviour(self):
"""
It should return the correct tray
"""
report = self.env['ir.actions.report'].search([], limit=1)
action = self.env['printing.report.xml.action'].create({
'user_id': self.env.user.id,
'report_id': report.id,
'action': 'server',
})
printer = self.new_printer()
tray_vals = {
'name': 'Tray',
'system_name': 'Tray',
'printer_id': printer.id,
}
user_tray = self.new_tray({'system_name':'User tray'}, tray_vals)
report_tray = self.new_tray({'system_name': 'Report tray'}, tray_vals)
action_tray = self.new_tray({'system_name': 'Action tray'}, tray_vals)
# No report passed
self.env.user.printer_tray_id = False
options = self.printer.print_options()
self.assertFalse('InputSlot' in options)
# No tray defined
self.env.user.printer_tray_id = False
report.printer_tray_id = False
action.printer_tray_id = False
options = report.behaviour()
self.assertTrue('tray' in options)
# Only user tray is defined
self.env.user.printer_tray_id = user_tray
report.printer_tray_id = False
action.printer_tray_id = False
options = report.behaviour()
self.assertIn({'tray': 'User tray'}, options)
# Only report tray is defined
self.env.user.printer_tray_id = False
report.printer_tray_id = report_tray
action.printer_tray_id = False
self.assertIn({'tray': 'Report tray'}, report.behaviour())
# Only action tray is defined
self.env.user.printer_tray_id = False
report.printer_tray_id = False
action.printer_tray_id = action_tray
self.assertIn({'tray': 'Action tray'}, report.behaviour())
# User and report tray defined
self.env.user.printer_tray_id = False
report.printer_tray_id = False
action.printer_tray_id = action_tray
self.assertIn({'tray': 'User tray'}, report.behaviour())
# All trays are defined
self.env.user.printer_tray_id = user_tray
report.printer_tray_id = report_tray
action.printer_tray_id = action_tray
self.assertIn({'tray': 'Action tray'}, report.behaviour())
def test_onchange_printer_tray_id_empty(self):
action = self.env['ir.actions.report'].new(
{'printer_tray_id': False})

View File

@@ -35,21 +35,56 @@ class TestPrintingPrinter(TransactionCase):
def new_record(self):
return self.Model.create(self.printer_vals)
def test_printing_options(self):
def test_option_tray(self):
"""
It should put the value in InputSlot
"""
self.assertEqual(self.Model._set_option_tray(None, 'Test Tray'),
{'InputSlot': 'Test Tray'})
self.assertEqual(self.Model._set_option_tray(None, False),
{})
def test_option_noops(self):
"""
Noops should return an empty dict
"""
self.assertEqual(self.Model._set_option_action(None, 'printer'), {})
self.assertEqual(self.Model._set_option_printer(None, self.printer),
{})
def test_option_doc_format(self):
"""
Raw documents should set raw boolean.
"""
self.assertEqual(self.Model._set_option_doc_format(None, 'raw'),
{'raw': 'True'})
# Deprecate _set_option_format in v12.
self.assertEqual(self.Model._set_option_format(None, 'raw'),
{'raw': 'True'})
self.assertEqual(self.Model._set_option_doc_format(None, 'pdf'), {})
# Deprecate _set_option_format in v12.
self.assertEqual(self.Model._set_option_format(None, 'pdf'), {})
def test_print_options(self):
""" It should generate the right options dictionnary """
'copies': '2',
# TODO: None here used as report - tests here should be merged
# with tests in test_printing_printer_tray from when modules merged
report = self.env['ir.actions.report'].search([], limit=1)
self.assertEqual(self.Model.print_options(
None, doc_format='raw'), {'raw': 'True'}
report, doc_format='raw'), {'raw': 'True'}
)
self.assertEqual(self.Model.print_options(
None, doc_format='pdf', copies=2), {'copies': '2'}
report, doc_format='pdf', copies=2), {'copies': '2'}
)
self.assertEqual(self.Model.print_options(
None, doc_format='raw', copies=2),
report, doc_format='raw', copies=2),
{'raw': 'True', 'copies': '2'}
)
self.assertIn('InputSlot',
self.Model.print_options(report, tray='Test').keys()
)
@mock.patch('%s.cups' % server_model)
def test_print_report(self, cups):

View File

@@ -100,74 +100,6 @@ class TestPrintingPrinter(TransactionCase):
},
}
def test_print_options(self):
"""
It should generate the right options dictionnary
"""
report = self.env['ir.actions.report'].search([], limit=1)
action = self.env['printing.report.xml.action'].create({
'user_id': self.env.user.id,
'report_id': report.id,
'action': 'server',
})
user_tray = self.new_tray({
'system_name': 'User tray',
})
report_tray = self.new_tray({
'system_name': 'Report tray',
})
action_tray = self.new_tray({
'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
action.printer_tray_id = False
options = self.Model.print_options(report, doc_format='pdf')
self.assertFalse('InputSlot' in options)
# Only user tray is defined
self.env.user.printer_tray_id = user_tray
report.printer_tray_id = False
action.printer_tray_id = False
options = self.Model.print_options(report, doc_format='pdf')
self.assertEquals(options, {
'InputSlot': 'User tray',
})
# Only report tray is defined
self.env.user.printer_tray_id = False
report.printer_tray_id = report_tray
action.printer_tray_id = False
options = self.Model.print_options(report, doc_format='pdf')
self.assertEquals(options, {
'InputSlot': 'Report tray',
})
# Only action tray is defined
self.env.user.printer_tray_id = False
report.printer_tray_id = False
action.printer_tray_id = action_tray
options = self.Model.print_options(report, doc_format='pdf')
self.assertEquals(options, {
'InputSlot': 'Action tray',
})
# All trays are defined
self.env.user.printer_tray_id = user_tray
report.printer_tray_id = report_tray
action.printer_tray_id = action_tray
options = self.Model.print_options(report, doc_format='pdf')
self.assertEquals(options, {
'InputSlot': 'Action tray',
})
@mock.patch('%s.cups' % server_model)
def test_update_printers(self, cups):
"""